Skip to content

Commit 9aa5c8f

Browse files
committed
fix/schema migration
Signed-off-by: Sujit <[email protected]>
1 parent e5b3611 commit 9aa5c8f

File tree

4 files changed

+16
-23
lines changed

4 files changed

+16
-23
lines changed

apps/verification/src/repositories/verification.repository.ts

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export class VerificationRepository {
8787
proofRequestsSearchCriteria: IProofRequestSearchCriteria
8888
): Promise<IProofPresentationsListCount> {
8989
try {
90-
const proofRequestsListData = await this.prisma.presentations.findMany({
90+
const proofRequestsList = await this.prisma.presentations.findMany({
9191
where: {
9292
orgId,
9393
OR: [
@@ -106,7 +106,12 @@ export class VerificationRepository {
106106
presentationId: true,
107107
schemaId: true,
108108
emailId: true,
109-
errorMessage: true
109+
errorMessage: true,
110+
connections: {
111+
select: {
112+
theirLabel: true
113+
}
114+
}
110115
},
111116
orderBy: {
112117
[proofRequestsSearchCriteria.sortField]: SortValue.ASC === proofRequestsSearchCriteria.sortBy ? 'asc' : 'desc'
@@ -116,22 +121,6 @@ export class VerificationRepository {
116121
skip: (proofRequestsSearchCriteria.pageNumber - 1) * proofRequestsSearchCriteria.pageSize
117122
});
118123

119-
const proofRequestsList = await Promise.all(
120-
proofRequestsListData.map(async (presentation) => {
121-
if (!presentation.connectionId) {
122-
return { ...presentation, theirLabel: null };
123-
}
124-
const connection = await this.prisma.connections.findUnique({
125-
where: { connectionId: presentation.connectionId },
126-
select: { theirLabel: true }
127-
});
128-
return {
129-
...presentation,
130-
theirLabel: connection?.theirLabel ?? null
131-
};
132-
})
133-
);
134-
135124
const proofRequestsCount = await this.prisma.presentations.count({
136125
where: {
137126
orgId,
@@ -309,17 +298,16 @@ export class VerificationRepository {
309298
}
310299
}
311300

312-
async addEmailAfterVerification(emailList: IEmailResponse[]): Promise<void> {
301+
async saveEmail(emailList: IEmailResponse[]): Promise<void> {
313302
try {
314303
for (const { proofRecordThId, email } of emailList) {
315304
await this.prisma.presentations.updateMany({
316305
where: { threadId: proofRecordThId },
317306
data: { emailId: email }
318307
});
319308
}
320-
// return this.prisma.organisation.findFirst({ where: { id: orgId } });
321309
} catch (error) {
322-
this.logger.error(`[getOrganization] - error: ${JSON.stringify(error)}`);
310+
this.logger.error(`[Verification Save Email] - error: ${JSON.stringify(error)}`);
323311
throw error;
324312
}
325313
}

apps/verification/src/verification.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ export class VerificationService {
570570
}
571571
if (emailId) {
572572
const emailResponse = await this.sendEmailInBatches(payload, emailId, getAgentDetails, getOrganization);
573-
await this.verificationRepository.addEmailAfterVerification(emailResponse as IEmailResponse[]);
573+
await this.verificationRepository.saveEmail(emailResponse as IEmailResponse[]);
574574
return emailResponse;
575575
} else {
576576
const presentationProof: IInvitation = await this.generateOOBProofReq(payload);
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- AddForeignKey
2+
ALTER TABLE "presentations" ADD CONSTRAINT "presentations_connectionId_fkey" FOREIGN KEY ("connectionId") REFERENCES "connections"("connectionId") ON DELETE SET NULL ON UPDATE CASCADE;

libs/prisma-service/prisma/schema.prisma

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ model connections {
325325
state String
326326
orgId String? @db.Uuid
327327
organisation organisation? @relation(fields: [orgId], references: [id])
328+
presentations presentations[]
328329
}
329330

330331
model credentials {
@@ -349,7 +350,7 @@ model presentations {
349350
createdBy String @db.Uuid
350351
lastChangedDateTime DateTime @default(now()) @db.Timestamptz(6)
351352
lastChangedBy String @db.Uuid
352-
connectionId String?
353+
connectionId String?
353354
state String?
354355
threadId String @unique
355356
isVerified Boolean?
@@ -359,6 +360,8 @@ model presentations {
359360
emailId String?
360361
orgId String? @db.Uuid
361362
organisation organisation? @relation(fields: [orgId], references: [id])
363+
connections connections? @relation(fields: [connectionId], references: [connectionId])
364+
362365
}
363366

364367
model file_upload {

0 commit comments

Comments
 (0)