From c9f199a76973185203fe46914830a7738b50a5d4 Mon Sep 17 00:00:00 2001 From: G Date: Sat, 7 Sep 2024 21:58:09 +0330 Subject: [PATCH] optimising the tickets --- src/features/ticket/ticket.service.ts | 109 ----------------------- src/features/wallet/wallet.controller.ts | 12 +-- 2 files changed, 4 insertions(+), 117 deletions(-) diff --git a/src/features/ticket/ticket.service.ts b/src/features/ticket/ticket.service.ts index 94e460611..ca908fdf1 100644 --- a/src/features/ticket/ticket.service.ts +++ b/src/features/ticket/ticket.service.ts @@ -202,59 +202,6 @@ export class TicketService { getTickets(): Promise { return this.ticketRepository.find({ - relations: { - need: { - child: { - ngo: { - location: false, - }, - socialWorker: true, - }, - provider: true, - socialWorker: true, - purchaser: true, - auditor: true, - }, - }, - select: { - need: { - id: true, - flaskId: true, - name: true, - provider: { - id: true, - }, - child: { - id: true, - flaskId: true, - sayNameTranslations: { en: true, fa: true }, - ngo: { - id: true, - flaskNgoId: true, - location: { - id: true, - }, - }, - socialWorker: { - id: true, - flaskUserId: true, - }, - }, - socialWorker: { - id: true, - flaskUserId: true, - }, - purchaser: { - id: true, - flaskUserId: true, - }, - auditor: { - id: true, - flaskUserId: true, - }, - updatedAt: true, - }, - }, order: { updatedAt: 'DESC', }, @@ -264,64 +211,8 @@ export class TicketService { getUserTickets(flaskUserId: number): Promise { return this.ticketRepository.find({ - relations: { - need: { - child: { - ngo: { - location: false, - }, - socialWorker: true, - }, - provider: true, - socialWorker: true, - purchaser: true, - auditor: true, - }, - }, where: { contributors: { flaskUserId: flaskUserId }, - // need: { - // signatures: IsNull(), - // }, - }, - select: { - need: { - id: true, - flaskId: true, - name: true, - provider: { - id: true, - }, - child: { - id: true, - flaskId: true, - sayNameTranslations: { en: true, fa: true }, - ngo: { - id: true, - flaskNgoId: true, - location: { - id: true, - }, - }, - socialWorker: { - id: true, - flaskUserId: true, - }, - }, - socialWorker: { - id: true, - flaskUserId: true, - }, - purchaser: { - id: true, - flaskUserId: true, - }, - auditor: { - id: true, - flaskUserId: true, - }, - updatedAt: true, - }, }, take: 250, order: { diff --git a/src/features/wallet/wallet.controller.ts b/src/features/wallet/wallet.controller.ts index bb51c834b..a708a7c01 100644 --- a/src/features/wallet/wallet.controller.ts +++ b/src/features/wallet/wallet.controller.ts @@ -282,20 +282,16 @@ export class WalletController { let transaction: SwSignatureResult; try { const flaskUserId = session.siwe.flaskUserId; - const userTickets = await this.ticketService.getUserTickets(flaskUserId); let counter = 0; const purchasedNeeds = await this.needService.getPurchasedNeedsCount( flaskUserId, ); - purchasedNeeds.forEach((need) => { + purchasedNeeds.forEach(async (need) => { + const ticket = await this.ticketService.getTicketByFlaskNeedId(need.id); if ( - userTickets.find( - (t) => - t.need.flaskId === need.id && - t.ticketHistories.find( - (h) => h.announcement == AnnouncementEnum.ARRIVED_AT_NGO, - ), + ticket.ticketHistories.find( + (h) => h.announcement == AnnouncementEnum.ARRIVED_AT_NGO, ) ) { counter++;