Skip to content

update: allow up to 10 daysWorked #434

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 3 commits into from
Jul 31, 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
58 changes: 5 additions & 53 deletions docs/Topcoder-bookings-api.postman_collection.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"info": {
"_postman_id": "0bd597ba-4bc2-4ea1-be33-45776b80c1ce",
"_postman_id": "8ead1433-9679-46de-9baa-d27d59106673",
"name": "Topcoder-bookings-api",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
Expand Down Expand Up @@ -15486,7 +15486,7 @@
"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(\"\\\"data.daysWorked\\\" must be less than or equal to 5\")\r",
" pm.expect(response.message).to.eq(\"\\\"data.daysWorked\\\" must be less than or equal to 10\")\r",
"});"
],
"type": "text/javascript"
Expand All @@ -15504,55 +15504,7 @@
],
"body": {
"mode": "raw",
"raw": "{\r\n \"daysWorked\": 6\r\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{URL}}/work-periods/{{workPeriodId-1}}",
"host": [
"{{URL}}"
],
"path": [
"work-periods",
"{{workPeriodId-1}}"
]
}
},
"response": []
},
{
"name": "patch work period with invalid parameter 4",
"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(\"Maximum allowed daysWorked is (4)\")\r",
"});"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "PATCH",
"header": [
{
"key": "Authorization",
"type": "text",
"value": "Bearer {{token_bookingManager}}"
}
],
"body": {
"mode": "raw",
"raw": "{\r\n \"daysWorked\": 5\r\n}",
"raw": "{\r\n \"daysWorked\": 11\r\n}",
"options": {
"raw": {
"language": "json"
Expand Down Expand Up @@ -16508,7 +16460,7 @@
"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(\"\\\"workPeriodPayment.days\\\" must be less than or equal to 5\")\r",
" pm.expect(response.message).to.eq(\"\\\"workPeriodPayment.days\\\" must be less than or equal to 10\")\r",
"});"
],
"type": "text/javascript"
Expand All @@ -16526,7 +16478,7 @@
],
"body": {
"mode": "raw",
"raw": "{\r\n \"workPeriodId\": \"{{workPeriodId-3}}\",\r\n \"days\": 6\r\n}",
"raw": "{\r\n \"workPeriodId\": \"{{workPeriodId-3}}\",\r\n \"days\": 11\r\n}",
"options": {
"raw": {
"language": "json"
Expand Down
34 changes: 27 additions & 7 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3947,7 +3947,7 @@ components:
"job-closed",
"offered",
"withdrawn",
"withdrawn-prescreen"
"withdrawn-prescreen",
]
description: "The job candidate status."
externalId:
Expand Down Expand Up @@ -4049,7 +4049,26 @@ components:
type: array
items:
type: string
enum: ["open", "placed", "selected", "client rejected - screening", "client rejected - interview", "rejected - other", "cancelled", "interview", "topcoder-rejected", "applied", "rejected-pre-screen", "skills-test", "phone-screen", "job-closed", "offered", "withdrawn", "withdrawn-prescreen"]
enum:
[
"open",
"placed",
"selected",
"client rejected - screening",
"client rejected - interview",
"rejected - other",
"cancelled",
"interview",
"topcoder-rejected",
"applied",
"rejected-pre-screen",
"skills-test",
"phone-screen",
"job-closed",
"offered",
"withdrawn",
"withdrawn-prescreen",
]
description: "The array of job Candidates status"
JobCandidateRequestBody:
required:
Expand Down Expand Up @@ -4085,7 +4104,7 @@ components:
"job-closed",
"offered",
"withdrawn",
"withdrawn-prescreen"
"withdrawn-prescreen",
]
description: "The job candidate status."
default: open
Expand Down Expand Up @@ -4123,7 +4142,7 @@ components:
"job-closed",
"offered",
"withdrawn",
"withdrawn-prescreen"
"withdrawn-prescreen",
]
externalId:
type: string
Expand Down Expand Up @@ -4644,7 +4663,7 @@ components:
daysWorked:
type: integer
minimum: 0
maximum: 5
maximum: 10
example: 2
description: "The count of the days worked for that work period."
daysPaid:
Expand Down Expand Up @@ -4696,6 +4715,8 @@ components:
properties:
daysWorked:
type: integer
minimum: 0
maximum: 10
example: 2
description: "The count of the days worked for that work period."
WorkPeriodPayment:
Expand Down Expand Up @@ -5275,7 +5296,7 @@ components:
"job-closed",
"offered",
"withdrawn",
"withdrawn-prescreen"
"withdrawn-prescreen",
]
description: "The job candidate status."
skills:
Expand Down Expand Up @@ -5872,4 +5893,3 @@ components:
properties:
message:
type: string

12 changes: 8 additions & 4 deletions src/eventHandlers/ResourceBookingEventHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,13 @@ async function updateWorkPeriods (payload) {
const originalFirstWeek = _.find(workPeriods, ['startDate', firstWeek.startDate])
const existentFirstWeek = _.minBy(workPeriods, 'startDate')
// recalculate daysWorked for the first week of existent workPeriods and daysWorked have changed
if (firstWeek.startDate === existentFirstWeek.startDate && firstWeek.daysWorked !== existentFirstWeek.daysWorked) {
if (firstWeek.startDate === existentFirstWeek.startDate && firstWeek.daysWorked !== existentFirstWeek.daysWorked &&
existentFirstWeek.daysPaid <= firstWeek.daysWorked) {
workPeriodsToUpdate.push(_.assign(firstWeek, { id: originalFirstWeek.id }))
// if first of intersected workPeriods is not the first one of existent workPeriods
// we only check if it's daysWorked exceeds the possible maximum
} else if (originalFirstWeek.daysWorked > firstWeek.daysWorked) {
} else if (originalFirstWeek.daysWorked > firstWeek.daysWorked &&
originalFirstWeek.daysPaid <= firstWeek.daysWorked) {
workPeriodsToUpdate.push(_.assign(firstWeek, { id: originalFirstWeek.id }))
}
}
Expand All @@ -201,11 +203,13 @@ async function updateWorkPeriods (payload) {
const originalLastWeek = _.find(workPeriods, ['startDate', lastWeek.startDate])
const existentLastWeek = _.maxBy(workPeriods, 'startDate')
// recalculate daysWorked for the last week of existent workPeriods and daysWorked have changed
if (lastWeek.startDate === existentLastWeek.startDate && lastWeek.daysWorked !== existentLastWeek.daysWorked) {
if (lastWeek.startDate === existentLastWeek.startDate && lastWeek.daysWorked !== existentLastWeek.daysWorked &&
existentLastWeek.daysPaid <= lastWeek.daysWorked) {
workPeriodsToUpdate.push(_.assign(lastWeek, { id: originalLastWeek.id }))
// if last of intersected workPeriods is not the last one of existent workPeriods
// we only check if it's daysWorked exceeds the possible maximum
} else if (originalLastWeek.daysWorked > lastWeek.daysWorked) {
} else if (originalLastWeek.daysWorked > lastWeek.daysWorked &&
originalLastWeek.daysPaid <= lastWeek.daysWorked) {
workPeriodsToUpdate.push(_.assign(lastWeek, { id: originalLastWeek.id }))
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/services/ResourceBookingService.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ async function _ensurePaidWorkPeriodsNotDeleted (resourceBookingId, oldValue, ne
// or any of it's WorkPeriodsPayment has status 'completed' or 'in-progress'.
_checkForPaidWorkPeriods(workPeriodsToRemove)
// check if this update makes maximum possible daysWorked value less than daysPaid
/* https://github.com/topcoder-platform/taas-apis/issues/428
_.each(newWorkPeriods, newWP => {
const wp = _.find(workPeriods, ['startDate', newWP.startDate])
if (!wp) {
Expand All @@ -260,6 +261,7 @@ async function _ensurePaidWorkPeriodsNotDeleted (resourceBookingId, oldValue, ne
throw new errors.ConflictError(`Cannot make maximum daysWorked (${newWP.daysWorked}) to the value less than daysPaid (${wp.daysPaid}) for WorkPeriod: ${wp.id}`)
}
})
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why this check is not valid anymore?
It looks like if we allow maximum 10 working days, we still should not allow this value to be less than daysPaid.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this checks if daysPaid exceeds maximum possible daysWorked.
maximum possible daysWorked is calculated regarding the startDay and endDate.
this check won't let us update any RB which has a WP has more paid daysWorked than expected (1-5).
So I moved the part of the logic we need to eventHandler, I don't allow to lower daysWorked less then daysPaid regardless of dates here:
https://github.com/eisbilir/taas-apis/blob/cb194d63722be0d8b6e1b040172c3236cfeadcd0/src/eventHandlers/ResourceBookingEventHandler.js#L192
https://github.com/eisbilir/taas-apis/blob/cb194d63722be0d8b6e1b040172c3236cfeadcd0/src/eventHandlers/ResourceBookingEventHandler.js#L197
https://github.com/eisbilir/taas-apis/blob/cb194d63722be0d8b6e1b040172c3236cfeadcd0/src/eventHandlers/ResourceBookingEventHandler.js#L207
https://github.com/eisbilir/taas-apis/blob/cb194d63722be0d8b6e1b040172c3236cfeadcd0/src/eventHandlers/ResourceBookingEventHandler.js#L212

Example 1
WP-1 has 4 daysWorked as maximum.
daysWorked was increased to 7.
payment was processed and daysPaid increased to 2.
RB dates updated and it forced WP-1 to have 3 daysWorked.
I will allow both RB dates and WP-1 daysWorked (3) to be updated.

Example 2
WP-1 has 4 daysWorked as maximum.
daysWorked was increased to 7.
payment was processed and daysPaid increased to 6.
RB dates updated and it forced WP-1 to have 3 daysWorked.
I will allow RB dates to be updated but WP-1 will keep it daysWorked at 7, same as before update.

WP-1 refers to 1st week.
we use recalculating of daysWorked logic for only the first and the last WP.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, got it.

}

/**
Expand Down Expand Up @@ -906,7 +908,7 @@ searchResourceBookings.schema = Joi.object().keys({
})
}),
'workPeriods.payments.status': Joi.workPeriodPaymentStatus(),
'workPeriods.payments.days': Joi.number().integer().min(0).max(5)
'workPeriods.payments.days': Joi.number().integer().min(0).max(10)
}).required(),
options: Joi.object().keys({
returnAll: Joi.boolean().default(false),
Expand Down
2 changes: 1 addition & 1 deletion src/services/WorkPeriodPaymentService.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ async function createWorkPeriodPayment (currentUser, workPeriodPayment) {

const singleCreateWorkPeriodPaymentSchema = Joi.object().keys({
workPeriodId: Joi.string().uuid().required(),
days: Joi.number().integer().min(0).max(5),
days: Joi.number().integer().min(0).max(10),
amount: Joi.when('days', {
is: Joi.number().integer().valid(0).exist(),
then: Joi.number().greater(0).required().messages({
Expand Down
4 changes: 3 additions & 1 deletion src/services/WorkPeriodService.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,9 +273,11 @@ async function updateWorkPeriod (currentUser, id, data) {
if (_.isNil(thisWeek)) {
throw new errors.ConflictError('Work Period dates are not compatible with Resource Booking dates')
}
/* https://github.com/topcoder-platform/taas-apis/issues/428
if (thisWeek.daysWorked < data.daysWorked) {
throw new errors.BadRequestError(`Maximum allowed daysWorked is (${thisWeek.daysWorked})`)
}
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we allow up to 10 and don't care about RB.endDate anymore, let's remove this code.

data.paymentStatus = helper.calculateWorkPeriodPaymentStatus(_.assign({}, oldValue, data))
data.updatedBy = await helper.getUserId(currentUser.userId)
const updated = await workPeriod.update(data)
Expand All @@ -300,7 +302,7 @@ partiallyUpdateWorkPeriod.schema = Joi.object().keys({
currentUser: Joi.object().required(),
id: Joi.string().uuid().required(),
data: Joi.object().keys({
daysWorked: Joi.number().integer().min(0).max(5)
daysWorked: Joi.number().integer().min(0).max(10)
}).required().min(1)
}).required()

Expand Down