Built motion from commit 5e31ea4.|0.0.32
[motion.git] / server / api / license / license.controller.js
index 350208c..6ccada0 100644 (file)
@@ -1 +1,161 @@
-var _0xce28=["\x75\x73\x65\x20\x73\x74\x72\x69\x63\x74","\x6C\x6F\x64\x61\x73\x68","\x72\x65\x71\x75\x65\x73\x74\x2D\x70\x72\x6F\x6D\x69\x73\x65","\x2E\x2E\x2F\x2E\x2E\x2F\x63\x6F\x6E\x66\x69\x67\x2F\x65\x6E\x76\x69\x72\x6F\x6E\x6D\x65\x6E\x74","\x2E\x2E\x2F\x2E\x2E\x2F\x63\x6F\x6E\x66\x69\x67\x2F\x6C\x69\x63\x65\x6E\x73\x65\x2F\x6C\x69\x63\x65\x6E\x73\x65\x2E\x73\x65\x72\x76\x69\x63\x65","\x53\x65\x74\x74\x69\x6E\x67\x73","\x2E\x2E\x2F\x2E\x2E\x2F\x6D\x6F\x64\x65\x6C\x73","\x44\x45\x4D\x4F\x20\x4C\x49\x43\x45\x4E\x53\x45","\x73\x65\x6E\x64","\x73\x74\x61\x74\x75\x73","\x6C\x69\x63\x65\x6E\x73\x65","\x64\x61\x74\x61\x56\x61\x6C\x75\x65\x73","\x64\x65\x63\x72\x79\x70\x74","\x70\x61\x72\x73\x65","\x74\x6F\x6B\x65\x6E","\x75\x75\x69\x64","\x6A\x73\x6F\x6E","\x74\x68\x65\x6E","\x75\x70\x64\x61\x74\x65\x41\x74\x74\x72\x69\x62\x75\x74\x65\x73","\x65\x6E\x64","\x64\x65\x73\x74\x72\x6F\x79","\x69\x6E\x64\x65\x78","\x63\x61\x74\x63\x68","\x66\x69\x6E\x64\x42\x79\x49\x64","\x73\x68\x6F\x77","\x63\x72\x65\x61\x74\x65","\x72\x65\x71\x75\x65\x73\x74","\x6C\x6F\x67","\x73\x74\x61\x74\x75\x73\x43\x6F\x64\x65","\x50\x4F\x53\x54","\x70\x72\x6F\x76\x69\x73\x69\x6F\x6E\x69\x6E\x67","\x2F\x73\x65\x72\x76\x65\x72\x73\x2F","\x2F\x72\x65\x71\x75\x65\x73\x74","\x62\x6F\x64\x79","\x75\x70\x64\x61\x74\x65"];_0xce28[0];var _=require(_0xce28[1]);var rp=require(_0xce28[2]);var config=require(_0xce28[3]);var license=require(_0xce28[4]);var Settings=require(_0xce28[6])[_0xce28[5]];var demoLicense={users:1,agents:1,telephones:0,chat:false,mail:false,fax:false,description:_0xce28[7]};function handleError(_0xb706x8,_0xb706x9){_0xb706x9=_0xb706x9||500;return function(_0xb706xa){_0xb706x8[_0xce28[9]](_0xb706x9)[_0xce28[8]](_0xb706xa)};}function responseWithResult(_0xb706x8,_0xb706x9){_0xb706x9=_0xb706x9||200;return function(_0xb706xc){if(_0xb706xc){if(_0xb706xc[_0xce28[10]]){_0xb706xc[_0xce28[11]][_0xce28[10]]=license[_0xce28[12]](_0xb706xc[_0xce28[11]][_0xce28[10]]);_0xb706xc[_0xce28[11]][_0xce28[10]]=JSON[_0xce28[13]](_0xb706xc[_0xce28[11]][_0xce28[10]]);}else {_0xb706xc[_0xce28[11]][_0xce28[10]]=demoLicense};_0xb706xc[_0xce28[11]][_0xce28[10]][_0xce28[14]]=config[_0xce28[15]];_0xb706x8[_0xce28[9]](_0xb706x9)[_0xce28[16]](_0xb706xc);}};}function handleEntityNotFound(_0xb706x8){return function(_0xb706xc){if(!_0xb706xc){_0xb706xc={dataValues:{license:demoLicense}};_0xb706xc[_0xce28[11]][_0xce28[10]][_0xce28[14]]=config[_0xce28[15]];_0xb706x8[_0xce28[9]](201)[_0xce28[16]](_0xb706xc);return null;};return _0xb706xc;}}function saveUpdates(_0xb706xf){return function(_0xb706xc){return _0xb706xc[_0xce28[18]](_0xb706xf)[_0xce28[17]](function(_0xb706x10){return _0xb706x10})}}function removeEntity(_0xb706x8){return function(_0xb706xc){if(_0xb706xc){return _0xb706xc[_0xce28[20]]()[_0xce28[17]](function(){_0xb706x8[_0xce28[9]](204)[_0xce28[19]]()})}}}exports[_0xce28[21]]=function(_0xb706x12,_0xb706x8){Settings[_0xce28[23]](1)[_0xce28[17]](handleEntityNotFound(_0xb706x8))[_0xce28[17]](responseWithResult(_0xb706x8))[_0xce28[22]](handleError(_0xb706x8))};exports[_0xce28[24]]=function(_0xb706x12,_0xb706x8){};exports[_0xce28[25]]=function(_0xb706x12,_0xb706x8){};exports[_0xce28[26]]=function(_0xb706x12,_0xb706x8){return rp({method:_0xce28[29],uri:config[_0xce28[30]]+_0xce28[31]+config[_0xce28[15]]+_0xce28[32],body:_0xb706x12[_0xce28[33]],json:true})[_0xce28[17]](function(_0xb706x13){console[_0xce28[27]](_0xb706x13);_0xb706x8[_0xce28[9]](201)[_0xce28[8]](_0xb706x13);})[_0xce28[22]](function(_0xb706xa){console[_0xce28[27]](_0xb706xa);return _0xb706x8[_0xce28[9]](_0xb706xa[_0xce28[28]]||500)[_0xce28[8]](_0xb706xa);})};exports[_0xce28[34]]=function(_0xb706x12,_0xb706x8){};exports[_0xce28[20]]=function(_0xb706x12,_0xb706x8){};
\ No newline at end of file
+/**
+ * Using Rails-like standard naming convention for endpoints.
+ * GET     /api/licenses              ->  index
+ * POST    /api/licenses              ->  create
+ * GET     /api/licenses/:id          ->  show
+ * PUT     /api/licenses/:id          ->  update
+ * DELETE  /api/licenses/:id          ->  destroy
+ */
+
+'use strict';
+
+var _ = require('lodash');
+var rp = require('request-promise');
+
+var config = require('../../config/environment');
+var license = require('../../config/license/license.service');
+var Settings = require('../../models').Settings;
+
+var demoLicense = {
+  users: 1,
+  agents: 1,
+  telephones: 0,
+  chat: false,
+  mail: false,
+  fax: false,
+  description: 'DEMO LICENSE'
+};
+
+function handleError(res, statusCode) {
+  statusCode = statusCode || 500;
+  return function (err) {
+    res.status(statusCode).send(err);
+  };
+}
+
+function responseWithResult(res, statusCode) {
+  statusCode = statusCode || 200;
+  return function (entity) {
+    if (entity) {
+      if (entity.license) {
+        entity.dataValues.license = license.decrypt(entity.dataValues.license);
+        entity.dataValues.license = JSON.parse(entity.dataValues.license);
+      } else {
+        entity.dataValues.license = demoLicense;
+      }
+
+      entity.dataValues.license.token = config.uuid;
+      res.status(statusCode).json(entity);
+    }
+  };
+}
+
+function handleEntityNotFound(res) {
+  return function (entity) {
+    if (!entity) {
+      entity = {
+        dataValues: {
+          license: demoLicense
+        }
+      };
+
+      entity.dataValues.license.token = config.uuid;
+      res.status(201).json(entity);
+      return null;
+    }
+
+    return entity;
+  };
+}
+
+function saveUpdates(updates) {
+  return function (entity) {
+    return entity
+      .updateAttributes(updates)
+      .then(function (updated) {
+        return updated;
+      });
+  };
+}
+
+function removeEntity(res) {
+  return function (entity) {
+    if (entity) {
+      return entity
+        .destroy()
+        .then(function () {
+          res.status(204).end();
+        });
+    }
+  };
+}
+
+// Gets a list of Licenses
+exports.index = function (req, res) {
+  // License.findAll()
+  //   .then(responseWithResult(res))
+  //   .catch(handleError(res));
+
+  Settings
+    .findById(1)
+    .then(handleEntityNotFound(res))
+    .then(responseWithResult(res))
+    .catch(handleError(res));
+}
+
+// Gets a single License from the DB
+exports.show = function (req, res) {
+  // License.findById(req.params.id)
+  //   .then(handleEntityNotFound(res))
+  //   .then(responseWithResult(res))
+  //   .catch(handleError(res));
+}
+
+// Creates a new License in the DB
+exports.create = function (req, res) {
+  // License.create(req.body)
+  //   .then(responseWithResult(res, 201))
+  //   .catch(handleError(res));
+}
+
+// Creates a new License in the DB
+exports.request = function (req, res) {
+  // License.create(req.body)
+  //   .then(responseWithResult(res, 201))
+  //   .catch(handleError(res));
+  return rp({
+      method: 'POST',
+      uri: config.provisioning + '/servers/' + config.uuid + '/request',
+      body: req.body,
+      json: true // Automatically stringifies the body to JSON
+    })
+    .then(function (data) {
+      console.log(data);
+      res.status(201).send(data);
+    })
+    .catch(function (err) {
+      console.log(err);
+      return res.status(err.statusCode || 500).send(err);
+    });
+  // .catch(handleError(res));
+}
+
+// Updates an existing License in the DB
+exports.update = function (req, res) {
+  // if (req.body.id) {
+  //   delete req.body.id;
+  // }
+  // License.findById(req.params.id)
+  //   .then(handleEntityNotFound(res))
+  //   .then(saveUpdates(req.body))
+  //   .then(responseWithResult(res))
+  //   .catch(handleError(res));
+}
+
+// Deletes a License from the DB
+exports.destroy = function (req, res) {
+  // License.findById(req.params.id)
+  //   .then(handleEntityNotFound(res))
+  //   .then(removeEntity(res))
+  //   .catch(handleError(res));
+}