UNPKG

fog-controller

Version:

Fog Controller project @ iotracks.com

131 lines (100 loc) 5.75 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 _usbInfo = require('./../models/usbInfo'); var _usbInfo2 = _interopRequireDefault(_usbInfo); var _baseManager = require('./../managers/baseManager'); var _baseManager2 = _interopRequireDefault(_baseManager); var _sequelize = require('./../utils/sequelize'); var _sequelize2 = _interopRequireDefault(_sequelize); var _sequelizeUtils = require('../utils/sequelizeUtils'); var _sequelizeUtils2 = _interopRequireDefault(_sequelizeUtils); 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; } /** * @author elukashick */ var USBInfoManager = function (_BaseManager) { _inherits(USBInfoManager, _BaseManager); function USBInfoManager() { _classCallCheck(this, USBInfoManager); return _possibleConstructorReturn(this, (USBInfoManager.__proto__ || Object.getPrototypeOf(USBInfoManager)).apply(this, arguments)); } _createClass(USBInfoManager, [{ key: 'getEntity', value: function getEntity() { return USBInfoManager; } /** * @desc - finds usbInfoObj based on the uuid * @param uuid Integer * @return JSON - returns a JSON object of usbInfoObj */ }, { key: 'findByInstanceId', value: function findByInstanceId(uuid) { return _usbInfo2.default.find({ where: { iofog_uuid: 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 - updates * @param Integer, JSON object - uuid, usbInfoObj * @return Integer - returns the number of rows updated */ }, { key: 'update', value: function update(infoObj) { return _usbInfo2.default.update(infoObj, { where: { iofog_uuid: infoObj.iofog_uuid } }); } /** * @desc - saves info * @param JSON object - usbInfoObj * @return Integer - returns the number of rows created */ }, { key: 'save', value: function save(infoObj) { return _usbInfo2.default.create(infoObj); } /** * @desc - deletes usbInfoObj based on the uuid * @param String - uuid * @return Integer - returns the number of rows deleted */ }, { key: 'deleteByInstanceId', value: function deleteByInstanceId(uuid) { return _usbInfo2.default.destroy({ where: { iofog_uuid: uuid } }); } }]); return USBInfoManager; }(_baseManager2.default); var instance = new USBInfoManager(); exports.default = instance;