diff --git a/docs/Topcoder-bookings-api.postman_collection.json b/docs/Topcoder-bookings-api.postman_collection.json index 04ab034f..8ee3ef14 100644 --- a/docs/Topcoder-bookings-api.postman_collection.json +++ b/docs/Topcoder-bookings-api.postman_collection.json @@ -12769,66 +12769,6 @@ }, "response": [] }, - { - "name": "search resource bookings with parameters 17", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test('Status code is 400', function () {\r", - " pm.response.to.have.status(400);\r", - " const response = pm.response.json()\r", - " pm.expect(response.message).to.eq(\"Cannot filter by both \\\"isFirstWeek\\\" and \\\"isLastWeek\\\" set to \\\"true\\\"\")\r", - "});" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "GET", - "header": [ - { - "key": "Authorization", - "type": "text", - "value": "Bearer {{token_bookingManager}}" - } - ], - "url": { - "raw": "{{URL}}/resourceBookings?fields=id,startDate,endDate,billingAccountId,workPeriods&billingAccountId=80000071&workPeriods.startDate=2021-02-07&workPeriods.isLastWeek=true&workPeriods.isFirstWeek=true", - "host": [ - "{{URL}}" - ], - "path": [ - "resourceBookings" - ], - "query": [ - { - "key": "fields", - "value": "id,startDate,endDate,billingAccountId,workPeriods" - }, - { - "key": "billingAccountId", - "value": "80000071" - }, - { - "key": "workPeriods.startDate", - "value": "2021-02-07" - }, - { - "key": "workPeriods.isLastWeek", - "value": "true" - }, - { - "key": "workPeriods.isFirstWeek", - "value": "true" - } - ] - } - }, - "response": [] - }, { "name": "put resource booking with booking manager", "event": [ diff --git a/src/services/ResourceBookingService.js b/src/services/ResourceBookingService.js index 7c5d0a59..46d2fe62 100644 --- a/src/services/ResourceBookingService.js +++ b/src/services/ResourceBookingService.js @@ -619,7 +619,8 @@ async function searchResourceBookings (currentUser, criteria, options) { esQuery.body.query.bool.must.push({ range: { startDate: { gte: criteria['workPeriods.startDate'] } } }) - } else if (criteria['workPeriods.isLastWeek']) { + } + if (criteria['workPeriods.isLastWeek']) { esQuery.body.query.bool.must.push({ range: { endDate: { lte: moment(criteria['workPeriods.startDate']).add(6, 'day').format('YYYY-MM-DD') } } }) @@ -736,7 +737,8 @@ async function searchResourceBookings (currentUser, criteria, options) { } if (criteria['workPeriods.isFirstWeek']) { filter[Op.and].push({ startDate: { [Op.gte]: criteria['workPeriods.startDate'] } }) - } else if (criteria['workPeriods.isLastWeek']) { + } + if (criteria['workPeriods.isLastWeek']) { filter[Op.and].push({ endDate: { [Op.lte]: moment(criteria['workPeriods.startDate']).add(6, 'day').format('YYYY-MM-DD') } }) } const queryCriteria = { @@ -898,13 +900,7 @@ searchResourceBookings.schema = Joi.object().keys({ }), 'workPeriods.isLastWeek': Joi.boolean().when(Joi.ref('workPeriods.startDate', { separator: false }), { is: Joi.exist(), - then: Joi.when(Joi.ref('workPeriods.isFirstWeek', { separator: false }), { - is: false, - then: Joi.boolean().default(false), - otherwise: Joi.boolean().valid(false).messages({ - 'any.only': 'Cannot filter by both "isFirstWeek" and "isLastWeek" set to "true"' - }) - }), + then: Joi.boolean().default(false), otherwise: Joi.boolean().valid(false).messages({ 'any.only': 'Cannot filter by "isLastWeek" without "startDate"' }) diff --git a/src/services/WorkPeriodPaymentService.js b/src/services/WorkPeriodPaymentService.js index 72b94d44..9a7a7780 100644 --- a/src/services/WorkPeriodPaymentService.js +++ b/src/services/WorkPeriodPaymentService.js @@ -75,6 +75,10 @@ async function _createSingleWorkPeriodPaymentWithWorkPeriodAndResourceBooking (w if (maxPossibleDays <= 0) { throw new errors.ConflictError(`There are no days to pay for WorkPeriod: ${correspondingWorkPeriod.id}`) } + const workPeriodStartTime = moment(`${correspondingWorkPeriod.startDate}T00:00:00.000+12`) + if (workPeriodStartTime.isAfter(moment())) { + throw new errors.BadRequestError(`Cannot process payments for the future WorkPeriods. You can process after ${workPeriodStartTime.diff(moment(), 'hours')} hours`) + } workPeriodPayment.days = _.defaultTo(workPeriodPayment.days, maxPossibleDays) workPeriodPayment.amount = _.round(workPeriodPayment.memberRate * workPeriodPayment.days / 5, 2) workPeriodPayment.customerRate = _.defaultTo(correspondingResourceBooking.customerRate, null)