Skip to content
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
13 changes: 13 additions & 0 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1557,6 +1557,11 @@ paths:
maximum: 5
example: 3
description: The workdays to pay
requestBody:
content:
application/json:
schema:
$ref: "#/components/schemas/ResourceBookingSearchBody"

responses:
"200":
Expand Down Expand Up @@ -4449,6 +4454,14 @@ components:
type: string
example: "topcoder user"
description: "The user who updated the job last time.(Will get the user info from the token)"
ResourceBookingSearchBody:
properties:
jobIds:
type: array
items:
type: string
format: uuid
description: "The array of job ids"
ResourceBookingRequestBody:
required:
- projectId
Expand Down
4 changes: 3 additions & 1 deletion src/controllers/ResourceBookingController.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Controller for ResourceBooking endpoints
*/
const HttpStatus = require('http-status-codes')
const _ = require('lodash')
const service = require('../services/ResourceBookingService')
const helper = require('../common/helper')

Expand Down Expand Up @@ -57,7 +58,8 @@ async function deleteResourceBooking (req, res) {
* @param res the response
*/
async function searchResourceBookings (req, res) {
const result = await service.searchResourceBookings(req.authUser, req.query)
const query = { ...req.query, jobIds: _.get(req, 'body.jobIds', []) }
const result = await service.searchResourceBookings(req.authUser, query)
helper.setResHeaders(req, res, result)
res.send(result.result)
}
Expand Down
19 changes: 16 additions & 3 deletions src/services/ResourceBookingService.js
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,8 @@ async function searchResourceBookings (currentUser, criteria, options) {
body: {
query: {
bool: {
must: []
must: [],
filter: []
}
},
from: (page - 1) * perPage,
Expand Down Expand Up @@ -600,11 +601,19 @@ async function searchResourceBookings (currentUser, criteria, options) {
})
// if criteria contains projectIds, filter projectId with this value
if (criteria.projectIds) {
esQuery.body.query.bool.filter = [{
esQuery.body.query.bool.filter.push({
terms: {
projectId: criteria.projectIds
}
}]
})
}
// if criteria contains jobIds, filter jobIds with this value
if (criteria.jobIds && criteria.jobIds.length > 0) {
esQuery.body.query.bool.filter.push({
terms: {
jobId: criteria.jobIds
}
})
}
// Apply WorkPeriod and WorkPeriodPayment filters
const workPeriodFilters = _.pick(criteria, ['workPeriods.paymentStatus', 'workPeriods.startDate', 'workPeriods.endDate', 'workPeriods.userHandle'])
Expand Down Expand Up @@ -710,6 +719,9 @@ async function searchResourceBookings (currentUser, criteria, options) {
if (criteria.projectIds) {
filter[Op.and].push({ projectId: criteria.projectIds })
}
if (criteria.jobIds && criteria.jobIds.length > 0) {
filter[Op.and].push({ id: criteria.jobIds })
}
const queryCriteria = {
where: filter,
offset: ((page - 1) * perPage),
Expand Down Expand Up @@ -831,6 +843,7 @@ searchResourceBookings.schema = Joi.object().keys({
endDate: Joi.date().format('YYYY-MM-DD'),
rateType: Joi.rateType(),
jobId: Joi.string().uuid(),
jobIds: Joi.array().items(Joi.string().uuid()),
userId: Joi.string().uuid(),
projectId: Joi.number().integer(),
projectIds: Joi.alternatives(
Expand Down