Skip to content

Commit 43c0fa2

Browse files
authored
Merge pull request #413 from eisbilir/update/process-payment
deny process payment for future WP
2 parents 5bdd97e + 740bde7 commit 43c0fa2

File tree

3 files changed

+9
-69
lines changed

3 files changed

+9
-69
lines changed

docs/Topcoder-bookings-api.postman_collection.json

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -12769,66 +12769,6 @@
1276912769
},
1277012770
"response": []
1277112771
},
12772-
{
12773-
"name": "search resource bookings with parameters 17",
12774-
"event": [
12775-
{
12776-
"listen": "test",
12777-
"script": {
12778-
"exec": [
12779-
"pm.test('Status code is 400', function () {\r",
12780-
" pm.response.to.have.status(400);\r",
12781-
" const response = pm.response.json()\r",
12782-
" pm.expect(response.message).to.eq(\"Cannot filter by both \\\"isFirstWeek\\\" and \\\"isLastWeek\\\" set to \\\"true\\\"\")\r",
12783-
"});"
12784-
],
12785-
"type": "text/javascript"
12786-
}
12787-
}
12788-
],
12789-
"request": {
12790-
"method": "GET",
12791-
"header": [
12792-
{
12793-
"key": "Authorization",
12794-
"type": "text",
12795-
"value": "Bearer {{token_bookingManager}}"
12796-
}
12797-
],
12798-
"url": {
12799-
"raw": "{{URL}}/resourceBookings?fields=id,startDate,endDate,billingAccountId,workPeriods&billingAccountId=80000071&workPeriods.startDate=2021-02-07&workPeriods.isLastWeek=true&workPeriods.isFirstWeek=true",
12800-
"host": [
12801-
"{{URL}}"
12802-
],
12803-
"path": [
12804-
"resourceBookings"
12805-
],
12806-
"query": [
12807-
{
12808-
"key": "fields",
12809-
"value": "id,startDate,endDate,billingAccountId,workPeriods"
12810-
},
12811-
{
12812-
"key": "billingAccountId",
12813-
"value": "80000071"
12814-
},
12815-
{
12816-
"key": "workPeriods.startDate",
12817-
"value": "2021-02-07"
12818-
},
12819-
{
12820-
"key": "workPeriods.isLastWeek",
12821-
"value": "true"
12822-
},
12823-
{
12824-
"key": "workPeriods.isFirstWeek",
12825-
"value": "true"
12826-
}
12827-
]
12828-
}
12829-
},
12830-
"response": []
12831-
},
1283212772
{
1283312773
"name": "put resource booking with booking manager",
1283412774
"event": [

src/services/ResourceBookingService.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,8 @@ async function searchResourceBookings (currentUser, criteria, options) {
619619
esQuery.body.query.bool.must.push({
620620
range: { startDate: { gte: criteria['workPeriods.startDate'] } }
621621
})
622-
} else if (criteria['workPeriods.isLastWeek']) {
622+
}
623+
if (criteria['workPeriods.isLastWeek']) {
623624
esQuery.body.query.bool.must.push({
624625
range: { endDate: { lte: moment(criteria['workPeriods.startDate']).add(6, 'day').format('YYYY-MM-DD') } }
625626
})
@@ -736,7 +737,8 @@ async function searchResourceBookings (currentUser, criteria, options) {
736737
}
737738
if (criteria['workPeriods.isFirstWeek']) {
738739
filter[Op.and].push({ startDate: { [Op.gte]: criteria['workPeriods.startDate'] } })
739-
} else if (criteria['workPeriods.isLastWeek']) {
740+
}
741+
if (criteria['workPeriods.isLastWeek']) {
740742
filter[Op.and].push({ endDate: { [Op.lte]: moment(criteria['workPeriods.startDate']).add(6, 'day').format('YYYY-MM-DD') } })
741743
}
742744
const queryCriteria = {
@@ -898,13 +900,7 @@ searchResourceBookings.schema = Joi.object().keys({
898900
}),
899901
'workPeriods.isLastWeek': Joi.boolean().when(Joi.ref('workPeriods.startDate', { separator: false }), {
900902
is: Joi.exist(),
901-
then: Joi.when(Joi.ref('workPeriods.isFirstWeek', { separator: false }), {
902-
is: false,
903-
then: Joi.boolean().default(false),
904-
otherwise: Joi.boolean().valid(false).messages({
905-
'any.only': 'Cannot filter by both "isFirstWeek" and "isLastWeek" set to "true"'
906-
})
907-
}),
903+
then: Joi.boolean().default(false),
908904
otherwise: Joi.boolean().valid(false).messages({
909905
'any.only': 'Cannot filter by "isLastWeek" without "startDate"'
910906
})

src/services/WorkPeriodPaymentService.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ async function _createSingleWorkPeriodPaymentWithWorkPeriodAndResourceBooking (w
7575
if (maxPossibleDays <= 0) {
7676
throw new errors.ConflictError(`There are no days to pay for WorkPeriod: ${correspondingWorkPeriod.id}`)
7777
}
78+
const workPeriodStartTime = moment(`${correspondingWorkPeriod.startDate}T00:00:00.000+12`)
79+
if (workPeriodStartTime.isAfter(moment())) {
80+
throw new errors.BadRequestError(`Cannot process payments for the future WorkPeriods. You can process after ${workPeriodStartTime.diff(moment(), 'hours')} hours`)
81+
}
7882
workPeriodPayment.days = _.defaultTo(workPeriodPayment.days, maxPossibleDays)
7983
workPeriodPayment.amount = _.round(workPeriodPayment.memberRate * workPeriodPayment.days / 5, 2)
8084
workPeriodPayment.customerRate = _.defaultTo(correspondingResourceBooking.customerRate, null)

0 commit comments

Comments
 (0)