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/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..b292f8d 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) @@ -84,7 +86,7 @@ router.post ('/:id', bodyParser.json (), async (req, res, next) => { }); } } else { - //no new skills for now + res.json ({result: constants.IDLengthError, message: ''}); } }); diff --git a/web/src/lib/api.js b/web/src/lib/api.js index d55c12c..f2557e4 100644 --- a/web/src/lib/api.js +++ b/web/src/lib/api.js @@ -1,26 +1,16 @@ 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', + method: 'PUT', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json'