UNPKG

fog-controller

Version:

Fog Controller project @ iotracks.com

113 lines (85 loc) 3.88 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _async = require('async'); var _async2 = _interopRequireDefault(_async); var _express = require('express'); var _express2 = _interopRequireDefault(_express); var _appUtils = require('../../utils/appUtils'); var _appUtils2 = _interopRequireDefault(_appUtils); var _winstonLogs = require('../../utils/winstonLogs'); var _winstonLogs2 = _interopRequireDefault(_winstonLogs); var _registryService = require('../../services/registryService'); var _registryService2 = _interopRequireDefault(_registryService); var _userService = require('../../services/userService'); var _userService2 = _interopRequireDefault(_userService); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } /** * @author elukashick */ var router = _express2.default.Router(); /********************************************* EndPoints ******************************************************/ /*********** GET listRegistryEndPoint (Get: /api/v2/authoring/registry/list) **********/ var listRegistryEndPoint = function listRegistryEndPoint(req, res) { _winstonLogs2.default.info("Endpoint hit: " + req.originalUrl); var params = {}, userProps = { userId: 'bodyParams.t', setProperty: 'user' }, registryForUserProps = { userId: 'user.id', setProperty: 'registry' }; params.bodyParams = req.params; params.bodyParams.t = req.query.t; _async2.default.waterfall([_async2.default.apply(_userService2.default.getUser, userProps, params), _async2.default.apply(_registryService2.default.listRegistry, registryForUserProps)], function (err, result) { _appUtils2.default.sendResponse(res, err, 'registry', params.registry, result); }); }; /*********** POST addRegistryEndPoint (Post: /api/v2/authoring/registry/add) **********/ var addRegistryEndPoint = function addRegistryEndPoint(req, res) { _winstonLogs2.default.info("Endpoint hit: " + req.originalUrl); var params = {}, userProps = { userId: 'bodyParams.t', setProperty: 'user' }, registryProps = { url: 'bodyParams.url', isPublic: 'bodyParams.isPublic', username: 'bodyParams.username', password: 'bodyParams.password', email: 'bodyParams.email', userId: 'user.id' }; params.bodyParams = req.body; params.bodyParams.t = req.query.t; _winstonLogs2.default.info("Parameters:" + JSON.stringify(params.bodyParams)); _async2.default.waterfall([_async2.default.apply(_userService2.default.getUser, userProps, params), _async2.default.apply(_registryService2.default.addRegistry, registryProps)], function (err, result) { _appUtils2.default.sendResponse(res, err, 'registry', params.registry, result); }); }; /*********** POST deleteRegistryEndPoint (Post: /api/v2/authoring/registry/delete) **********/ var deleteRegistryEndPoint = function deleteRegistryEndPoint(req, res) { _winstonLogs2.default.info("Endpoint hit: " + req.originalUrl); var params = {}, userProps = { userId: 'bodyParams.t', setProperty: 'user' }, registryProps = { id: 'bodyParams.id' }; params.bodyParams = req.body; _winstonLogs2.default.info("Parameters:" + JSON.stringify(params.bodyParams)); _async2.default.waterfall([_async2.default.apply(_userService2.default.getUser, userProps, params), _async2.default.apply(_registryService2.default.deleteRegistry, registryProps)], function (err, result) { _appUtils2.default.sendResponse(res, err, 'registry', params.registry, result); }); }; exports.default = { listRegistryEndPoint: listRegistryEndPoint, addRegistryEndPoint: addRegistryEndPoint, deleteRegistryEndPoint: deleteRegistryEndPoint };