Skip to content

deny process payment for future WP #413

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 2 commits into from
Jul 21, 2021
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
60 changes: 0 additions & 60 deletions docs/Topcoder-bookings-api.postman_collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
14 changes: 5 additions & 9 deletions src/services/ResourceBookingService.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') } }
})
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -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"'
})
Expand Down
4 changes: 4 additions & 0 deletions src/services/WorkPeriodPaymentService.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down