Skip to content

Commit 60b5ac2

Browse files
authored
Merge pull request #19 from topcoder-platform/PM-921_qa-fixes
update to admin winnings: throw error & check payment status
2 parents 1e8408a + 7f5215e commit 60b5ac2

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

src/api/admin-winning/adminWinning.service.ts

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -364,19 +364,22 @@ export class AdminWinningService {
364364
payment.payment_status !== PaymentStatus.ON_HOLD_ADMIN &&
365365
payment.payment_status !== PaymentStatus.PAID
366366
) {
367-
errMessage =
368-
"cannot put a payment back to owed unless it is on hold by an admin, or it's been paid";
367+
throw new BadRequestException(
368+
"cannot put a payment back to owed unless it is on hold by an admin, or it's been paid",
369+
);
369370
}
370371
}
371372

372373
break;
373374

374375
default:
375-
errMessage = 'invalid payment status provided';
376-
break;
376+
throw new BadRequestException('invalid payment status provided');
377377
}
378378

379-
if (errMessage) {
379+
if (
380+
errMessage &&
381+
payment.payment_status === PaymentStatus.PROCESSING
382+
) {
380383
throw new BadRequestException(errMessage);
381384
}
382385

@@ -412,6 +415,22 @@ export class AdminWinningService {
412415
if (body.releaseDate) {
413416
const newReleaseDate = new Date(body.releaseDate);
414417

418+
if (
419+
![
420+
PaymentStatus.OWED,
421+
PaymentStatus.ON_HOLD,
422+
PaymentStatus.ON_HOLD_ADMIN,
423+
].includes(payment.payment_status as PaymentStatus)
424+
) {
425+
throw new BadRequestException(
426+
`Cannot update release date for payment unless it's in one of the states: ${[
427+
PaymentStatus.OWED,
428+
PaymentStatus.ON_HOLD,
429+
PaymentStatus.ON_HOLD_ADMIN,
430+
].join(', ')}`,
431+
);
432+
}
433+
415434
transactions.push(
416435
this.updateReleaseDate(
417436
userId,
@@ -439,7 +458,6 @@ export class AdminWinningService {
439458
if (
440459
body.paymentAmount !== undefined &&
441460
(payment.payment_status === PaymentStatus.OWED ||
442-
payment.payment_status === PaymentStatus.ON_HOLD ||
443461
payment.payment_status === PaymentStatus.ON_HOLD ||
444462
payment.payment_status === PaymentStatus.ON_HOLD_ADMIN)
445463
) {

0 commit comments

Comments
 (0)