From d60303829eec7f5433ad0d5792f586c24cecceba Mon Sep 17 00:00:00 2001 From: dengjun Date: Sat, 17 Jul 2021 13:55:54 +0800 Subject: [PATCH] rb jobIds added --- docs/swagger.yaml | 13 +++++++++++++ src/controllers/ResourceBookingController.js | 4 +++- src/services/ResourceBookingService.js | 19 ++++++++++++++++--- 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/docs/swagger.yaml b/docs/swagger.yaml index e566edf7..48d1efb0 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -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": @@ -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 diff --git a/src/controllers/ResourceBookingController.js b/src/controllers/ResourceBookingController.js index f8d3d566..24fafcd7 100644 --- a/src/controllers/ResourceBookingController.js +++ b/src/controllers/ResourceBookingController.js @@ -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') @@ -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) } diff --git a/src/services/ResourceBookingService.js b/src/services/ResourceBookingService.js index cabadca0..e3411588 100644 --- a/src/services/ResourceBookingService.js +++ b/src/services/ResourceBookingService.js @@ -556,7 +556,8 @@ async function searchResourceBookings (currentUser, criteria, options) { body: { query: { bool: { - must: [] + must: [], + filter: [] } }, from: (page - 1) * perPage, @@ -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']) @@ -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), @@ -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(