UNPKG

fog-controller

Version:

Fog Controller project @ iotracks.com

129 lines (100 loc) 6.63 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 _hwInfo = require('./../models/hwInfo'); var _hwInfo2 = _interopRequireDefault(_hwInfo); 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 HWInfoManager.js * @author elukashick * @description */ var HWInfoManager = function (_BaseManager) { _inherits(HWInfoManager, _BaseManager); function HWInfoManager() { _classCallCheck(this, HWInfoManager); return _possibleConstructorReturn(this, (HWInfoManager.__proto__ || Object.getPrototypeOf(HWInfoManager)).apply(this, arguments)); } _createClass(HWInfoManager, [{ key: 'getEntity', value: function getEntity() { return HWInfoManager; } /** * @desc - finds info based on the uuid * @param Integer - uuid * @return JSON - returns a JSON object of hwInfo */ }, { key: 'findByInstanceId', value: function findByInstanceId(uuid) { return _hwInfo2.default.find({ where: { iofog_uuid: uuid } }); } /** * @desc - updates * @param Integer, JSON object - uuid, infoObj * @return Integer - returns the number of rows updated */ }, { key: 'update', value: function update(infoObj) { return _hwInfo2.default.update(infoObj, { where: { iofog_uuid: infoObj.iofog_uuid } }); } /** * @desc - updates if usbInfoObj exists in db otherwise creates it * @param Integer - uuid * @return JSON - returns a JSON usbInfoObj */ }, { key: 'upsert', value: function upsert(infoObj) { var _this2 = this; return this.findByInstanceId(infoObj.iofog_uuid).then(function (dbObj) { return null == dbObj ? _this2.save(infoObj) : _this2.update(infoObj); }); } /** * @desc - saves infoObj * @param JSON object - infoObj * @return Integer - returns the number of rows created */ }, { key: 'save', value: function save(infoObj) { return _hwInfo2.default.create(infoObj); } /** * @desc - deletes the info based on the uuid * @param String - uuid * @return Integer - returns the number of rows deleted */ }, { key: 'deleteByInstanceId', value: function deleteByInstanceId(uuid) { return _hwInfo2.default.destroy({ where: { iofog_uuid: uuid } }); } }]); return HWInfoManager; }(_baseManager2.default); var instance = new HWInfoManager(); exports.default = instance;