Skip to content

Feature/add job ids #264

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
May 27, 2021
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
107 changes: 107 additions & 0 deletions docs/Topcoder-bookings-api.postman_collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,113 @@
},
"response": []
},
{
"name": "search jobs with request body",
"protocolProfileBehavior": {
"disableBodyPruning": true
},
"request": {
"method": "GET",
"header": [
{
"key": "Authorization",
"type": "text",
"value": "Bearer {{token_bookingManager}}"
}
],
"body": {
"mode": "raw",
"raw": "{\r\n \"jobIds\": [\"{{jobId}}\",\"{{jobIdCreatedByM2M}}\"]\r\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{URL}}/jobs",
"host": [
"{{URL}}"
],
"path": [
"jobs"
],
"query": [
{
"key": "page",
"value": "0",
"disabled": true
},
{
"key": "perPage",
"value": "3",
"disabled": true
},
{
"key": "sortBy",
"value": "id",
"disabled": true
},
{
"key": "sortOrder",
"value": "asc",
"disabled": true
},
{
"key": "projectId",
"value": "21",
"disabled": true
},
{
"key": "externalId",
"value": "1212",
"disabled": true
},
{
"key": "description",
"value": "Dummy",
"disabled": true
},
{
"key": "startDate",
"value": "2020-09-27T04:17:23.131Z",
"disabled": true
},
{
"key": "resourceType",
"value": "Dummy Resource Type",
"disabled": true
},
{
"key": "skill",
"value": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
"disabled": true
},
{
"key": "rateType",
"value": "hourly",
"disabled": true
},
{
"key": "status",
"value": "sourcing",
"disabled": true
},
{
"key": "workload",
"value": "full-time",
"disabled": true
},
{
"key": "title",
"value": "dummy",
"disabled": true
}
]
}
},
"response": []
},
{
"name": "search jobs with with m2m all",
"request": {
Expand Down
14 changes: 14 additions & 0 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,11 @@ paths:
type: string
enum: ["sourcing", "in-review", "assigned", "closed", "cancelled"]
description: The rate type.
requestBody:
content:
application/json:
schema:
$ref: "#/components/schemas/JobSearchBody"
responses:
"200":
description: OK
Expand Down Expand Up @@ -3363,6 +3368,15 @@ components:
type: string
example: "topcoder user"
description: "The user who updated the job last time.(Will get the user info from the token)"
JobSearchBody:
properties:
jobIds:
type: array
items:
type: string
format: uuid
description: "The array of job ids"

JobRequestBody:
required:
- projectId
Expand Down
3 changes: 3 additions & 0 deletions src/controllers/JobController.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ async function deleteJob (req, res) {
* @param res the response
*/
async function searchJobs (req, res) {
if (req.body && req.body.jobIds) {
req.query.jobIds = req.body.jobIds
}
const result = await service.searchJobs(req.authUser, req.query)
helper.setResHeaders(req, res, result)
res.send(result.result)
Expand Down
23 changes: 18 additions & 5 deletions src/services/JobService.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,8 @@ async function searchJobs (currentUser, criteria, options = { returnAll: false }
body: {
query: {
bool: {
must: []
must: [],
filter: []
}
},
from: (page - 1) * perPage,
Expand Down Expand Up @@ -393,11 +394,19 @@ async function searchJobs (currentUser, criteria, options = { returnAll: false }
})
// 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: {
_id: criteria.jobIds
}
})
}
logger.debug({ component: 'JobService', context: 'searchJobs', message: `Query: ${JSON.stringify(esQuery)}` })

Expand All @@ -422,7 +431,7 @@ async function searchJobs (currentUser, criteria, options = { returnAll: false }
logger.logFullError(err, { component: 'JobService', context: 'searchJobs' })
}
logger.info({ component: 'JobService', context: 'searchJobs', message: 'fallback to DB query' })
const filter = {}
const filter = { [Op.and]: [] }
_.each(_.pick(criteria, [
'projectId',
'externalId',
Expand All @@ -449,6 +458,9 @@ async function searchJobs (currentUser, criteria, options = { returnAll: false }
[Op.contains]: [criteria.skills]
}
}
if (criteria.jobIds && criteria.jobIds.length > 0) {
filter[Op.and].push({ id: criteria.jobIds })
}
const jobs = await Job.findAll({
where: filter,
offset: ((page - 1) * perPage),
Expand Down Expand Up @@ -486,7 +498,8 @@ searchJobs.schema = Joi.object().keys({
rateType: Joi.rateType(),
workload: Joi.workload(),
status: Joi.jobStatus(),
projectIds: Joi.array().items(Joi.number().integer()).single()
projectIds: Joi.array().items(Joi.number().integer()).single(),
jobIds: Joi.array().items(Joi.string().uuid())
}).required(),
options: Joi.object()
}).required()
Expand Down