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

Commit aa6eb1c

Browse files
committed
Issue 639 - fix issues with api
1 parent a84d310 commit aa6eb1c

File tree

4 files changed

+188
-58
lines changed

4 files changed

+188
-58
lines changed

docs/swagger.yaml

Lines changed: 136 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,85 @@ tags:
1212
description: "Template files to serve as reference for multitude of tasks"
1313
- name: "uploads"
1414
description: "Upload files for batch processing"
15-
- name: "skills"
16-
description: "Skills endpoints"
17-
externalDocs:
18-
description: "Proxy to EMSI skills"
19-
url: "https://api.emsidata.com/apis/skills-classification#get-search-for-skills"
2015
schemes:
2116
- "https"
2217
- "http"
2318
paths:
2419
/templates:
20+
get:
21+
summary: "Get all templates"
22+
description: |
23+
"Return all templates. You can specify the date from and name when you would like the records.""
24+
tags:
25+
- "templates"
26+
operationId: "getTemplates"
27+
parameters:
28+
- name: "from"
29+
in: "query"
30+
description: "The date from when you would like the uploads (inclusive)"
31+
required: false
32+
type: "string"
33+
default: "today's value"
34+
- name: "name"
35+
in: "query"
36+
description: "The name of templates"
37+
required: false
38+
type: "string"
39+
responses:
40+
"200":
41+
description: "Success"
42+
schema:
43+
type: array
44+
items:
45+
$ref: '#/definitions/Template'
46+
"400":
47+
$ref: "#/definitions/BadRequest"
48+
"401":
49+
$ref: "#/definitions/Unauthorized"
50+
"403":
51+
$ref: "#/definitions/Forbidden"
52+
"404":
53+
$ref: "#/definitions/NotFound"
54+
"500":
55+
$ref: "#/definitions/ServerError"
56+
security:
57+
- api_key: []
58+
x-swagger-router-controller: "Templates"
59+
60+
head:
61+
summary: "Get only status code for fetching all templates"
62+
description: "Equivalent to GET /templates, but returns only status codes"
63+
tags:
64+
- "templates"
65+
operationId: "headTemplates"
66+
parameters:
67+
- name: "from"
68+
in: "query"
69+
description: "The date from when you would like the uploads (inclusive)"
70+
required: false
71+
type: "string"
72+
default: "today's value"
73+
- name: "organizationId"
74+
in: "query"
75+
description: "The name of templates"
76+
required: false
77+
type: "string"
78+
responses:
79+
"200":
80+
description: "Success"
81+
"400":
82+
$ref: "#/definitions/BadRequest"
83+
"401":
84+
$ref: "#/definitions/Unauthorized"
85+
"403":
86+
$ref: "#/definitions/Forbidden"
87+
"404":
88+
$ref: "#/definitions/NotFound"
89+
"500":
90+
$ref: "#/definitions/ServerError"
91+
security:
92+
- api_key: []
93+
x-swagger-router-controller: "Templates"
2594
post:
2695
tags:
2796
- "templates"
@@ -89,6 +158,29 @@ paths:
89158
security:
90159
- api_key: []
91160
x-swagger-router-controller: "Templates"
161+
head:
162+
tags:
163+
- "templates"
164+
summary: "Get only status code for getting template"
165+
description: "Equivalent to GET /templates/:id, but returns only status codes"
166+
operationId: "headTemplateById"
167+
produces:
168+
- "application/json"
169+
parameters: []
170+
responses:
171+
"200":
172+
description: "Success"
173+
"401":
174+
$ref: "#/definitions/Unauthorized"
175+
"403":
176+
$ref: "#/definitions/Forbidden"
177+
"404":
178+
$ref: "#/definitions/NotFound"
179+
"500":
180+
$ref: "#/definitions/ServerError"
181+
security:
182+
- api_key: []
183+
x-swagger-router-controller: "Templates"
92184
/uploads:
93185
get:
94186
summary: "Get all uploads"
@@ -104,6 +196,11 @@ paths:
104196
required: false
105197
type: "string"
106198
default: "today's value"
199+
- name: "organizationId"
200+
in: "query"
201+
description: "The organization id to associate with"
202+
required: true
203+
type: "string"
107204
responses:
108205
"200":
109206
description: "Success"
@@ -121,6 +218,9 @@ paths:
121218
$ref: "#/definitions/NotFound"
122219
"500":
123220
$ref: "#/definitions/ServerError"
221+
security:
222+
- api_key: []
223+
x-swagger-router-controller: "Uploads"
124224

125225
head:
126226
summary: "Get only status code for fetching all uploads"
@@ -135,6 +235,11 @@ paths:
135235
required: false
136236
type: "string"
137237
default: "today's value"
238+
- name: "organizationId"
239+
in: "query"
240+
description: "The organization id to associate with"
241+
required: true
242+
type: "string"
138243
responses:
139244
"200":
140245
description: "Success"
@@ -148,6 +253,9 @@ paths:
148253
$ref: "#/definitions/NotFound"
149254
"500":
150255
$ref: "#/definitions/ServerError"
256+
security:
257+
- api_key: []
258+
x-swagger-router-controller: "Uploads"
151259

