Skip to content

Commit 407326b

Browse files
committed
fix edit payments
fix postman collection after merging fix maxPossibleDays calculation don't update amount in challenge as it is not allowed by Challenge API ref issue #431
1 parent 81a3112 commit 407326b

File tree

2 files changed

+7
-12
lines changed

2 files changed

+7
-12
lines changed

docs/Topcoder-bookings-api.postman_collection.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"info": {
3-
"_postman_id": "8ead1433-9679-46de-9baa-d27d59106673"
3+
"_postman_id": "8ead1433-9679-46de-9baa-d27d59106673",
44
"name": "Topcoder-bookings-api",
55
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
66
},

src/services/WorkPeriodPaymentService.js

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,20 +56,15 @@ async function _createSingleWorkPeriodPayment (workPeriodPayment, createdBy) {
5656
*/
5757
async function _updateChallenge (challengeId, data) {
5858
const body = {}
59+
5960
if (data.billingAccountId) {
6061
body.billing = {
6162
billingAccountId: _.toString(data.billingAccountId),
6263
markup: 0 // for TaaS payments we always use 0 markup
6364
}
6465
}
65-
if (data.amount) {
66-
body.prizeSets = [{
67-
type: 'placement',
68-
prizes: [{ type: 'USD', value: data.amount }]
69-
}]
70-
}
7166

72-
if (data.billingAccountId || data.amount) {
67+
if (data.billingAccountId) {
7368
try {
7469
await helper.updateChallenge(challengeId, body)
7570
logger.debug({ component: 'WorkPeriodPaymentService', context: 'updateChallenge', message: `Challenge with id ${challengeId} is updated` })
@@ -279,9 +274,9 @@ async function updateWorkPeriodPayment (currentUser, id, data) {
279274

280275
if (data.days) {
281276
const correspondingWorkPeriod = await helper.ensureWorkPeriodById(workPeriodPayment.workPeriodId) // ensure work period exists
282-
const maxPossibleDays = correspondingWorkPeriod.daysWorked - correspondingWorkPeriod.daysPaid - oldValue.days
277+
const maxPossibleDays = correspondingWorkPeriod.daysWorked - (correspondingWorkPeriod.daysPaid - oldValue.days)
283278
if (data.days > maxPossibleDays) {
284-
throw new errors.BadRequestError(`Days cannot be more than not paid days which is ${maxPossibleDays}`)
279+
throw new errors.BadRequestError(`Cannot update days paid to more than ${maxPossibleDays}, otherwise total paid days (${correspondingWorkPeriod.daysPaid - oldValue.days}) would be more that total worked days (${correspondingWorkPeriod.daysWorked}) for the week.`)
285280
}
286281
}
287282

@@ -312,8 +307,8 @@ partiallyUpdateWorkPeriodPayment.schema = Joi.object().keys({
312307
id: Joi.string().uuid().required(),
313308
data: Joi.object().keys({
314309
status: Joi.workPeriodPaymentUpdateStatus(),
315-
amount: Joi.number().min(0),
316-
days: Joi.number().integer(),
310+
amount: Joi.number().greater(0),
311+
days: Joi.number().integer().min(0).max(10),
317312
memberRate: Joi.number().positive(),
318313
customerRate: Joi.number().positive().allow(null),
319314
billingAccountId: Joi.number().positive().integer()

0 commit comments

Comments
 (0)