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

fix #19 #20

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.env
node_modules
74 changes: 3 additions & 71 deletions docs/skills-api.postman_collection.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"info": {
"_postman_id": "8d22bd52-0b64-43a5-9db3-c8516cb3e371",
"_postman_id": "f4b1365c-fcee-492c-848a-c7c5a49a779f",
"name": "skills-api",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
Expand Down Expand Up @@ -90,41 +90,7 @@
],
"body": {
"mode": "raw",
"raw": "{\n \"name\": \"taxonomies_update12\",\n \"metadata\": {\n \"version\": \"1.0.0\"\n }\n}"
},
"url": {
"raw": "{{HOST}}/taxonomies/{{taxonomyId}}",
"host": [
"{{HOST}}"
],
"path": [
"taxonomies",
"{{taxonomyId}}"
]
}
},
"response": []
},
{
"name": "{{HOST}}/taxonomies/:id",
"request": {
"method": "PUT",
"header": [
{
"key": "Authorization",
"type": "text",
"value": "Bearer {{token}}"
},
{
"key": "Content-Type",
"name": "Content-Type",
"type": "text",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"name\": \"taxonomies_update\",\n \"metadata\": {\n \"new_metadata_field\": \"value\"\n }\n}"
"raw": "{\n \"metadata\": {\n \"version\": \"1.0.0\"\n }\n}"
},
"url": {
"raw": "{{HOST}}/taxonomies/{{taxonomyId}}",
Expand Down Expand Up @@ -319,41 +285,7 @@
],
"body": {
"mode": "raw",
"raw": "{\n \"name\": \"skill_name_update23\",\n \"metadata\": {\n \"memberProminence\": \"0.75\",\n \"version\": \"0.1.0\"\n }\n}"
},
"url": {
"raw": "{{HOST}}/skills/{{skillId}}",
"host": [
"{{HOST}}"
],
"path": [
"skills",
"{{skillId}}"
]
}
},
"response": []
},
{
"name": "{{HOST}}/skills/:id",
"request": {
"method": "PUT",
"header": [
{
"key": "Authorization",
"type": "text",
"value": "Bearer {{token}}"
},
{
"key": "Content-Type",
"name": "Content-Type",
"type": "text",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n\t\"taxonomyId\":\"{{taxonomyId}}\",\n\t\"name\":\"jump6\",\n \"metadata\": {\n \"challengeProminence\": \"0.2\"\n }\n}"
"raw": "{\n \"metadata\": {\n \"memberProminence\": \"0.75\",\n \"version\": \"0.1.0\"\n }\n}"
},
"url": {
"raw": "{{HOST}}/skills/{{skillId}}",
Expand Down
125 changes: 28 additions & 97 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -303,55 +303,7 @@ paths:
name: "body"
required: true
schema:
$ref: "#/definitions/SkillUpdateRequestBody"
responses:
"200":
description: "OK - the request was successful"
schema:
$ref: "#/definitions/Skill"
"400":
$ref: "#/definitions/BadRequest"
"401":
$ref: "#/definitions/Unauthorized"
"403":
$ref: "#/definitions/Forbidden"
"404":
$ref: "#/definitions/NotFound"
"409":
$ref: "#/definitions/Conflict"
"500":
$ref: "#/definitions/ServerError"
security:
- Bearer: []
x-swagger-router-controller: "Skills"

put:
tags:
- "Skills"
description: >
Fully update an existing skill with given id.


**PERMISSION**

1. permission `UPDATE_SKILL` is required to perform this operation

2. permission `ADD_SKILL_METADATA` is required if new metadata fields are provided.

3. permission `DELETE_SKILL_METADATA` is required if there is any existing metadata field in the skill.
operationId: "skillsSkillIdPUT"
parameters:
- name: "skillId"
in: "path"
description: "The skill id"
required: true
type: "string"
format: "UUID"
- in: "body"
name: "body"
required: true
schema:
$ref: "#/definitions/SkillRequestBody"
$ref: "#/definitions/SkillPatchRequestBody"
responses:
"200":
description: "OK - the request was successful"
Expand Down Expand Up @@ -611,54 +563,7 @@ paths:
name: "body"
required: true
schema:
$ref: "#/definitions/TaxonomyUpdateRequestBody"
responses:
"200":
description: "OK - the request was successful"
schema:
$ref: "#/definitions/Taxonomy"
"400":
$ref: "#/definitions/BadRequest"
"401":
$ref: "#/definitions/Unauthorized"
"403":
$ref: "#/definitions/Forbidden"
"404":
$ref: "#/definitions/NotFound"
"409":
$ref: "#/definitions/Conflict"
"500":
$ref: "#/definitions/ServerError"
security:
- Bearer: []
x-swagger-router-controller: "Taxonomy"
put:
tags:
- "Taxonomies"
description: >
Fully update an existing taxonomy with given id.


**PERMISSION**

1. permission `UPDATE_TAXONOMY` is required to perform this operation

2. permission `ADD_TAXONOMY_METADATA` is required if any metadata field is provided.

3. permission `DELETE_TAXONOMY_METADATA` is required if there is any existing metadata field in the taxonomy.
operationId: "skillstaxonomiestaxonomyIdPUT"
parameters:
- name: "taxonomyId"
in: "path"
description: "The taxonomy id"
required: true
type: "string"
format: "UUID"
- in: "body"
name: "body"
required: true
schema:
$ref: "#/definitions/TaxonomyRequestBody"
$ref: "#/definitions/TaxonomyPatchRequestBody"
responses:
"200":
description: "OK - the request was successful"
Expand Down Expand Up @@ -788,6 +693,23 @@ definitions:
metadata:
challengeProminence: "challengeProminence"
memberProminence: "memberProminence"
SkillPatchRequestBody:
type: "object"
properties:
metadata:
type: "object"
description: "The metadata for the skill"
properties:
challengeProminence:
type: "string"
description: "The challenge prominence ranging from [0, 1]"
memberProminence:
type: "string"
description: "The member prominence ranging from [0, 1]"
example:
metadata:
challengeProminence: "challengeProminence"
memberProminence: "memberProminence"
Taxonomy:
allOf:
- type: "object"
Expand Down Expand Up @@ -831,6 +753,15 @@ definitions:
name: "name"
metadata:
random_field_name_01: random_value_01
TaxonomyPatchRequestBody:
type: "object"
properties:
metadata:
type: "object"
description: "The metadata of the taxonomy."
example:
metadata:
random_field_name_01: random_value_01
Unauthorized:
type: "object"
properties:
Expand Down
5 changes: 0 additions & 5 deletions src/modules/skill/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@ module.exports = {
auth: 'jwt',
permission: 'skill.edit'
},
put: {
method: Controller.fullyUpdate,
auth: 'jwt',
permission: 'skill.edit'
},
delete: {
method: Controller.remove,
auth: 'jwt',
Expand Down
63 changes: 2 additions & 61 deletions src/modules/skill/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ create.schema = {
}

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

if (entity.taxonomyId && entity.taxonomyId !== instance.taxonomyId) {
// check if the taxonomy exists or not
await dbHelper.get(Taxonomy, entity.taxonomyId)
}

// check if the skill has conflict or not
await dbHelper.makeSureUnique(Skill, { ...entity, id }, uniqueFields)

if (entity.metadata) {
const inputFields = Object.keys(entity.metadata)
const existingFields = Object.keys(instance.metadata)
Expand All @@ -138,7 +130,7 @@ async function patch (id, entity, auth) {
}
}

const updateData = { ...instance, ...entity, metadata: { ...instance.metadata, ...entity.metadata } }
const updateData = { ...instance, metadata: { ...instance.metadata, ...entity.metadata } }

return update(instance, updateData, auth)
}
Expand All @@ -158,56 +150,6 @@ patch.schema = {
auth: joi.object()
}

/**
* Fully update skill by id.
* Existing metadata fields would be entirely replace with the new ones.
*
* @param id the skill id
* @param entity the request skill entity
* @param auth the auth object
* @return the updated skill
*/
async function fullyUpdate (id, entity, auth) {
// check if the skill exists or not
const instance = await dbHelper.get(Skill, id)

if (entity.taxonomyId !== instance.taxonomyId) {
// check if the taxonomy exists or not
await dbHelper.get(Taxonomy, entity.taxonomyId)
}

// check if the skill has conflict or not
await dbHelper.makeSureUnique(Skill, { ...entity, id }, uniqueFields)

if (Object.keys(entity.metadata).length) {
// check permission for adding new metadata fields
serviceHelper.hasPermission(PERMISSION.ADD_SKILL_METADATA, auth)
}
if (Object.keys(instance.metadata).length) {
// check permission for removing existing metadata fields
serviceHelper.hasPermission(PERMISSION.DELETE_SKILL_METADATA, auth)
}

const updateData = entity

return update(instance, updateData, auth)
}

fullyUpdate.schema = {
id: joi.string().uuid().required(),
entity: joi.object().keys({
taxonomyId: joi.string().uuid().required(),
name: joi.string().required(),
uri: joi.string().default(null),
externalId: joi.string().default(null),
metadata: joi.object().keys({
challengeProminence: joi.prominence('challengeProminence'),
memberProminence: joi.prominence('memberProminence')
}).unknown(true).required()
}).required(),
auth: joi.object()
}

/**
* get skill by id
* @param id the skill id
Expand Down Expand Up @@ -333,7 +275,6 @@ module.exports = {
create,
search,
patch,
fullyUpdate,
get,
remove
}
5 changes: 0 additions & 5 deletions src/modules/taxonomy/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@ module.exports = {
auth: 'jwt',
permission: 'taxonomy.edit'
},
put: {
method: Controller.fullyUpdate,
auth: 'jwt',
permission: 'taxonomy.edit'
},
delete: {
method: Controller.remove,
auth: 'jwt',
Expand Down
Loading