UNPKG

fog-controller

Version:

Fog Controller project @ iotracks.com

142 lines (116 loc) 7.43 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); var _fog = require('./../models/fog'); var _fog2 = _interopRequireDefault(_fog); var _baseManager = require('./../managers/baseManager'); var _baseManager2 = _interopRequireDefault(_baseManager); var _sequelize = require('./../utils/sequelize'); var _sequelize2 = _interopRequireDefault(_sequelize); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /** * @file fogManager.js * @author Zishan Iqbal * @description This file includes the CURD operations for the fog Model. */ var FogManager = function (_BaseManager) { _inherits(FogManager, _BaseManager); function FogManager() { _classCallCheck(this, FogManager); return _possibleConstructorReturn(this, (FogManager.__proto__ || Object.getPrototypeOf(FogManager)).apply(this, arguments)); } _createClass(FogManager, [{ key: 'getEntity', value: function getEntity() { return _fog2.default; } /** * @desc - finds the fog based on the instanceId * @param Integer - instanceId * @return JSON - returns a JSON object of fog */ }, { key: 'findByInstanceId', value: function findByInstanceId(instanceId) { return _fog2.default.find({ where: { uuid: instanceId } }); } /** * @desc - updates the config data in the fog with the id that matches the instanceId * @param Integer, JSON object - instanceId, config * @return Integer - returns the number of rows updated */ }, { key: 'updateFogConfig', value: function updateFogConfig(instanceId, config) { return _fog2.default.update(config, { where: { uuid: instanceId } }); } /** * @desc - creates a new Iofog with config data * @param JSON object - config * @return Integer - returns the number of rows created */ }, { key: 'createFog', value: function createFog(config) { return _fog2.default.create(config); } /** * @desc - finds all the fog UUID and Typkey and sends them * back in order of TypeKey in the form of JSON objects * @param - none * @return Array of JSON - returns an Array containing JSON objects */ }, { key: 'getFogList', value: function getFogList() { var fogListQuery = "SELECT UUID, typeKey from iofogs ORDER BY TypeKey"; return _sequelize2.default.query(fogListQuery, { type: _sequelize2.default.QueryTypes.SELECT }); } /** * @desc - deletes the fog based on the instanceId * @param String - instanceId * @return Integer - returns the number of rows deleted */ }, { key: 'deleteByInstanceId', value: function deleteByInstanceId(instanceId) { return _fog2.default.destroy({ where: { uuid: instanceId } }); } }, { key: 'findByUserId', value: function findByUserId(userId) { var instanceQuery = 'SELECT i.*, t.id as typeId, t.name as typeName, t.image as typeImage, t.description as typeDescription FROM iofogs i JOIN iofog_type t ON (i.typeKey= t.ID)' + ' JOIN iofog_users u ON (i.UUID = u.fog_id) WHERE u.user_id =' + userId; return _sequelize2.default.query(instanceQuery, { type: _sequelize2.default.QueryTypes.SELECT }); } }, { key: 'getFogInstanceDetails', value: function getFogInstanceDetails(instanceId) { var instanceQuery = 'SELECT i.*, t.name as typeName, t.image as typeImage, t.description as typeDescription ' + 'FROM iofogs i INNER JOIN iofog_type t ON i.typeKey = t.ID WHERE i.UUID in (:instanceId)'; return _sequelize2.default.query(instanceQuery, { replacements: { instanceId: instanceId }, type: _sequelize2.default.QueryTypes.SELECT }); } }]); return FogManager; }(_baseManager2.default); var instance = new FogManager(); exports.default = instance;