Skip to content

Commit dc1cfa4

Browse files
author
dengjun
committed
Add JobIds to /jobs endpoint:30185451
1 parent 2ad5544 commit dc1cfa4

File tree

4 files changed

+186
-14
lines changed

4 files changed

+186
-14
lines changed

docs/Topcoder-bookings-api.postman_collection.json

Lines changed: 108 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"info": {
3-
"_postman_id": "3f80d93d-6ca3-4645-970d-a9e533394e2e",
3+
"_postman_id": "4b866040-1336-427b-9e20-56d809b87519",
44
"name": "Topcoder-bookings-api",
55
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
66
},
@@ -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: 57 additions & 8 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
@@ -3317,6 +3322,15 @@ components:
33173322
type: string
33183323
example: "topcoder user"
33193324
description: "The user who updated the job last time.(Will get the user info from the token)"
3325+
JobSearchBody:
3326+
properties:
3327+
jobIds:
3328+
type: array
3329+
items:
3330+
type: string
3331+
format: uuid
3332+
description: "The array of job ids"
3333+
33203334
JobRequestBody:
33213335
required:
33223336
- projectId
@@ -3517,7 +3531,18 @@ components:
35173531
description: "The user id."
35183532
status:
35193533
type: string
3520-
enum: ["open", "placed", "selected", "client rejected - screening", "client rejected - interview", "rejected - other", "cancelled", "interview", "topcoder-rejected"]
3534+
enum:
3535+
[
3536+
"open",
3537+
"placed",
3538+
"selected",
3539+
"client rejected - screening",
3540+
"client rejected - interview",
3541+
"rejected - other",
3542+
"cancelled",
3543+
"interview",
3544+
"topcoder-rejected",
3545+
]
35213546
description: "The job candidate status."
35223547
default: open
35233548
externalId:
@@ -3632,7 +3657,15 @@ components:
36323657
description: "Interview end time."
36333658
status:
36343659
type: string
3635-
enum: ["Scheduling", "Scheduled", "Requested for reschedule", "Rescheduled", "Completed", "Cancelled"]
3660+
enum:
3661+
[
3662+
"Scheduling",
3663+
"Scheduled",
3664+
"Requested for reschedule",
3665+
"Rescheduled",
3666+
"Completed",
3667+
"Cancelled",
3668+
]
36363669
description: "The interview status."
36373670
rescheduleUrl:
36383671
type: string
@@ -3678,7 +3711,15 @@ components:
36783711
format: email
36793712
status:
36803713
type: string
3681-
enum: ["Scheduling", "Scheduled", "Requested for reschedule", "Rescheduled", "Completed", "Cancelled"]
3714+
enum:
3715+
[
3716+
"Scheduling",
3717+
"Scheduled",
3718+
"Requested for reschedule",
3719+
"Rescheduled",
3720+
"Completed",
3721+
"Cancelled",
3722+
]
36823723
default: "Scheduling"
36833724
description: "The interview status."
36843725
UpdateInterviewRequestBody:
@@ -3737,7 +3778,15 @@ components:
37373778
description: "Interview end time."
37383779
status:
37393780
type: string
3740-
enum: ["Scheduling", "Scheduled", "Requested for reschedule", "Rescheduled", "Completed", "Cancelled"]
3781+
enum:
3782+
[
3783+
"Scheduling",
3784+
"Scheduled",
3785+
"Requested for reschedule",
3786+
"Rescheduled",
3787+
"Completed",
3788+
"Cancelled",
3789+
]
37413790
description: "The interview status."
37423791
rescheduleUrl:
37433792
type: string
@@ -3845,7 +3894,7 @@ components:
38453894
billingAccountId:
38463895
type: integer
38473896
example: 80000071
3848-
description: 'the billing account id for payments'
3897+
description: "the billing account id for payments"
38493898
createdAt:
38503899
type: string
38513900
format: date-time
@@ -3913,7 +3962,7 @@ components:
39133962
billingAccountId:
39143963
type: integer
39153964
example: 80000071
3916-
description: 'the billing account id for payments'
3965+
description: "the billing account id for payments"
39173966
ResourceBookingPatchRequestBody:
39183967
properties:
39193968
status:
@@ -3946,7 +3995,7 @@ components:
39463995
billingAccountId:
39473996
type: integer
39483997
example: 80000071
3949-
description: 'the billing account id for payments'
3998+
description: "the billing account id for payments"
39503999
WorkPeriod:
39514000
required:
39524001
- id
@@ -4130,7 +4179,7 @@ components:
41304179
billingAccountId:
41314180
type: integer
41324181
example: 80000071
4133-
description: 'the billing account id for payments'
4182+
description: "the billing account id for payments"
41344183
createdAt:
41354184
type: string
41364185
format: date-time

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)