Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into feature/permanent…
Browse files Browse the repository at this point in the history
…-delete-person
  • Loading branch information
PetarDimitrov91 committed Nov 21, 2023
2 parents 53b89df + 8b25f9a commit 4f9b604
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
20 changes: 19 additions & 1 deletion apps/api/src/affiliate/affiliate.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export class AffiliateController {
@Param('affiliateCode') affiliateCode: string,
@Query('status') status: DonationStatus | undefined,
@Query('page', new DefaultValuePipe(1), ParseIntPipe) page: number,
@Query('limit', new DefaultValuePipe(10), ParseIntPipe) limit: number,
@Query('limit') limit: number | undefined,
) {
return await this.affiliateService.findAffiliateDonationsWithPagination(
affiliateCode,
Expand All @@ -146,6 +146,24 @@ export class AffiliateController {
)
}

@Get(':affiliateCode/donations/:customerId/list')
@Public()
async findAffiliateDonationByCustomerId(
@Param('affiliateCode') affiliateCode: string,
@Param('customerId') customerId: string,
@Query('status') status: DonationStatus | undefined,
@Query('page', new DefaultValuePipe(1), ParseIntPipe) page: number,
@Query('limit') limit: number | undefined,
) {
return await this.affiliateService.findDonationsByCustomerId(
affiliateCode,
customerId,
status,
page,
limit,
)
}

@Patch(':affiliateCode/donations/:donationId/cancel')
@Public()
async cancelAffiliateDonation(
Expand Down
28 changes: 25 additions & 3 deletions apps/api/src/affiliate/affiliate.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,28 @@ export class AffiliateService {
return await this.prismaService.affiliate.findUnique({ where: { id } })
}

async findDonationsByCustomerId(
affiliateCode: string,
extCustomerId: string,
status: DonationStatus | undefined,
currentPage: number,
limit: number | undefined,
) {
return await this.prismaService.affiliate.findFirst({
where: {
affiliateCode,
donations: { some: { extCustomerId: { equals: extCustomerId }, status } },
},
select: {
donations: {
take: limit ? Number(limit) : undefined,
skip: Number((currentPage - 1) * (limit ?? 0)),
include: { metadata: true },
},
},
})
}

async findAll() {
return await this.prismaService.affiliate.findMany({
orderBy: { createdAt: 'desc' },
Expand Down Expand Up @@ -62,16 +84,16 @@ export class AffiliateService {
affiliateCode: string,
status: DonationStatus | undefined,
currentPage: number,
limit: number,
limit: number | undefined,
) {
return await this.prismaService.affiliate.findUnique({
where: { affiliateCode },
select: {
donations: {
orderBy: { createdAt: 'desc' },
where: { status },
take: limit,
skip: Number((currentPage - 1) * limit),
take: limit ? Number(limit) : undefined,
skip: Number((currentPage - 1) * (limit ?? 0)),
include: { metadata: true },
},
},
Expand Down

0 comments on commit 4f9b604

Please sign in to comment.