diff --git a/src/features/ticket/ticket.service.ts b/src/features/ticket/ticket.service.ts index 2d4b40c3e..0a0aec391 100644 --- a/src/features/ticket/ticket.service.ts +++ b/src/features/ticket/ticket.service.ts @@ -254,6 +254,10 @@ export class TicketService { }, }, }, + order: { + createdAt: 'DESC', + }, + take: 50, }); } @@ -317,8 +321,41 @@ export class TicketService { }, }, }, + take: 50, + order: { + createdAt: 'DESC', + }, }); } + + async getNeedsTickets(needIds: number[]): Promise { + const queryBuilder = this.ticketRepository + .createQueryBuilder('ticket') + .leftJoinAndMapOne( + 'ticket.need', + NeedEntity, + 'need', + ' need.flaskId = ticket.flaskNeedId', + ) + .where('need.flaskId IN (:...needIds)', { needIds: needIds }) + .select([ + 'ticket', + 'need.id', + 'need.nameTranslations', + 'need.title', + 'need.imageUrl', + 'need.category', + 'need.type', + 'need.status', + 'need.cost', + 'need.isDeleted', + 'need.created', + 'need.confirmDate', + ]) + .cache(6000); + return await queryBuilder.getMany(); + } + getUserOnlyArrivalTickets(flaskUserId: number): Promise { return this.ticketRepository.find({ relations: { diff --git a/src/features/user/user.controller.ts b/src/features/user/user.controller.ts index 8625a1ad8..0729c79f2 100644 --- a/src/features/user/user.controller.ts +++ b/src/features/user/user.controller.ts @@ -297,19 +297,20 @@ export class UserController { const time3 = new Date().getTime(); // add IPFS + tickets for every need try { - let tickets: TicketEntity[]; let signatures: SignatureEntity[]; let ipfs: IpfsEntity; - if (role === SAYPlatformRoles.AUDITOR) { - tickets = await this.ticketService.getTickets(); - } else { - tickets = await this.ticketService.getUserTickets(panelFlaskUserId); - } + + const list: number[] = []; + allNeeds.forEach((column) => { + for (let i = 0; i < column.length; i++) { + list.push(column[i].id); + } + }); + const tickets = await this.ticketService.getNeedsTickets(list); console.log( '\x1b[33m%s\x1b[0m', `Taking care of Need signatures + Tickets...\n`, ); - for (let i = 0; i < allNeeds.length; i++) { for (let k = 0; k < allNeeds[i].length; k++) { const fetchedNeed = allNeeds[i][k];