Skip to content

Commit

Permalink
fix: Resolve not being able to update payment/donation
Browse files Browse the repository at this point in the history
  • Loading branch information
sashko9807 committed Apr 24, 2024
1 parent 6414873 commit e491490
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
17 changes: 6 additions & 11 deletions apps/api/src/donations/donations.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -680,20 +680,20 @@ export class DonationsService {
* @param updatePaymentDto
* @returns
*/
async update(id: string, updatePaymentDto: UpdatePaymentDto): Promise<Payment> {
async update(paymentId: string, updatePaymentDto: UpdatePaymentDto): Promise<Payment> {
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 },
},
},
})
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 (
Expand Down Expand Up @@ -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,
},
})

Expand Down
7 changes: 6 additions & 1 deletion apps/api/src/donations/dto/update-payment.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,10 @@ export class UpdatePaymentDto extends PartialType(CreatePaymentDto) {
@Expose()
@ApiProperty()
@IsOptional()
billingEmail?: string
billingEmail?: string

@Expose()
@ApiProperty()
@IsOptional()
donationId?: string
}

0 comments on commit e491490

Please sign in to comment.