Skip to content
2 changes: 1 addition & 1 deletion src/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Joi.rateType = () => Joi.string().valid('hourly', 'daily', 'weekly', 'monthly')
Joi.jobStatus = () => Joi.string().valid('sourcing', 'in-review', 'assigned', 'closed', 'cancelled')
Joi.resourceBookingStatus = () => Joi.string().valid('placed', 'closed', 'cancelled')
Joi.workload = () => Joi.string().valid('full-time', 'fractional')
Joi.jobCandidateStatus = () => Joi.string().valid('open', 'placed', 'selected', 'client rejected - screening', 'client rejected - interview', 'rejected - other', 'cancelled', 'interview', 'topcoder-rejected')
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')
Joi.title = () => Joi.string().max(128)
Joi.paymentStatus = () => Joi.string().valid('pending', 'partially-completed', 'completed', 'cancelled')
Joi.xaiTemplate = () => Joi.string().valid(...allowedXAITemplate)
Expand Down
3 changes: 0 additions & 3 deletions src/common/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -725,9 +725,6 @@ function getPageLink(req, page) {
* @param {Object} result the operation result
*/
function setResHeaders(req, res, result) {
if (result.fromDb) {
return;
}
const totalPages = Math.ceil(result.total / result.perPage);
if (result.page > 1) {
res.set('X-Prev-Page', result.page - 1);
Expand Down
4 changes: 3 additions & 1 deletion src/eventHandlers/ResourceBookingEventHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,9 @@ async function updateWorkPeriods (payload) {
raw: true
})
// gather workPeriod dates
const newWorkPeriods = helper.extractWorkPeriods(payload.value.startDate || payload.options.oldValue.startDate, payload.value.endDate || payload.options.oldValue.endDate)
const newWorkPeriods = helper.extractWorkPeriods(
_.isUndefined(payload.value.startDate) ? payload.options.oldValue.startDate : payload.value.startDate,
_.isUndefined(payload.value.endDate) ? payload.options.oldValue.endDate : payload.value.endDate)
// find which workPeriods should be removed
const workPeriodsToRemove = _.differenceBy(workPeriods, newWorkPeriods, 'startDate')
// find which workperiods should be created
Expand Down
4 changes: 2 additions & 2 deletions src/services/PaymentService.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ async function createChallenge (challenge, token) {

if (challenge.billingAccountId) {
body.billing = {
billingAccountId: challenge.billingAccountId,
markup: 0 // for TaaS payments we always use 0 markup
billingAccountId: _.toString(challenge.billingAccountId),
markup: 0 // for TaaS payments we always use 0 markup
}
}
try {
Expand Down
42 changes: 25 additions & 17 deletions src/services/ResourceBookingService.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,9 @@ async function _ensurePaidWorkPeriodsNotDeleted (resourceBookingId, oldValue, ne
return
}
// gather workPeriod dates from provided dates
const newWorkPeriods = helper.extractWorkPeriods(newValue.startDate || oldValue.startDate, newValue.endDate || oldValue.endDate)
const newWorkPeriods = helper.extractWorkPeriods(
_.isUndefined(newValue.startDate) ? oldValue.startDate : newValue.startDate,
_.isUndefined(newValue.endDate) ? oldValue.endDate : newValue.endDate)
// find which workPeriods should be removed
const workPeriodsToRemove = _.differenceBy(workPeriods, newWorkPeriods, 'startDate')
// we can't delete workperiods with paymentStatus 'partially-completed' or 'completed'.
Expand Down Expand Up @@ -470,21 +472,15 @@ async function searchResourceBookings (currentUser, criteria, options = { return
criteria.sortOrder = 'desc'
}
try {
throw new Error('fallback to DB')
const esQuery = {
index: config.get('esConfig.ES_INDEX_RESOURCE_BOOKING'),
_source_includes: queryOpt.include,
_source_excludes: ['workPeriods.payments', ...queryOpt.excludeRB, ...queryOpt.excludeWP],
body: {
query: {
bool: {
must: [
{
nested: {
path: 'workPeriods',
query: { bool: { must: [] } }
}
}
]
must: []
}
},
from: (page - 1) * perPage,
Expand Down Expand Up @@ -526,22 +522,33 @@ async function searchResourceBookings (currentUser, criteria, options = { return
}]
}
// Apply WorkPeriod filters
_.each(_.pick(criteria, ['workPeriods.paymentStatus', 'workPeriods.startDate', 'workPeriods.endDate', 'workPeriods.userHandle']), (value, key) => {
esQuery.body.query.bool.must[0].nested.query.bool.must.push({
term: {
[key]: {
value
const workPeriodFilters = ['workPeriods.paymentStatus', 'workPeriods.startDate', 'workPeriods.endDate', 'workPeriods.userHandle']
if (_.intersection(criteria, workPeriodFilters).length > 0) {
const workPeriodsMust = []
_.each(_.pick(criteria, workPeriodFilters), (value, key) => {
workPeriodsMust.push({
term: {
[key]: {
value
}
}
})
})

esQuery.body.query.bool.must.push({
nested: {
path: 'workPeriods',
query: { bool: { must: workPeriodsMust } }
}
})
})
}
logger.debug({ component: 'ResourceBookingService', context: 'searchResourceBookings', message: `Query: ${JSON.stringify(esQuery)}` })

const { body } = await esClient.search(esQuery)
let resourceBookings = _.map(body.hits.hits, '_source')
// ESClient will return ResourceBookings with it's all nested WorkPeriods
// We re-apply WorkPeriod filters
_.each(_.pick(criteria, ['workPeriods.startDate', 'workPeriods.endDate', 'workPeriods.userHandle', 'workPeriods.paymentStatus']), (value, key) => {
_.each(_.pick(criteria, workPeriodFilters), (value, key) => {
key = key.split('.')[1]
_.each(resourceBookings, r => {
r.workPeriods = _.filter(r.workPeriods, { [key]: value })
Expand Down Expand Up @@ -612,9 +619,10 @@ async function searchResourceBookings (currentUser, criteria, options = { return
queryCriteria.order = [[{ model: WorkPeriod, as: 'workPeriods' }, _.split(criteria.sortBy, '.')[1], criteria.sortOrder]]
}
const resourceBookings = await ResourceBooking.findAll(queryCriteria)
const total = await ResourceBooking.count(_.omit(queryCriteria, ['limit', 'offset', 'attributes', 'order']))
return {
fromDb: true,
total: resourceBookings.length,
total,
page,
perPage,
result: resourceBookings
Expand Down