Skip to content

Commit

Permalink
fix: delete file_upload records (#803)
Browse files Browse the repository at this point in the history
* feat: delete issuance records

Signed-off-by: bhavanakarwade <[email protected]>

* reafctor: variables names

Signed-off-by: bhavanakarwade <[email protected]>

* feat: delete issuance records by orgid

Signed-off-by: bhavanakarwade <[email protected]>

* fix: file upload delete changes

Signed-off-by: bhavanakarwade <[email protected]>

---------

Signed-off-by: bhavanakarwade <[email protected]>
Signed-off-by: KulkarniShashank <[email protected]>
  • Loading branch information
bhavanakarwade authored and KulkarniShashank committed Sep 11, 2024
1 parent 0de20e4 commit a5759a4
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 6 deletions.
2 changes: 1 addition & 1 deletion apps/api-gateway/src/connection/connection.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ export class ConnectionController {
return res.status(HttpStatus.CREATED).json(finalResponse);
}

@Delete('/:orgId/connections')
@Delete('/orgs/:orgId/connections')
@ApiOperation({ summary: 'Delete connection record', description: 'Delete connections by orgId' })
@ApiResponse({ status: HttpStatus.OK, description: 'Success', type: ApiResponseDto })
@ApiBearerAuth()
Expand Down
2 changes: 1 addition & 1 deletion apps/api-gateway/src/issuance/issuance.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ issueCredentialDto.type = 'Issuance';
return res.status(HttpStatus.CREATED).json(finalResponse);
}

@Delete('/:orgId/issuance-records')
@Delete('/orgs/:orgId/issuance-records')
@ApiOperation({ summary: 'Delete issuance record', description: 'Delete issuance records by orgId' })
@ApiResponse({ status: HttpStatus.OK, description: 'Success', type: ApiResponseDto })
@ApiBearerAuth()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ export class VerificationController {

}

@Delete('/:orgId/verification-records')
@Delete('/orgs/:orgId/verification-records')
@ApiOperation({ summary: 'Delete verification record', description: 'Delete verification records by orgId' })
@ApiResponse({ status: HttpStatus.OK, description: 'Success', type: ApiResponseDto })
@ApiBearerAuth()
Expand Down
6 changes: 5 additions & 1 deletion apps/issuance/interfaces/issuance.interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// eslint-disable-next-line camelcase
import { AutoAccept, SchemaType } from '@credebl/enum/enum';
import { IUserRequest } from '@credebl/user-request/user-request.interface';
import { organisation } from '@prisma/client';
import { Prisma, organisation } from '@prisma/client';
import { IUserRequestInterface } from 'apps/agent-service/src/interface/agent-service.interface';
import { IssueCredentialType } from 'apps/api-gateway/src/issuance/interfaces';

Expand Down Expand Up @@ -315,4 +315,8 @@ export interface IQueuePayload{
totalJobs: number;
isRetry: boolean;
isLastData: boolean;
}
export interface IDeletedFileUploadRecords {
deleteFileDetails: Prisma.BatchPayload;
deleteFileUploadDetails: Prisma.BatchPayload;
}
42 changes: 42 additions & 0 deletions apps/issuance/src/issuance.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { ResponseMessages } from '@credebl/common/response-messages';
import {
FileUpload,
FileUploadData,
IDeletedFileUploadRecords,
IssueCredentialWebhookPayload,
OrgAgent,
PreviewRequest,
Expand Down Expand Up @@ -590,6 +591,47 @@ export class IssuanceRepository {
}
}

async getFileUploadDataByOrgId(orgId: string): Promise<file_upload[]> {
try {
const fileDetails = await this.prisma.file_upload.findMany({
where: {
orgId
}
});
return fileDetails;
} catch (error) {
this.logger.error(`[getting file upload details] - error: ${JSON.stringify(error)}`);
throw error;
}
}

async deleteFileUploadData(fileUploadIds: string[], orgId: string): Promise<IDeletedFileUploadRecords> {
try {
return await this.prisma.$transaction(async (prisma) => {

const deleteFileDetails = await prisma.file_data.deleteMany({
where: {
fileUploadId: {
in: fileUploadIds
}
}
});

const deleteFileUploadDetails = await prisma.file_upload.deleteMany({
where: {
orgId
}
});

return { deleteFileDetails, deleteFileUploadDetails };

});
} catch (error) {
this.logger.error(`[Error in deleting file data] - error: ${JSON.stringify(error)}`);
throw error;
}
}

async deleteIssuanceRecordsByOrgId(orgId: string): Promise<IDeletedIssuanceRecords> {
try {
const tablesToCheck = [`${PrismaTables.PRESENTATIONS}`];
Expand Down
11 changes: 9 additions & 2 deletions apps/issuance/src/issuance.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1448,11 +1448,18 @@ async sendEmailForCredentialOffer(sendEmailCredentialOffer: SendEmailCredentialO

async deleteIssuanceRecords(orgId: string, userDetails: user): Promise<IDeletedIssuanceRecords> {
try {

const getFileUploadData = await this.issuanceRepository.getFileUploadDataByOrgId(orgId);

const getFileUploadIds = getFileUploadData.map(fileData => fileData.id);

await this.issuanceRepository.deleteFileUploadData(getFileUploadIds, orgId);

const deletedCredentialsRecords = await this.issuanceRepository.deleteIssuanceRecordsByOrgId(orgId);

if (0 === deletedCredentialsRecords?.deleteResult?.count) {
throw new NotFoundException(ResponseMessages.issuance.error.issuanceRecordsNotFound);
}
}

const statusCounts = {
[IssuanceProcessState.REQUEST_SENT]: 0,
Expand Down Expand Up @@ -1482,7 +1489,7 @@ async sendEmailForCredentialOffer(sendEmailCredentialOffer: SendEmailCredentialO
};

await this.userActivityRepository._orgDeletedActivity(orgId, userDetails, deletedIssuanceData, RecordType.ISSUANCE_RECORD);

return deletedCredentialsRecords;
} catch (error) {
this.logger.error(`[deleteIssuanceRecords] - error in deleting issuance records: ${JSON.stringify(error)}`);
Expand Down

0 comments on commit a5759a4

Please sign in to comment.