fog-controller
Version:
Fog Controller project @ iotracks.com
58 lines (39 loc) • 3.35 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
var _elementInstanceConnectionsManager = require('../managers/elementInstanceConnectionsManager');
var _elementInstanceConnectionsManager2 = _interopRequireDefault(_elementInstanceConnectionsManager);
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 createElementInstanceConnection = function createElementInstanceConnection(props, params, callback) {
_elementInstanceConnectionsManager2.default.create(props.newConnectionObj).then(_appUtils2.default.onCreate.bind(null, params, props.setProperty, 'Error: Cannot Create Element Instance Conenction', callback));
};
var findBySourceElementInstance = function findBySourceElementInstance(props, params, callback) {
var sourceElementInstanceIds = _appUtils2.default.getProperty(params, props.sourceElementInstanceIds);
_elementInstanceConnectionsManager2.default.findBySourceElementInstance(_underscore2.default.pluck(sourceElementInstanceIds, props.field)).then(_appUtils2.default.onFindOptional.bind(null, params, props.setProperty, callback));
};
var findBySourceAndDestinationElementInstance = function findBySourceAndDestinationElementInstance(props, params, callback) {
var sourceElementInstanceId = _appUtils2.default.getProperty(params, props.sourceElementInstanceId),
destinationElementInstanceId = _appUtils2.default.getProperty(params, props.destinationElementInstanceId);
_elementInstanceConnectionsManager2.default.findBySourceAndDestinationElementInstance(sourceElementInstanceId, destinationElementInstanceId).then(_appUtils2.default.onFindOptional.bind(null, params, props.setProperty, callback));
};
var deleteElementInstanceConnection = function deleteElementInstanceConnection(props, params, callback) {
var elementInstanceData = _appUtils2.default.getProperty(params, props.elementInstanceData);
_elementInstanceConnectionsManager2.default.deleteElementInstanceConnection(_underscore2.default.pluck(elementInstanceData, props.field)).then(_appUtils2.default.onDeleteOptional.bind(null, params, callback));
};
var deleteBySourceAndDestinationElementInstance = function deleteBySourceAndDestinationElementInstance(props, params, callback) {
var sourceElementInstanceId = _appUtils2.default.getProperty(params, props.sourceElementInstanceId),
destinationElementInstanceId = _appUtils2.default.getProperty(params, props.destinationElementInstanceId);
_elementInstanceConnectionsManager2.default.deleteBySourceAndDestinationElementInstance(sourceElementInstanceId, destinationElementInstanceId).then(_appUtils2.default.onDelete.bind(null, params, 'There is no such element instance connection to delete.', callback));
};
exports.default = {
createElementInstanceConnection: createElementInstanceConnection,
findBySourceElementInstance: findBySourceElementInstance,
findBySourceAndDestinationElementInstance: findBySourceAndDestinationElementInstance,
deleteElementInstanceConnection: deleteElementInstanceConnection,
deleteBySourceAndDestinationElementInstance: deleteBySourceAndDestinationElementInstance
};