Skip to content

Commit de72b27

Browse files
authored
Merge pull request #267 from mbaghel/feature/role-intake
Feature/role intake
2 parents 95d7488 + 1ced875 commit de72b27

File tree

5 files changed

+31
-24
lines changed

5 files changed

+31
-24
lines changed

src/bootstrap.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Joi.rateType = () => Joi.string().valid('hourly', 'daily', 'weekly', 'monthly')
1616
Joi.jobStatus = () => Joi.string().valid('sourcing', 'in-review', 'assigned', 'closed', 'cancelled')
1717
Joi.resourceBookingStatus = () => Joi.string().valid('placed', 'closed', 'cancelled')
1818
Joi.workload = () => Joi.string().valid('full-time', 'fractional')
19-
Joi.jobCandidateStatus = () => Joi.string().valid('open', 'placed', 'selected', 'client rejected - screening', 'client rejected - interview', 'rejected - other', 'cancelled', 'interview', 'topcoder-rejected')
19+
Joi.jobCandidateStatus = () => Joi.string().valid('open', 'placed', 'selected', 'client rejected - screening', 'client rejected - interview', 'rejected - other', 'cancelled', 'interview', 'topcoder-rejected', 'applied','rejected-pre-screen','skills-test','skills-test','phone-screen','job-closed')
2020
Joi.title = () => Joi.string().max(128)
2121
Joi.paymentStatus = () => Joi.string().valid('pending', 'partially-completed', 'completed', 'cancelled')
2222
Joi.xaiTemplate = () => Joi.string().valid(...allowedXAITemplate)

