Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit 25b3a9a

Browse files
author
dengjun
committed
ci:adding new API in earn-app
1 parent 7a865ea commit 25b3a9a

File tree

6 files changed

+123
-1
lines changed

6 files changed

+123
-1
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ workflows:
7676
filters:
7777
branches:
7878
only:
79-
- dev
79+
- gigs-optimize-b
8080

8181
# Production builds are exectuted only on tagged commits to the
8282
# master branch.

src/api/app-constants.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
const Scopes = {
66
// JobApplication
77
READ_JOBAPPLICATION: "read:earn-jobApplications",
8+
READ_JOB: "read:earn-job",
89
READ_PROFILE: "read:earn-profile",
910
WRITE_PROFILE: "write:earn-profile",
1011
ALL_PROFILE: "all:earn-profile",

src/api/controllers/JobApplicationController.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ async function getMyJobApplications(req, res) {
1515
res.send(result.result);
1616
}
1717

18+
async function getJob(req, res) {
19+
const result = await service.getJob(req.authUser, req.query);
20+
res.send(result);
21+
}
22+
1823
module.exports = {
1924
getMyJobApplications,
25+
getJob,
2026
};

src/api/docs/swagger.yaml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,60 @@ paths:
8888
application/json:
8989
schema:
9090
$ref: "#/components/schemas/Error"
91+
/job:
92+
get:
93+
tags:
94+
- Job
95+
description: |
96+
Check whether the Job Application info has been synced.
97+
98+
**Authorization** All topcoder members are allowed.
99+
security:
100+
- bearerAuth: []
101+
parameters:
102+
- in: query
103+
name: externalId
104+
required: true
105+
schema:
106+
type: string
107+
description: The Job External Id
108+
responses:
109+
"200":
110+
description: OK
111+
content:
112+
application/json:
113+
schema:
114+
$ref: "#/components/schemas/JobSynced"
115+
"400":
116+
description: Bad request
117+
content:
118+
application/json:
119+
schema:
120+
$ref: "#/components/schemas/Error"
121+
"401":
122+
description: Not authenticated
123+
content:
124+
application/json:
125+
schema:
126+
$ref: "#/components/schemas/Error"
127+
"403":
128+
description: Forbidden
129+
content:
130+
application/json:
131+
schema:
132+
$ref: "#/components/schemas/Error"
133+
"404":
134+
description: Not Found
135+
content:
136+
application/json:
137+
schema:
138+
$ref: "#/components/schemas/Error"
139+
"500":
140+
description: Internal Server Error
141+
content:
142+
application/json:
143+
schema:
144+
$ref: "#/components/schemas/Error"
91145
/profile:
92146
get:
93147
tags:
@@ -187,6 +241,14 @@ components:
187241
scheme: bearer
188242
bearerFormat: JWT
189243
schemas:
244+
JobSynced:
245+
required:
246+
- synced
247+
properties:
248+
synced:
249+
type: boolean
250+
description: "Whether the job application has been synced"
251+
example: true
190252
JobApplication:
191253
required:
192254
- title

src/api/routes/JobApplicationRoutes.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,12 @@ module.exports = {
1212
scopes: [constants.Scopes.READ_JOBAPPLICATION],
1313
},
1414
},
15+
"/job": {
16+
get: {
17+
controller: "JobApplicationController",
18+
method: "getJob",
19+
auth: "jwt",
20+
scopes: [constants.Scopes.READ_JOB],
21+
},
22+
},
1523
};

src/api/services/JobApplicationService.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,51 @@ getMyJobApplications.schema = Joi.object()
9696
})
9797
.required();
9898

99+
async function getJob(currentUser, criteria) {
100+
const emptyResult = {
101+
synced: false,
102+
};
103+
// we expect logged-in users
104+
if (currentUser.isMachine) {
105+
return emptyResult;
106+
}
107+
// get user id by calling taas-api with current user's token
108+
const { id: userId } = await helper.getCurrentUserDetails(
109+
currentUser.jwtToken
110+
);
111+
if (!userId) {
112+
throw new errors.NotFoundError(
113+
`Id for user: ${currentUser.userId} not found`
114+
);
115+
}
116+
// get job based on the jobExternalId
117+
const { result: jobs } = await helper.getJobs(criteria);
118+
if (jobs && jobs.length) {
119+
const candidates = jobs[0].candidates || [];
120+
const newJob = candidates.find((item) => item.userId == userId);
121+
if (newJob) {
122+
return {
123+
synced: true,
124+
};
125+
}
126+
}
127+
return {
128+
synced: false,
129+
};
130+
}
131+
132+
getJob.schema = Joi.object()
133+
.keys({
134+
currentUser: Joi.object().required(),
135+
criteria: Joi.object()
136+
.keys({
137+
externalId: Joi.string(),
138+
})
139+
.required(),
140+
})
141+
.required();
142+
99143
module.exports = {
100144
getMyJobApplications,
145+
getJob,
101146
};

0 commit comments

Comments
 (0)