From e1f315cb812236d94a3eeea676df45971341ba86 Mon Sep 17 00:00:00 2001 From: GotPPay Date: Mon, 15 Jan 2018 16:06:37 +0100 Subject: [PATCH 1/4] backend api refactoring --- backend/controllers/index.js | 3 +-- backend/controllers/skill.js | 6 ++++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/backend/controllers/index.js b/backend/controllers/index.js index 9cf449c..93f7810 100644 --- a/backend/controllers/index.js +++ b/backend/controllers/index.js @@ -1,6 +1,5 @@ var express = require ('express'), router = express.Router (); -router.use ('/getSkill', require ('./skill')); -router.use ('/updateSkill', require ('./skill')); // this will be fixed in next code refactoring +router.use ('/skill', require ('./skill')); module.exports = router; diff --git a/backend/controllers/skill.js b/backend/controllers/skill.js index 4a5fc62..94cfecc 100644 --- a/backend/controllers/skill.js +++ b/backend/controllers/skill.js @@ -22,7 +22,7 @@ router.get ('/:id', async (req, res, next) => { } }); -router.post ('/:id', bodyParser.json (), async (req, res, next) => { +router.put ('/:id', bodyParser.json (), async (req, res, next) => { let id = req.params.id; let dataFromWeb = JSON.stringify (req.body); let skill = JSON.parse (dataFromWeb); @@ -33,7 +33,9 @@ router.post ('/:id', bodyParser.json (), async (req, res, next) => { console.log ('id = ' + id); - if (id !== '-1') { + //TODO : Fix inconsistency ! If skill is sent to amazon and accepted, but + //fails in database (ID doesn't exist) + if (id.length === constants.skillIDLength) { if (updateOnAmazon) { amazonHelper .updateSkill (skill) From 7e4b959ffa622caf82a0c87533616b16ce4cc7a4 Mon Sep 17 00:00:00 2001 From: GotPPay Date: Mon, 15 Jan 2018 16:09:09 +0100 Subject: [PATCH 2/4] backend api refactoring --- backend/config/constants.js | 2 +- backend/controllers/skill.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/config/constants.js b/backend/config/constants.js index 5895516..39913a3 100644 --- a/backend/config/constants.js +++ b/backend/config/constants.js @@ -15,7 +15,7 @@ constants.apiResultCodes = { ok:0, amazonError:1, databaseError:2, - + IDLengthError:3, } constants.skillIDLength = 24; diff --git a/backend/controllers/skill.js b/backend/controllers/skill.js index 94cfecc..b292f8d 100644 --- a/backend/controllers/skill.js +++ b/backend/controllers/skill.js @@ -86,7 +86,7 @@ router.put ('/:id', bodyParser.json (), async (req, res, next) => { }); } } else { - //no new skills for now + res.json ({result: constants.IDLengthError, message: ''}); } }); From 6e7bccea864e72a396f3cbb40a8bcfb7210f647b Mon Sep 17 00:00:00 2001 From: GotPPay Date: Mon, 15 Jan 2018 16:09:41 +0100 Subject: [PATCH 3/4] frontend api refactoring --- web/src/lib/api.js | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/web/src/lib/api.js b/web/src/lib/api.js index d55c12c..22d4bc1 100644 --- a/web/src/lib/api.js +++ b/web/src/lib/api.js @@ -1,24 +1,14 @@ import fetch from 'isomorphic-fetch'; import {BASE_URL} from '../config/config'; -export const getAllIntents = (id)=>{ - let url = `http://${BASE_URL}/intents/${id}` - return fetch(url, {method: 'GET'}); -} - export const getSkill = (id)=>{ - let url = `http://${BASE_URL}/getSkill/${id}` - return fetch(url, {method: 'GET'}); -} - -export const deleteSkill = (id)=>{ - let url = `http://${BASE_URL}/deleteSkill/${id}` + let url = `http://${BASE_URL}/skill/${id}` return fetch(url, {method: 'GET'}); } export const updateSkill = (skill)=>{ let id = (skill._id) ? skill._id : -1; - let url = `http://${BASE_URL}/updateSkill/${id}` + let url = `http://${BASE_URL}/skill/${id}` return fetch(url, { method: 'POST', headers: { From 6859f567a9aedee68b8cc092b068c30ac2448508 Mon Sep 17 00:00:00 2001 From: GotPPay Date: Mon, 15 Jan 2018 16:27:12 +0100 Subject: [PATCH 4/4] frontend api refactoring --- web/src/lib/api.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/src/lib/api.js b/web/src/lib/api.js index 22d4bc1..f2557e4 100644 --- a/web/src/lib/api.js +++ b/web/src/lib/api.js @@ -10,7 +10,7 @@ export const updateSkill = (skill)=>{ let id = (skill._id) ? skill._id : -1; let url = `http://${BASE_URL}/skill/${id}` return fetch(url, { - method: 'POST', + method: 'PUT', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json'