From: Laurence Maultsby Date: Thu, 19 Jan 2017 01:12:34 +0000 (-0500) Subject: UpdateSave functionality fixed X-Git-Tag: v1.1.0~17^2 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=refs%2Fchanges%2F82%2F982%2F1;p=osm%2FUI.git UpdateSave functionality fixed Signed-off-by: Laurence Maultsby --- diff --git a/skyquake/plugins/composer/api/composer.js b/skyquake/plugins/composer/api/composer.js index 8df1a9123..a2355ab6a 100644 --- a/skyquake/plugins/composer/api/composer.js +++ b/skyquake/plugins/composer/api/composer.js @@ -272,36 +272,36 @@ Composer.create = function(req) { }); }); }; -// Composer.update = function(req) { -// var api_server = req.query['api_server']; -// var catalogType = req.params.catalogType; -// var id = req.params.id; -// var data = req.body; -// console.log('Updating', catalogType, 'id', id, 'on', api_server); -// var jsonData = {}; -// jsonData[catalogType] = {}; -// jsonData[catalogType] = data; -// return new Promise(function(resolve, reject) { -// var requestHeaders = {}; -// _.extend(requestHeaders, constants.HTTP_HEADERS.accept.data, constants.HTTP_HEADERS.content_type.data, { -// 'Authorization': req.get('Authorization') -// }); -// request({ -// uri: utils.confdPort(api_server) + APIVersion + '/api/config/' + catalogType + '-catalog' + '/' + catalogType + '/' + id, -// method: 'PUT', -// headers: requestHeaders, -// forever: constants.FOREVER_ON, -// rejectUnauthorized: false, -// json: jsonData -// }, function(error, response, body) { -// if (utils.validateResponse('Composer.update', error, response, body, resolve, reject)) { -// resolve({ -// statusCode: response.statusCode -// }); -// } -// }); -// }); -// +Composer.updateSave = function(req) { + var api_server = req.query['api_server']; + var catalogType = req.params.catalogType; + var id = req.params.id; + var data = req.body; + console.log('Updating', catalogType, 'id', id, 'on', api_server); + var jsonData = {}; + jsonData[catalogType] = {}; + jsonData[catalogType] = data; + return new Promise(function(resolve, reject) { + var requestHeaders = {}; + _.extend(requestHeaders, constants.HTTP_HEADERS.accept.data, constants.HTTP_HEADERS.content_type.data, { + 'Authorization': req.get('Authorization') + }); + request({ + uri: utils.confdPort(api_server) + APIVersion + '/api/config/' + catalogType + '-catalog' + '/' + catalogType + '/' + id, + method: 'PUT', + headers: requestHeaders, + forever: constants.FOREVER_ON, + rejectUnauthorized: false, + json: jsonData + }, function(error, response, body) { + if (utils.validateResponse('Composer.update', error, response, body, resolve, reject)) { + resolve({ + statusCode: response.statusCode + }); + } + }); + }); +} Composer.update = function(req) { console.log(' Updating file', req.file.originalname, 'as', req.file.filename); diff --git a/skyquake/plugins/composer/routes.js b/skyquake/plugins/composer/routes.js index 2c78cc952..378220927 100644 --- a/skyquake/plugins/composer/routes.js +++ b/skyquake/plugins/composer/routes.js @@ -96,7 +96,7 @@ router.post('/api/catalog/:catalogType', cors(), function(req, res) { }); }); router.put('/api/catalog/:catalogType/:id', cors(), function(req, res) { - Composer.update(req).then(function(data) { + Composer.updateSave(req).then(function(data) { res.send(data); }, function(error) { res.status(error.statusCode);