Skip to content

Commit d603038

Browse files
author
dengjun
committed
rb jobIds added
1 parent 77b415e commit d603038

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

docs/swagger.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1557,6 +1557,11 @@ paths:
15571557
maximum: 5
15581558
example: 3
15591559
description: The workdays to pay
1560+
requestBody:
1561+
content:
1562+
application/json:
1563+
schema:
1564+
$ref: "#/components/schemas/ResourceBookingSearchBody"
15601565

15611566
responses:
15621567
"200":
@@ -4449,6 +4454,14 @@ components:
44494454
type: string
44504455
example: "topcoder user"
44514456
description: "The user who updated the job last time.(Will get the user info from the token)"
4457+
ResourceBookingSearchBody:
4458+
properties:
4459+
jobIds:
4460+
type: array
4461+
items:
4462+
type: string
4463+
format: uuid
4464+
description: "The array of job ids"
44524465
ResourceBookingRequestBody:
44534466
required:
44544467
- projectId

src/controllers/ResourceBookingController.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* Controller for ResourceBooking endpoints
33
*/
44
const HttpStatus = require('http-status-codes')
5+
const _ = require('lodash')
56
const service = require('../services/ResourceBookingService')
67
const helper = require('../common/helper')
78

@@ -57,7 +58,8 @@ async function deleteResourceBooking (req, res) {
5758
* @param res the response
5859
*/
5960
async function searchResourceBookings (req, res) {
60-
const result = await service.searchResourceBookings(req.authUser, req.query)
61+
const query = { ...req.query, jobIds: _.get(req, 'body.jobIds', []) }
62+
const result = await service.searchResourceBookings(req.authUser, query)
6163
helper.setResHeaders(req, res, result)
6264
res.send(result.result)
6365
}

src/services/ResourceBookingService.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,8 @@ async function searchResourceBookings (currentUser, criteria, options) {
556556
body: {
557557
query: {
558558
bool: {
559-
must: []
559+
must: [],
560+
filter: []
560561
}
561562
},
562563
from: (page - 1) * perPage,
@@ -600,11 +601,19 @@ async function searchResourceBookings (currentUser, criteria, options) {
600601
})
601602
// if criteria contains projectIds, filter projectId with this value
602603
if (criteria.projectIds) {
603-
esQuery.body.query.bool.filter = [{
604+
esQuery.body.query.bool.filter.push({
604605
terms: {
605606
projectId: criteria.projectIds
606607
}
607-
}]
608+
})
609+
}
610+
// if criteria contains jobIds, filter jobIds with this value
611+
if (criteria.jobIds && criteria.jobIds.length > 0) {
612+
esQuery.body.query.bool.filter.push({
613+
terms: {
614+
jobId: criteria.jobIds
615+
}
616+
})
608617
}
609618
// Apply WorkPeriod and WorkPeriodPayment filters
610619
const workPeriodFilters = _.pick(criteria, ['workPeriods.paymentStatus', 'workPeriods.startDate', 'workPeriods.endDate', 'workPeriods.userHandle'])
@@ -710,6 +719,9 @@ async function searchResourceBookings (currentUser, criteria, options) {
710719
if (criteria.projectIds) {
711720
filter[Op.and].push({ projectId: criteria.projectIds })
712721
}
722+
if (criteria.jobIds && criteria.jobIds.length > 0) {
723+
filter[Op.and].push({ id: criteria.jobIds })
724+
}
713725
const queryCriteria = {
714726
where: filter,
715727
offset: ((page - 1) * perPage),
@@ -831,6 +843,7 @@ searchResourceBookings.schema = Joi.object().keys({
831843
endDate: Joi.date().format('YYYY-MM-DD'),
832844
rateType: Joi.rateType(),
833845
jobId: Joi.string().uuid(),
846+
jobIds: Joi.array().items(Joi.string().uuid()),
834847
userId: Joi.string().uuid(),
835848
projectId: Joi.number().integer(),
836849
projectIds: Joi.alternatives(

0 commit comments

Comments
 (0)