Skip to content

Commit db00fbd

Browse files
committed
1 parent 010451d commit db00fbd

File tree

7 files changed

+35
-279
lines changed

7 files changed

+35
-279
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
.env
2+
node_modules

docs/skills-api.postman_collection.json

Lines changed: 3 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"info": {
3-
"_postman_id": "8d22bd52-0b64-43a5-9db3-c8516cb3e371",
3+
"_postman_id": "f4b1365c-fcee-492c-848a-c7c5a49a779f",
44
"name": "skills-api",
55
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
66
},
@@ -90,41 +90,7 @@
9090
],
9191
"body": {
9292
"mode": "raw",
93-
"raw": "{\n \"name\": \"taxonomies_update12\",\n \"metadata\": {\n \"version\": \"1.0.0\"\n }\n}"
94-
},
95-
"url": {
96-
"raw": "{{HOST}}/taxonomies/{{taxonomyId}}",
97-
"host": [
98-
"{{HOST}}"
99-
],
100-
"path": [
101-
"taxonomies",
102-
"{{taxonomyId}}"
103-
]
104-
}
105-
},
106-
"response": []
107-
},
108-
{
109-
"name": "{{HOST}}/taxonomies/:id",
110-
"request": {
111-
"method": "PUT",
112-
"header": [
113-
{
114-
"key": "Authorization",
115-
"type": "text",
116-
"value": "Bearer {{token}}"
117-
},
118-
{
119-
"key": "Content-Type",
120-
"name": "Content-Type",
121-
"type": "text",
122-
"value": "application/json"
123-
}
124-
],
125-
"body": {
126-
"mode": "raw",
127-
"raw": "{\n \"name\": \"taxonomies_update\",\n \"metadata\": {\n \"new_metadata_field\": \"value\"\n }\n}"
93+
"raw": "{\n \"metadata\": {\n \"version\": \"1.0.0\"\n }\n}"
12894
},
12995
"url": {
13096
"raw": "{{HOST}}/taxonomies/{{taxonomyId}}",
@@ -319,41 +285,7 @@
319285
],
320286
"body": {
321287
"mode": "raw",
322-
"raw": "{\n \"name\": \"skill_name_update23\",\n \"metadata\": {\n \"memberProminence\": \"0.75\",\n \"version\": \"0.1.0\"\n }\n}"
323-
},
324-
"url": {
325-
"raw": "{{HOST}}/skills/{{skillId}}",
326-
"host": [
327-
"{{HOST}}"
328-
],
329-
"path": [
330-
"skills",
331-
"{{skillId}}"
332-
]
333-
}
334-
},
335-
"response": []
336-
},
337-
{
338-
"name": "{{HOST}}/skills/:id",
339-
"request": {
340-
"method": "PUT",
341-
"header": [
342-
{
343-
"key": "Authorization",
344-
"type": "text",
345-
"value": "Bearer {{token}}"
346-
},
347-
{
348-
"key": "Content-Type",
349-
"name": "Content-Type",
350-
"type": "text",
351-
"value": "application/json"
352-
}
353-
],
354-
"body": {
355-
"mode": "raw",
356-
"raw": "{\n\t\"taxonomyId\":\"{{taxonomyId}}\",\n\t\"name\":\"jump6\",\n \"metadata\": {\n \"challengeProminence\": \"0.2\"\n }\n}"
288+
"raw": "{\n \"metadata\": {\n \"memberProminence\": \"0.75\",\n \"version\": \"0.1.0\"\n }\n}"
357289
},
358290
"url": {
359291
"raw": "{{HOST}}/skills/{{skillId}}",

docs/swagger.yaml

Lines changed: 28 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -303,55 +303,7 @@ paths:
303303
name: "body"
304304
required: true
305305
schema:
306-
$ref: "#/definitions/SkillUpdateRequestBody"
307-
responses:
308-
"200":
309-
description: "OK - the request was successful"
310-
schema:
311-
$ref: "#/definitions/Skill"
312-
"400":
313-
$ref: "#/definitions/BadRequest"
314-
"401":
315-
$ref: "#/definitions/Unauthorized"
316-
"403":
317-
$ref: "#/definitions/Forbidden"
318-
"404":
319-
$ref: "#/definitions/NotFound"
320-
"409":
321-
$ref: "#/definitions/Conflict"
322-
"500":
323-
$ref: "#/definitions/ServerError"
324-
security:
325-
- Bearer: []
326-
x-swagger-router-controller: "Skills"
327-
328-
put:
329-
tags:
330-
- "Skills"
331-
description: >
332-
Fully update an existing skill with given id.
333-
334-
335-
**PERMISSION**
336-
337-
1. permission `UPDATE_SKILL` is required to perform this operation
338-
339-
2. permission `ADD_SKILL_METADATA` is required if new metadata fields are provided.
340-
341-
3. permission `DELETE_SKILL_METADATA` is required if there is any existing metadata field in the skill.
342-
operationId: "skillsSkillIdPUT"
343-
parameters:
344-
- name: "skillId"
345-
in: "path"
346-
description: "The skill id"
347-
required: true
348-
type: "string"
349-
format: "UUID"
350-
- in: "body"
351-
name: "body"
352-
required: true
353-
schema:
354-
$ref: "#/definitions/SkillRequestBody"
306+
$ref: "#/definitions/SkillPatchRequestBody"
355307
responses:
356308
"200":
357309
description: "OK - the request was successful"
@@ -611,54 +563,7 @@ paths:
611563
name: "body"
612564
required: true
613565
schema:
614-
$ref: "#/definitions/TaxonomyUpdateRequestBody"
615-
responses:
616-
"200":
617-
description: "OK - the request was successful"
618-
schema:
619-
$ref: "#/definitions/Taxonomy"
620-
"400":
621-
$ref: "#/definitions/BadRequest"
622-
"401":
623-
$ref: "#/definitions/Unauthorized"
624-
"403":
625-
$ref: "#/definitions/Forbidden"
626-
"404":
627-
$ref: "#/definitions/NotFound"
628-
"409":
629-
$ref: "#/definitions/Conflict"
630-
"500":
631-
$ref: "#/definitions/ServerError"
632-
security:
633-
- Bearer: []
634-
x-swagger-router-controller: "Taxonomy"
635-
put:
636-
tags:
637-
- "Taxonomies"
638-
description: >
639-
Fully update an existing taxonomy with given id.
640-
641-
642-
**PERMISSION**
643-
644-
1. permission `UPDATE_TAXONOMY` is required to perform this operation
645-
646-
2. permission `ADD_TAXONOMY_METADATA` is required if any metadata field is provided.
647-
648-
3. permission `DELETE_TAXONOMY_METADATA` is required if there is any existing metadata field in the taxonomy.
649-
operationId: "skillstaxonomiestaxonomyIdPUT"
650-
parameters:
651-
- name: "taxonomyId"
652-
in: "path"
653-
description: "The taxonomy id"
654-
required: true
655-
type: "string"
656-
format: "UUID"
657-
- in: "body"
658-
name: "body"
659-
required: true
660-
schema:
661-
$ref: "#/definitions/TaxonomyRequestBody"
566+
$ref: "#/definitions/TaxonomyPatchRequestBody"
662567
responses:
663568
"200":
664569
description: "OK - the request was successful"
@@ -788,6 +693,23 @@ definitions:
788693
metadata:
789694
challengeProminence: "challengeProminence"
790695
memberProminence: "memberProminence"
696+
SkillPatchRequestBody:
697+
type: "object"
698+
properties:
699+
metadata:
700+
type: "object"
701+
description: "The metadata for the skill"
702+
properties:
703+
challengeProminence:
704+
type: "string"
705+
description: "The challenge prominence ranging from [0, 1]"
706+
memberProminence:
707+
type: "string"
708+
description: "The member prominence ranging from [0, 1]"
709+
example:
710+
metadata:
711+
challengeProminence: "challengeProminence"
712+
memberProminence: "memberProminence"
791713
Taxonomy:
792714
allOf:
793715
- type: "object"
@@ -831,6 +753,15 @@ definitions:
831753
name: "name"
832754
metadata:
833755
random_field_name_01: random_value_01
756+
TaxonomyPatchRequestBody:
757+
type: "object"
758+
properties:
759+
metadata:
760+
type: "object"
761+
description: "The metadata of the taxonomy."
762+
example:
763+
metadata:
764+
random_field_name_01: random_value_01
834765
Unauthorized:
835766
type: "object"
836767
properties:

src/modules/skill/route.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,6 @@ module.exports = {
3030
auth: 'jwt',
3131
permission: 'skill.edit'
3232
},
33-
put: {
34-
method: Controller.fullyUpdate,
35-
auth: 'jwt',
36-
permission: 'skill.edit'
37-
},
3833
delete: {
3934
method: Controller.remove,
4035
auth: 'jwt',

src/modules/skill/service.js

Lines changed: 2 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ create.schema = {
6969
}
7070

7171
/**
72-
* Update skill by id. Used in functions patch and fullyUpdate.
72+
* Update skill by id. Used in functions patch.
7373
*
7474
* @param instance the skill instance
7575
* @param updateData the data to be updated
@@ -115,14 +115,6 @@ async function patch (id, entity, auth) {
115115
// check if the skill exists or not
116116
const instance = await dbHelper.get(Skill, id)
117117

118-
if (entity.taxonomyId && entity.taxonomyId !== instance.taxonomyId) {
119-
// check if the taxonomy exists or not
120-
await dbHelper.get(Taxonomy, entity.taxonomyId)
121-
}
122-
123-
// check if the skill has conflict or not
124-
await dbHelper.makeSureUnique(Skill, { ...entity, id }, uniqueFields)
125-
126118
if (entity.metadata) {
127119
const inputFields = Object.keys(entity.metadata)
128120
const existingFields = Object.keys(instance.metadata)
@@ -138,7 +130,7 @@ async function patch (id, entity, auth) {
138130
}
139131
}
140132

141-
const updateData = { ...instance, ...entity, metadata: { ...instance.metadata, ...entity.metadata } }
133+
const updateData = { ...instance, metadata: { ...instance.metadata, ...entity.metadata } }
142134

143135
return update(instance, updateData, auth)
144136
}
@@ -158,56 +150,6 @@ patch.schema = {
158150
auth: joi.object()
159151
}
160152

161-
/**
162-
* Fully update skill by id.
163-
* Existing metadata fields would be entirely replace with the new ones.
164-
*
165-
* @param id the skill id
166-
* @param entity the request skill entity
167-
* @param auth the auth object
168-
* @return the updated skill
169-
*/
170-
async function fullyUpdate (id, entity, auth) {
171-
// check if the skill exists or not
172-
const instance = await dbHelper.get(Skill, id)
173-
174-
if (entity.taxonomyId !== instance.taxonomyId) {
175-
// check if the taxonomy exists or not
176-
await dbHelper.get(Taxonomy, entity.taxonomyId)
177-
}
178-
179-
// check if the skill has conflict or not
180-
await dbHelper.makeSureUnique(Skill, { ...entity, id }, uniqueFields)
181-
182-
if (Object.keys(entity.metadata).length) {
183-
// check permission for adding new metadata fields
184-
serviceHelper.hasPermission(PERMISSION.ADD_SKILL_METADATA, auth)
185-
}
186-
if (Object.keys(instance.metadata).length) {
187-
// check permission for removing existing metadata fields
188-
serviceHelper.hasPermission(PERMISSION.DELETE_SKILL_METADATA, auth)
189-
}
190-
191-
const updateData = entity
192-
193-
return update(instance, updateData, auth)
194-
}
195-
196-
fullyUpdate.schema = {
197-
id: joi.string().uuid().required(),
198-
entity: joi.object().keys({
199-
taxonomyId: joi.string().uuid().required(),
200-
name: joi.string().required(),
201-
uri: joi.string().default(null),
202-
externalId: joi.string().default(null),
203-
metadata: joi.object().keys({
204-
challengeProminence: joi.prominence('challengeProminence'),
205-
memberProminence: joi.prominence('memberProminence')
206-
}).unknown(true).required()
207-
}).required(),
208-
auth: joi.object()
209-
}
210-
211153
/**
212154
* get skill by id
213155
* @param id the skill id
@@ -333,7 +275,6 @@ module.exports = {
333275
create,
334276
search,
335277
patch,
336-
fullyUpdate,
337278
get,
338279
remove
339280
}

src/modules/taxonomy/route.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,6 @@ module.exports = {
3030
auth: 'jwt',
3131
permission: 'taxonomy.edit'
3232
},
33-
put: {
34-
method: Controller.fullyUpdate,
35-
auth: 'jwt',
36-
permission: 'taxonomy.edit'
37-
},
3833
delete: {
3934
method: Controller.remove,
4035
auth: 'jwt',

0 commit comments

Comments
 (0)