src/common/helper.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -725,9 +725,6 @@ function getPageLink(req, page) {
725725
* @param {Object} result the operation result
726726
*/
727727
function setResHeaders(req, res, result) {
728-
if (result.fromDb) {
729-
return;
730-
}
731728
const totalPages = Math.ceil(result.total / result.perPage);
732729
if (result.page > 1) {
733730
res.set('X-Prev-Page', result.page - 1);

src/eventHandlers/ResourceBookingEventHandler.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,9 @@ async function updateWorkPeriods (payload) {
169169
raw: true
170170
})
171171
// gather workPeriod dates
172-
const newWorkPeriods = helper.extractWorkPeriods(payload.value.startDate || payload.options.oldValue.startDate, payload.value.endDate || payload.options.oldValue.endDate)
172+
const newWorkPeriods = helper.extractWorkPeriods(
173+
_.isUndefined(payload.value.startDate) ? payload.options.oldValue.startDate : payload.value.startDate,
174+
_.isUndefined(payload.value.endDate) ? payload.options.oldValue.endDate : payload.value.endDate)
173175
// find which workPeriods should be removed
174176
const workPeriodsToRemove = _.differenceBy(workPeriods, newWorkPeriods, 'startDate')
175177
// find which workperiods should be created

src/services/PaymentService.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ async function createChallenge (challenge, token) {
8484

8585
if (challenge.billingAccountId) {
8686
body.billing = {
87-
billingAccountId: challenge.billingAccountId,
88-
markup: 0 // for TaaS payments we always use 0 markup
87+
billingAccountId: _.toString(challenge.billingAccountId),
88+
markup: 0 // for TaaS payments we always use 0 markup
8989
}
9090
}
9191
try {

src/services/ResourceBookingService.js

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,9 @@ async function _ensurePaidWorkPeriodsNotDeleted (resourceBookingId, oldValue, ne
194194
return
195195
}
196196
// gather workPeriod dates from provided dates
197-
const newWorkPeriods = helper.extractWorkPeriods(newValue.startDate || oldValue.startDate, newValue.endDate || oldValue.endDate)
197+
const newWorkPeriods = helper.extractWorkPeriods(
198+
_.isUndefined(newValue.startDate) ? oldValue.startDate : newValue.startDate,
199+
_.isUndefined(newValue.endDate) ? oldValue.endDate : newValue.endDate)
198200
// find which workPeriods should be removed
199201
const workPeriodsToRemove = _.differenceBy(workPeriods, newWorkPeriods, 'startDate')
200202
// we can't delete workperiods with paymentStatus 'partially-completed' or 'completed'.
@@ -470,21 +472,15 @@ async function searchResourceBookings (currentUser, criteria, options = { return
470472
criteria.sortOrder = 'desc'
471473
}
472474
try {
475+
throw new Error('fallback to DB')
473476
const esQuery = {
474477
index: config.get('esConfig.ES_INDEX_RESOURCE_BOOKING'),
475478
_source_includes: queryOpt.include,
476479
_source_excludes: ['workPeriods.payments', ...queryOpt.excludeRB, ...queryOpt.excludeWP],
477480
body: {
478481
query: {
479482
bool: {
480-
must: [
481-
{
482-
nested: {
483-
path: 'workPeriods',
484-
query: { bool: { must: [] } }
485-
}
486-
}
487-
]
483+
must: []
488484
}
489485
},
490486
from: (page - 1) * perPage,
@@ -526,22 +522,33 @@ async function searchResourceBookings (currentUser, criteria, options = { return
526522
}]
527523
}
528524
// Apply WorkPeriod filters
529-
_.each(_.pick(criteria, ['workPeriods.paymentStatus', 'workPeriods.startDate', 'workPeriods.endDate', 'workPeriods.userHandle']), (value, key) => {
530-
esQuery.body.query.bool.must[0].nested.query.bool.must.push({
531-
term: {
532-
[key]: {
533-
value
525+
const workPeriodFilters = ['workPeriods.paymentStatus', 'workPeriods.startDate', 'workPeriods.endDate', 'workPeriods.userHandle']
526+
if (_.intersection(criteria, workPeriodFilters).length > 0) {
527+
const workPeriodsMust = []
528+
_.each(_.pick(criteria, workPeriodFilters), (value, key) => {
529+
workPeriodsMust.push({
530+
term: {
531+
[key]: {
532+
value
533+
}
534534
}
535+
})
536+
})
537+
538+
esQuery.body.query.bool.must.push({
539+
nested: {
540+
path: 'workPeriods',
541+
query: { bool: { must: workPeriodsMust } }
535542
}
536543
})
537-
})
544+
}
538545
logger.debug({ component: 'ResourceBookingService', context: 'searchResourceBookings', message: `Query: ${JSON.stringify(esQuery)}` })
539546

540547
const { body } = await esClient.search(esQuery)
541548
let resourceBookings = _.map(body.hits.hits, '_source')
542549
// ESClient will return ResourceBookings with it's all nested WorkPeriods
543550
// We re-apply WorkPeriod filters
544-
_.each(_.pick(criteria, ['workPeriods.startDate', 'workPeriods.endDate', 'workPeriods.userHandle', 'workPeriods.paymentStatus']), (value, key) => {
551+
_.each(_.pick(criteria, workPeriodFilters), (value, key) => {
545552
key = key.split('.')[1]
546553
_.each(resourceBookings, r => {
547554
r.workPeriods = _.filter(r.workPeriods, { [key]: value })
@@ -612,9 +619,10 @@ async function searchResourceBookings (currentUser, criteria, options = { return
612619
queryCriteria.order = [[{ model: WorkPeriod, as: 'workPeriods' }, _.split(criteria.sortBy, '.')[1], criteria.sortOrder]]
613620
}
614621
const resourceBookings = await ResourceBooking.findAll(queryCriteria)
622+
const total = await ResourceBooking.count(_.omit(queryCriteria, ['limit', 'offset', 'attributes', 'order']))
615623
return {
616624
fromDb: true,
617-
total: resourceBookings.length,
625+
total,
618626
page,
619627
perPage,
620628
result: resourceBookings

0 commit comments

Comments
 (0)