Skip to content

Commit edbff4e

Browse files
authored
Merge pull request #264 from topcoder-platform/feature/add-jobIds
Feature/add job ids
2 parents 1320187 + f5ae061 commit edbff4e

File tree

4 files changed

+142
-5
lines changed

4 files changed

+142
-5
lines changed

docs/Topcoder-bookings-api.postman_collection.json

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,113 @@
491491
},
492492
"response": []
493493
},
494+
{
495+
"name": "search jobs with request body",
496+
"protocolProfileBehavior": {
497+
"disableBodyPruning": true
498+
},
499+
"request": {
500+
"method": "GET",
501+
"header": [
502+
{
503+
"key": "Authorization",
504+
"type": "text",
505+
"value": "Bearer {{token_bookingManager}}"
506+
}
507+
],
508+
"body": {
509+
"mode": "raw",
510+
"raw": "{\r\n \"jobIds\": [\"{{jobId}}\",\"{{jobIdCreatedByM2M}}\"]\r\n}",
511+
"options": {
512+
"raw": {
513+
"language": "json"
514+
}
515+
}
516+
},
517+
"url": {
518+
"raw": "{{URL}}/jobs",
519+
"host": [
520+
"{{URL}}"
521+
],
522+
"path": [
523+
"jobs"
524+
],
525+
"query": [
526+
{
527+
"key": "page",
528+
"value": "0",
529+
"disabled": true
530+
},
531+
{
532+
"key": "perPage",
533+
"value": "3",
534+
"disabled": true
535+
},
536+
{
537+
"key": "sortBy",
538+
"value": "id",
539+
"disabled": true
540+
},
541+
{
542+
"key": "sortOrder",
543+
"value": "asc",
544+
"disabled": true
545+
},
546+
{
547+
"key": "projectId",
548+
"value": "21",
549+
"disabled": true
550+
},
551+
{
552+
"key": "externalId",
553+
"value": "1212",
554+
"disabled": true
555+
},
556+
{
557+
"key": "description",
558+
"value": "Dummy",
559+
"disabled": true
560+
},
561+
{
562+
"key": "startDate",
563+
"value": "2020-09-27T04:17:23.131Z",
564+
"disabled": true
565+
},
566+
{
567+
"key": "resourceType",
568+
"value": "Dummy Resource Type",
569+
"disabled": true
570+
},
571+
{
572+
"key": "skill",
573+
"value": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
574+
"disabled": true
575+
},
576+
{
577+
"key": "rateType",
578+
"value": "hourly",
579+
"disabled": true
580+
},
581+
{
582+
"key": "status",
583+
"value": "sourcing",
584+
"disabled": true
585+
},
586+
{
587+
"key": "workload",
588+
"value": "full-time",
589+
"disabled": true
590+
},
591+
{
592+
"key": "title",
593+
"value": "dummy",
594+
"disabled": true
595+
}
596+
]
597+
}
598+
},
599+
"response": []
600+
},
494601
{
495602
"name": "search jobs with with m2m all",
496603
"request": {

docs/swagger.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,11 @@ paths:
181181
type: string
182182
enum: ["sourcing", "in-review", "assigned", "closed", "cancelled"]
183183
description: The rate type.
184+
requestBody:
185+
content:
186+
application/json:
187+
schema:
188+
$ref: "#/components/schemas/JobSearchBody"
184189
responses:
185190
"200":
186191
description: OK
@@ -3363,6 +3368,15 @@ components:
33633368
type: string
33643369
example: "topcoder user"
33653370
description: "The user who updated the job last time.(Will get the user info from the token)"
3371+
JobSearchBody:
3372+
properties:
3373+
jobIds:
3374+
type: array
3375+
items:
3376+
type: string
3377+
format: uuid
3378+
description: "The array of job ids"
3379+
33663380
JobRequestBody:
33673381
required:
33683382
- projectId

src/controllers/JobController.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ async function deleteJob (req, res) {
5757
* @param res the response
5858
*/
5959
async function searchJobs (req, res) {
60+
if (req.body && req.body.jobIds) {
61+
req.query.jobIds = req.body.jobIds
62+
}
6063
const result = await service.searchJobs(req.authUser, req.query)
6164
helper.setResHeaders(req, res, result)
6265
res.send(result.result)

src/services/JobService.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,8 @@ async function searchJobs (currentUser, criteria, options = { returnAll: false }
344344
body: {
345345
query: {
346346
bool: {
347-
must: []
347+
must: [],
348+
filter: []
348349
}
349350
},
350351
from: (page - 1) * perPage,
@@ -393,11 +394,19 @@ async function searchJobs (currentUser, criteria, options = { returnAll: false }
393394
})
394395
// If criteria contains projectIds, filter projectId with this value
395396
if (criteria.projectIds) {
396-
esQuery.body.query.bool.filter = [{
397+
esQuery.body.query.bool.filter.push({
397398
terms: {
398399
projectId: criteria.projectIds
399400
}
400-
}]
401+
})
402+
}
403+
// if criteria contains jobIds, filter jobIds with this value
404+
if (criteria.jobIds && criteria.jobIds.length > 0) {
405+
esQuery.body.query.bool.filter.push({
406+
terms: {
407+
_id: criteria.jobIds
408+
}
409+
})
401410
}
402411
logger.debug({ component: 'JobService', context: 'searchJobs', message: `Query: ${JSON.stringify(esQuery)}` })
403412

@@ -422,7 +431,7 @@ async function searchJobs (currentUser, criteria, options = { returnAll: false }
422431
logger.logFullError(err, { component: 'JobService', context: 'searchJobs' })
423432
}
424433
logger.info({ component: 'JobService', context: 'searchJobs', message: 'fallback to DB query' })
425-
const filter = {}
434+
const filter = { [Op.and]: [] }
426435
_.each(_.pick(criteria, [
427436
'projectId',
428437
'externalId',
@@ -449,6 +458,9 @@ async function searchJobs (currentUser, criteria, options = { returnAll: false }
449458
[Op.contains]: [criteria.skills]
450459
}
451460
}
461+
if (criteria.jobIds && criteria.jobIds.length > 0) {
462+
filter[Op.and].push({ id: criteria.jobIds })
463+
}
452464
const jobs = await Job.findAll({
453465
where: filter,
454466
offset: ((page - 1) * perPage),
@@ -486,7 +498,8 @@ searchJobs.schema = Joi.object().keys({
486498
rateType: Joi.rateType(),
487499
workload: Joi.workload(),
488500
status: Joi.jobStatus(),
489-
projectIds: Joi.array().items(Joi.number().integer()).single()
501+
projectIds: Joi.array().items(Joi.number().integer()).single(),
502+
jobIds: Joi.array().items(Joi.string().uuid())
490503
}).required(),
491504
options: Joi.object()
492505
}).required()

0 commit comments

Comments
 (0)