152260
post:
153261
tags:
@@ -217,6 +325,29 @@ paths:
217325
security:
218326
- api_key: []
219327
x-swagger-router-controller: "Uploads"
328+
head:
329+
tags:
330+
- "uploads"
331+
summary: "Get only status code for getting details of an upload"
332+
description: "Equivalent to GET /uploads/:id, but returns only status codes"
333+
operationId: "headUploadById"
334+
produces:
335+
- "application/json"
336+
parameters: []
337+
responses:
338+
"200":
339+
description: "Success"
340+
"401":
341+
$ref: "#/definitions/Unauthorized"
342+
"403":
343+
$ref: "#/definitions/Forbidden"
344+
"404":
345+
$ref: "#/definitions/NotFound"
346+
"500":
347+
$ref: "#/definitions/ServerError"
348+
security:
349+
- api_key: []
350+
x-swagger-router-controller: "Uploads"
220351
patch:
221352
tags:
222353
- "uploads"
@@ -254,37 +385,6 @@ paths:
254385
security:
255386
- api_key: []
256387
x-swagger-router-controller: "Uploads"
257-
/skills:
258-
get:
259-
tags:
260-
- "skills"
261-
summary: "Search for skills by name using the q query parameter"
262-
description: "Responds with the skills search result. Proxy api to EMSI"
263-
operationId: "getSkills"
264-
produces:
265-
- "application/json"
266-
parameters:
267-
- name: "q"
268-
in: "query"
269-
description: "The skill to search for. All special characters must be URL encoded, eg. \"C++ Progr\" should be encoded \"C%2B%2B%20Progr\""
270-
required: false
271-
type: "string"
272-
responses:
273-
"200":
274-
description: "Success"
275-
schema:
276-
$ref: "#/definitions/Skill"
277-
"401":
278-
$ref: "#/definitions/Unauthorized"
279-
"403":
280-
$ref: "#/definitions/Forbidden"
281-
"404":
282-
$ref: "#/definitions/NotFound"
283-
"500":
284-
$ref: "#/definitions/ServerError"
285-
security:
286-
- api_key: []
287-
x-swagger-router-controller: "Skills"
288388
securityDefinitions:
289389
api_key:
290390
type: "apiKey"
@@ -335,26 +435,6 @@ definitions:
335435
type: "string"
336436
description: "The organization id to associate new users with"
337437
- $ref: "#/definitions/AuditFields"
338-
Skill:
339-
allOf:
340-
- type: "object"
341-
properties:
342-
skills:
343-
type: "array"
344-
items:
345-
properties:
346-
type:
347-
type: string
348-
description: The skill type
349-
example: 'Hard Skill'
350-
id:
351-
type: string
352-
description: The skill id
353-
example: 'KS1200364C9C1LK3V5Q1'
354-
name:
355-
type: string
356-
description: The skill name
357-
example: 'C (Programming Language)'
358438
AuditFields:
359439
type: "object"
360440
required:

src/controllers/TemplateController.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,18 @@ async function getEntity (req, res) {
2323
res.send(result)
2424
}
2525

26+
/**
27+
* Get template
28+
* @param {Object} req the request
29+
* @param {Object} res the response
30+
*/
31+
async function getEntities (req, res) {
32+
const result = await service.getEntities(req.query)
33+
res.send(result)
34+
}
35+
2636
module.exports = {
2737
uploadEntity,
28-
getEntity
38+
getEntity,
39+
getEntities
2940
}

src/routes.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@ module.exports = {
6262
auth: 'jwt',
6363
access: constants.AdminUser,
6464
scopes: [constants.Scopes.CreateTemplate, constants.Scopes.AllTemplate]
65+
},
66+
get: {
67+
controller: 'TemplateController',
68+
method: 'getEntities',
69+
auth: 'jwt',
70+
access: constants.AdminUser,
71+
scopes: [constants.Scopes.GetTemplate, constants.Scopes.AllTemplate]
6572
}
6673
},
6774
'/templates/:id': {

src/services/TemplateService.js

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,41 @@ uploadEntity.schema = {
5757
}).required()
5858
}
5959

60+
/**
61+
* Returns all templates (filtered by created date)
62+
* @param {Object} query the filter query
63+
* @returns {Object} the list of templates
64+
*/
65+
async function getEntities (query) {
66+
const filter = {}
67+
if (!query.from) {
68+
query.from = (new Date((new Date()).setDate((new Date()).getDate() - 1)).toISOString()) // 24 hours ago
69+
}
70+
filter.created = { ge: query.from }
71+
if (query.name) {
72+
filter.name = { contains: query.name }
73+
}
74+
const templates = await helper.getAll(config.AMAZON.DYNAMODB_TEMPLATE_TABLE, filter)
75+
const res = _.map(templates, (template) => {
76+
template = _.extend(
77+
_.omit(_.pickBy(template, _.isString), 'objectKey'), { url: helper.generateS3Url(template.objectKey) }
78+
)
79+
return template
80+
})
81+
return res
82+
}
83+
84+
getEntities.schema = {
85+
query: Joi.object().keys({
86+
from: Joi.string(),
87+
name: Joi.string()
88+
})
89+
}
90+
6091
module.exports = {
6192
getEntity,
62-
uploadEntity
93+
uploadEntity,
94+
getEntities
6395
}
6496

6597
logger.buildService(module.exports)

0 commit comments

Comments
 (0)