Skip to content

Commit

Permalink
Delete document function implemented (#1007)
Browse files Browse the repository at this point in the history
  • Loading branch information
GitVivekHub authored Apr 12, 2024
1 parent 52bdeeb commit c3caf6c
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 44 deletions.
86 changes: 42 additions & 44 deletions src/src/beneficiaries/beneficiaries.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1899,32 +1899,30 @@ export class BeneficiariesService {

if (body.enrollment_verification_status == 'pending') {
const data = {
query: `query searchById {
users_by_pk(id: ${updatedUser?.program_beneficiaries?.user_id}) {
id
program_beneficiaries{
payment_receipt_document_id
document {
id
name
}
}
query: `query MyQuery {
documents(where: {doument_type: {_eq: "enrollment_receipt"},user_id:{_eq:${updatedUser?.program_beneficiaries?.user_id}}}){
id
name
}
}`,
}
`,
};

const response = await this.hasuraServiceFromServices.getData(data);
const documentDetails =
response?.data?.users_by_pk?.program_beneficiaries[0]?.document;
if (documentDetails?.id) {
const documentDetails = response?.data?.documents;
if (documentDetails?.length > 0) {
//delete document from documnet table
await this.hasuraService.delete('documents', {
id: documentDetails?.id,
});
}
if (documentDetails?.name) {
//delete document from s3 bucket
await this.s3Service.deletePhoto(documentDetails?.name);
// await this.hasuraService.delete('documents', {
// id: documentDetails?.id,
// });
// if (documentDetails?.name) {
// //delete document from s3 bucket
// await this.s3Service.deletePhoto(documentDetails?.name);
// }

for (const documentDetail of documentDetails) {
await this.uploadFileService.DeleteFile(documentDetail);
}
}
}

Expand Down Expand Up @@ -2879,33 +2877,33 @@ export class BeneficiariesService {
myRequest['enrollment_aadhaar_no'] = null;
myRequest['is_eligible'] = null;
const data = {
query: `query searchById {
users_by_pk(id: ${req.id}) {
id
program_beneficiaries{
payment_receipt_document_id
document {
id
name
}
}
}
}`,
query: `query MyQuery {
documents(where: {doument_type: {_eq: "enrollment_receipt"},user_id:{_eq:${req?.id}}}){
id
name
}
}
`,
};

const response =
await this.hasuraServiceFromServices.getData(data);
const documentDetails =
response?.data?.users_by_pk?.program_beneficiaries[0]
?.document;
if (documentDetails?.id) {
const documentDetails = response?.data?.documents;
if (documentDetails?.length > 0) {
//delete document from documnet table
await this.hasuraService.delete('documents', {
id: documentDetails?.id,
});
}
if (documentDetails?.name) {
//delete document from s3 bucket
await this.s3Service.deletePhoto(documentDetails?.name);
// await this.hasuraService.delete('documents', {
// id: documentDetails?.id,
// });
// if (documentDetails?.name) {
// //delete document from s3 bucket
// await this.s3Service.deletePhoto(documentDetails?.name);
// }

for (const documentDetail of documentDetails) {
await this.uploadFileService.DeleteFile(
documentDetail,
);
}
}
const status = await this.statusUpdate(
{
Expand Down
10 changes: 10 additions & 0 deletions src/src/upload-file/upload-file.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,4 +261,14 @@ export class UploadFileService {
}
}
}

async DeleteFile(documentDetails: any) {
await this.hasuraService.delete('documents', {
id: documentDetails?.id,
});
if (documentDetails?.name) {
//delete document from s3 bucket
await this.s3Service.deletePhoto(documentDetails?.name);
}
}
}

0 comments on commit c3caf6c

Please sign in to comment.