UNPKG

fog-controller

Version:

Fog Controller project @ iotracks.com

84 lines (59 loc) 4.51 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _elementInstancePortManager = require('../managers/elementInstancePortManager'); var _elementInstancePortManager2 = _interopRequireDefault(_elementInstancePortManager); var _appUtils = require('../utils/appUtils'); var _appUtils2 = _interopRequireDefault(_appUtils); var _underscore = require('underscore'); var _underscore2 = _interopRequireDefault(_underscore); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } var createElementInstancePort = function createElementInstancePort(props, params, callback) { var userId = _appUtils2.default.getProperty(params, props.userId), internalPort = _appUtils2.default.getProperty(params, props.internalPort), externalPort = _appUtils2.default.getProperty(params, props.externalPort), elementId = _appUtils2.default.getProperty(params, props.elementId); _elementInstancePortManager2.default.createElementPort(userId, elementId, externalPort, internalPort).then(_appUtils2.default.onCreate.bind(null, params, props.setProperty, 'Unable to create Element Instance Port', callback)); }; var createElementInstancePortByPortValue = function createElementInstancePortByPortValue(props, params, callback) { var userId = _appUtils2.default.getProperty(params, props.userId), internalPort = props.internalPort, externalPort = props.externalPort, elementId = _appUtils2.default.getProperty(params, props.elementId); _elementInstancePortManager2.default.createElementPort(userId, elementId, externalPort, internalPort).then(_appUtils2.default.onCreate.bind(null, params, props.setProperty, 'Unable to create Element Instance Port', callback)); }; var deleteElementInstancePort = function deleteElementInstancePort(props, params, callback) { var elementId = _appUtils2.default.getProperty(params, props.elementId); _elementInstancePortManager2.default.deleteByElementInstanceId(elementId).then(_appUtils2.default.onDeleteOptional.bind(null, params, callback)); }; var deleteElementInstancePortById = function deleteElementInstancePortById(props, params, callback) { var elementPortId = _appUtils2.default.getProperty(params, props.elementPortId); _elementInstancePortManager2.default.deleteById(elementPortId).then(_appUtils2.default.onDelete.bind(null, params, 'No Element Instance Port found', callback)); }; var deleteElementInstancePortsByElementIds = function deleteElementInstancePortsByElementIds(props, params, callback) { var elementInstanceData = _appUtils2.default.getProperty(params, props.elementInstanceData); _elementInstancePortManager2.default.deleteByElementInstanceId(_underscore2.default.pluck(elementInstanceData, props.field)).then(_appUtils2.default.onDeleteOptional.bind(null, params, callback)); }; var findElementInstancePortsByElementIds = function findElementInstancePortsByElementIds(props, params, callback) { var elementInstanceData = _appUtils2.default.getProperty(params, props.elementInstanceData); _elementInstancePortManager2.default.findPortsByElementIds(_underscore2.default.pluck(elementInstanceData, props.field)).then(_appUtils2.default.onFindOptional.bind(null, params, props.setProperty, callback)); }; var getElementInstancePort = function getElementInstancePort(props, params, callback) { var portId = _appUtils2.default.getProperty(params, props.portId); _elementInstancePortManager2.default.findById(portId).then(_appUtils2.default.onFind.bind(null, params, props.setProperty, 'Cannot find Element Instance Port', callback)); }; var getPortsByElementId = function getPortsByElementId(props, params, callback) { var elementPortId = _appUtils2.default.getProperty(params, props.elementPortId); _elementInstancePortManager2.default.getPortsByElementId(elementPortId).then(_appUtils2.default.onFind.bind(null, params, props.setProperty, 'No Element Instance Port found', callback)); }; exports.default = { createElementInstancePort: createElementInstancePort, createElementInstancePortByPortValue: createElementInstancePortByPortValue, deleteElementInstancePort: deleteElementInstancePort, deleteElementInstancePortsByElementIds: deleteElementInstancePortsByElementIds, deleteElementInstancePortById: deleteElementInstancePortById, findElementInstancePortsByElementIds: findElementInstancePortsByElementIds, getElementInstancePort: getElementInstancePort, getPortsByElementId: getPortsByElementId };