Skip to content

PM-1304 - allow admin to update payment description #73

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/api/admin/admin.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,14 @@ export class AdminController {
@Body() body: WinningUpdateRequestDto,
@User() user: UserInfo,
): Promise<ResponseDto<string>> {
if (!body.paymentAmount && !body.releaseDate && !body.paymentStatus) {
if (
!body.paymentAmount &&
!body.releaseDate &&
!body.paymentStatus &&
!body.description
) {
throw new BadRequestException(
'paymentStatus, releaseDate and paymentAmount cannot be null at the same time.',
'description, paymentStatus, releaseDate and paymentAmount cannot be null at the same time.',
);
}

Expand Down
24 changes: 24 additions & 0 deletions src/api/admin/admin.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,30 @@ export class AdminService {
}

let version = payment.version ?? 1;

if (body.description) {
transactions.push((tx) =>
tx.payment.update({
where: {
payment_id: payment.payment_id,
version: version,
},
data: {
winnings: {
update: {
data: {
description: body.description,
},
},
},
updated_at: new Date(),
updated_by: userId,
version: version++,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high
correctness
The version field is being incremented with version++ but this operation is not atomic. If this code is executed concurrently, it might lead to race conditions where multiple transactions could end up with the same version number. Consider using a database mechanism to ensure atomicity or handle versioning more robustly.

},
}),
);
}

let paymentStatus = payment.payment_status as PaymentStatus;
// Update Payment Status if requested
if (body.paymentStatus) {
Expand Down
8 changes: 8 additions & 0 deletions src/api/admin/dto/winnings.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ export class WinningUpdateRequestDto {
@IsUUID()
winningsId: string;

@ApiProperty({
description: 'Payment description',
example: 'Task Payment',
})
@IsOptional()
@IsString()
description: string;

@ApiProperty({
description: 'The audit note',
example: 'audit note',
Expand Down