Skip to content

Commit fa7886f

Browse files
authored
Merge pull request #1395 from credebl/fix/schema_name_for_w3c_credentials
fix: Save schemaId during connection, email, and bulk issuance
2 parents fe5fbad + 759dd3b commit fa7886f

File tree

3 files changed

+45
-3
lines changed

3 files changed

+45
-3
lines changed

apps/issuance/src/issuance.repository.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,8 @@ export class IssuanceRepository {
230230
threadId: issueCredentialDto?.threadId,
231231
connectionId: issueCredentialDto?.connectionId,
232232
state: issueCredentialDto?.state,
233-
schemaId,
234-
credDefId
233+
credDefId,
234+
...(schemaId ? { schemaId } : {})
235235
},
236236
create: {
237237
createDateTime: issueCredentialDto?.createDateTime,
@@ -741,4 +741,18 @@ export class IssuanceRepository {
741741
throw error;
742742
}
743743
}
744+
745+
async updateSchemaIdByThreadId(threadId: string, schemaId: string): Promise<void> {
746+
try {
747+
await this.prisma.credentials.update({
748+
where: { threadId },
749+
data: {
750+
schemaId
751+
}
752+
});
753+
} catch (error) {
754+
this.logger.error(`[updateSchemaIdByThreadId] - error: ${JSON.stringify(error)}`);
755+
throw error;
756+
}
757+
}
744758
}

apps/issuance/src/issuance.service.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,18 @@ export class IssuanceService {
281281

282282
if (allSuccessful) {
283283
finalStatusCode = HttpStatus.CREATED;
284+
const context = payload?.credentialData[0]?.credential?.['@context'] as string[];
285+
286+
if (Array.isArray(context) && context.includes(CommonConstants.W3C_SCHEMA_URL)) {
287+
const filterData = context.filter((item) => CommonConstants.W3C_SCHEMA_URL !== item);
288+
const [schemaId] = filterData;
289+
results.forEach((record) => {
290+
if (PromiseResult.FULFILLED === record.status && record?.value?.threadId) {
291+
this.issuanceRepository.updateSchemaIdByThreadId(record?.value?.threadId, schemaId);
292+
}
293+
});
294+
}
295+
284296
finalMessage = ResponseMessages.issuance.success.create;
285297
} else if (allFailed) {
286298
finalStatusCode = HttpStatus.BAD_REQUEST;
@@ -889,7 +901,6 @@ export class IssuanceService {
889901

890902
await this.delay(500); // Wait for 0.5 seconds
891903
const sendOobOffer = await this.sendEmailForCredentialOffer(sendEmailCredentialOffer);
892-
893904
arraycredentialOfferResponse.push(sendOobOffer);
894905
}
895906
if (0 < errors.length) {
@@ -1064,6 +1075,20 @@ export class IssuanceService {
10641075
return false;
10651076
}
10661077

1078+
if (isEmailSent) {
1079+
const w3cSchemaId = outOfBandIssuancePayload?.credentialFormats?.jsonld?.credential?.['@context'] as string[];
1080+
if (w3cSchemaId && w3cSchemaId.includes(CommonConstants.W3C_SCHEMA_URL)) {
1081+
const filterData = w3cSchemaId.filter((item) => CommonConstants.W3C_SCHEMA_URL !== item);
1082+
const [schemaId] = filterData;
1083+
if (credentialCreateOfferDetails.response.credentialRequestThId) {
1084+
this.issuanceRepository.updateSchemaIdByThreadId(
1085+
credentialCreateOfferDetails.response.credentialRequestThId,
1086+
schemaId
1087+
);
1088+
}
1089+
}
1090+
}
1091+
10671092
return isEmailSent;
10681093
} catch (error) {
10691094
const iterationNoMessage = ` at position ${iterationNo}`;

libs/common/src/common.constant.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ export enum CommonConstants {
4545
URL_LEDG_GET_TAA = '/ledger/taa',
4646
URL_LEDG_POST_TAA_ACCEPT = '/ledger/taa/accept',
4747

48+
//W3cSCHEMA
49+
W3C_SCHEMA_URL = 'https://www.w3.org/2018/credentials/v1',
50+
4851
// MESSAGING SERVICES
4952
URL_MSG_SEND_MESSAGE = '/connections/#/send-message',
5053
URL_MSG_TRUST_PING = '/connections/#/send-ping',

0 commit comments

Comments
 (0)