From e4914900ffff6ef5d5e8ffe4441bf816f11bfc3a Mon Sep 17 00:00:00 2001 From: Alexander Petkov Date: Wed, 24 Apr 2024 15:59:57 +0300 Subject: [PATCH] fix: Resolve not being able to update payment/donation --- apps/api/src/donations/donations.service.ts | 17 ++++++----------- .../api/src/donations/dto/update-payment.dto.ts | 7 ++++++- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/apps/api/src/donations/donations.service.ts b/apps/api/src/donations/donations.service.ts index 407755bbf..6acd6590f 100644 --- a/apps/api/src/donations/donations.service.ts +++ b/apps/api/src/donations/donations.service.ts @@ -680,12 +680,12 @@ export class DonationsService { * @param updatePaymentDto * @returns */ - async update(id: string, updatePaymentDto: UpdatePaymentDto): Promise { + async update(paymentId: string, updatePaymentDto: UpdatePaymentDto): Promise { try { // execute the below in prisma transaction return await this.prisma.$transaction(async (tx) => { const currentPayment = await tx.payment.findFirst({ - where: { id }, + where: { id: paymentId }, include: { donations: { select: { personId: true, targetVaultId: true }, @@ -693,7 +693,7 @@ export class DonationsService { }, }) if (!currentPayment) { - throw new NotFoundException(`Update failed. No donation found with ID: ${id}`) + throw new NotFoundException(`Update failed. No payment found with ID: ${paymentId}`) } if ( @@ -730,23 +730,18 @@ export class DonationsService { } const donation = await tx.payment.update({ - where: { id }, + where: { id: paymentId }, data: { status: status, donations: { - updateMany: { - where: { paymentId: id }, + update: { + where: { id: updatePaymentDto.donationId ?? '' }, data: { personId: updatePaymentDto.targetPersonId ? donorId : undefined, }, }, }, billingEmail: updatePaymentDto.billingEmail ? billingEmail : undefined, - //In case of personId or billingEmail change, take the last updatedAt property to prevent any changes to updatedAt property - updatedAt: - updatePaymentDto.targetPersonId || updatePaymentDto.billingEmail - ? currentPayment.updatedAt - : undefined, }, }) diff --git a/apps/api/src/donations/dto/update-payment.dto.ts b/apps/api/src/donations/dto/update-payment.dto.ts index 2835ca608..8ad7f1522 100644 --- a/apps/api/src/donations/dto/update-payment.dto.ts +++ b/apps/api/src/donations/dto/update-payment.dto.ts @@ -14,5 +14,10 @@ export class UpdatePaymentDto extends PartialType(CreatePaymentDto) { @Expose() @ApiProperty() @IsOptional() - billingEmail?: string + billingEmail?: string + + @Expose() + @ApiProperty() + @IsOptional() + donationId?: string }