Skip to content

Commit

Permalink
optimising the tickets
Browse files Browse the repository at this point in the history
  • Loading branch information
ehsan-g committed Sep 7, 2024
1 parent db74296 commit c9f199a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 117 deletions.
109 changes: 0 additions & 109 deletions src/features/ticket/ticket.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,59 +202,6 @@ export class TicketService {

getTickets(): Promise<TicketEntity[]> {
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',
},
Expand All @@ -264,64 +211,8 @@ export class TicketService {

getUserTickets(flaskUserId: number): Promise<TicketEntity[]> {
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: {
Expand Down
12 changes: 4 additions & 8 deletions src/features/wallet/wallet.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
Expand Down

0 comments on commit c9f199a

Please sign in to comment.