Built motion from commit 5e31ea4.|0.0.32
[motion.git] / server / api / square_odbc / square_odbc.controller.js
index e2b05d4..a444b26 100644 (file)
@@ -1 +1,209 @@
-var _0x8977=["\x75\x73\x65\x20\x73\x74\x72\x69\x63\x74","\x6C\x6F\x64\x61\x73\x68","\x53\x71\x75\x61\x72\x65\x4F\x64\x62\x63","\x2E\x2E\x2F\x2E\x2E\x2F\x6D\x6F\x64\x65\x6C\x73","\x75\x74\x69\x6C","\x69\x6E\x64\x65\x78","\x6E\x61\x6D\x65","\x64\x65\x73\x63\x72\x69\x70\x74\x69\x6F\x6E","\x70\x65\x72\x5F\x70\x61\x67\x65","\x71\x75\x65\x72\x79","\x70\x61\x67\x65","\x6F\x72\x64\x65\x72","\x25\x73\x20\x25\x73","\x73\x6F\x72\x74\x5F\x62\x79","\x73\x6F\x72\x74\x5F\x6F\x72\x64\x65\x72","\x41\x53\x43","\x66\x6F\x72\x6D\x61\x74","\x24\x6F\x72","\x77\x68\x65\x72\x65","\x25","\x70\x75\x73\x68","\x66\x6F\x72\x45\x61\x63\x68","\x24","\x24\x6C\x69\x6B\x65","\x66\x6F\x72\x49\x6E","\x53\x6F\x6D\x65\x74\x68\x69\x6E\x67\x20\x62\x6C\x65\x77\x20\x75\x70\x21","\x73\x65\x6E\x64","\x73\x74\x61\x74\x75\x73","\x63\x61\x74\x63\x68","\x63\x6F\x75\x6E\x74","\x63\x65\x69\x6C","\x6F\x66\x66\x73\x65\x74","\x25\x73\x3A\x2F\x2F\x25\x73\x25\x73\x3F\x70\x61\x67\x65\x3D\x25\x64","\x70\x72\x6F\x74\x6F\x63\x6F\x6C","\x68\x6F\x73\x74","\x68\x65\x61\x64\x65\x72\x73","\x62\x61\x73\x65\x55\x72\x6C","\x72\x6F\x77\x73","\x74\x68\x65\x6E","\x66\x69\x6E\x64\x41\x6E\x64\x43\x6F\x75\x6E\x74\x41\x6C\x6C","\x6F\x64\x62\x63\x56\x61\x6C\x69\x64\x61\x74\x69\x6F\x6E","\x62\x6F\x64\x79","\x6C\x6F\x67","\x73\x65\x6E\x64\x53\x74\x61\x74\x75\x73","\x66\x69\x6E\x64\x41\x6C\x6C","\x73\x68\x6F\x77","\x69\x64","\x70\x61\x72\x61\x6D\x73","\x66\x69\x6E\x64\x42\x79\x49\x64","\x63\x72\x65\x61\x74\x65","\x75\x70\x64\x61\x74\x65","\x6C\x65\x6E\x67\x74\x68","\x4D\x45\x53\x53\x41\x47\x45\x5F\x45\x58\x49\x53\x54\x5F\x4F\x44\x42\x43","\x6D\x65\x72\x67\x65","\x73\x61\x76\x65","\x64\x65\x73\x74\x72\x6F\x79","\x66\x69\x6E\x64","\x62\x75\x6C\x6B\x44\x65\x73\x74\x72\x6F\x79"];_0x8977[0];var _=require(_0x8977[1]);var SquareOdbc=require(_0x8977[3])[_0x8977[2]];var util=require(_0x8977[4]);exports[_0x8977[5]]=function(_0xb6ddx4,_0xb6ddx5){var _0xb6ddx6=[_0x8977[6],_0x8977[7]];var _0xb6ddx7=_0xb6ddx4[_0x8977[9]][_0x8977[8]]?parseInt(_0xb6ddx4[_0x8977[9]][_0x8977[8]],10):100;var _0xb6ddx8=_0xb6ddx4[_0x8977[9]][_0x8977[10]]?parseInt(_0xb6ddx4[_0x8977[9]][_0x8977[10]],10):0;var _0xb6ddx9={where:{},limit:_0xb6ddx7,offset:_0xb6ddx8*_0xb6ddx7};_[_0x8977[24]](_0xb6ddx4[_0x8977[9]],function(_0xb6ddxa,_0xb6ddxb){switch(_0xb6ddxb){case _0x8977[8]:;case _0x8977[10]:break ;;case _0x8977[13]:_0xb6ddx9[_0x8977[11]]=util[_0x8977[16]](_0x8977[12],_0xb6ddx4[_0x8977[9]][_0x8977[13]],_0xb6ddx4[_0x8977[9]][_0x8977[14]]||_0x8977[15])||null;break ;;case _0x8977[14]:break ;;case _0x8977[22]:_0xb6ddx9[_0x8977[18]][_0x8977[17]]=[];_0xb6ddx6[_0x8977[21]](function(_0xb6ddxc){var _0xb6ddxd={};_0xb6ddxd[_0xb6ddxc]={$like:_0x8977[19]+_0xb6ddxa+_0x8977[19]};_0xb6ddx9[_0x8977[18]][_0x8977[17]][_0x8977[20]](_0xb6ddxd);});break ;;default:_0xb6ddx9[_0x8977[18]][_0xb6ddxb]={$like:{}};_0xb6ddx9[_0x8977[18]][_0xb6ddxb][_0x8977[23]]=_0x8977[19]+_0xb6ddxa+_0x8977[19];;}});SquareOdbc[_0x8977[39]](_0xb6ddx9)[_0x8977[38]](function(_0xb6ddxf){var _0xb6ddx10=Math[_0x8977[30]](_0xb6ddxf[_0x8977[29]]/_0xb6ddx7);var _0xb6ddx11=_0xb6ddx10>(_0xb6ddx9[_0x8977[31]]+1)?util[_0x8977[16]](_0x8977[32],_0xb6ddx4[_0x8977[33]],_0xb6ddx4[_0x8977[35]][_0x8977[34]],_0xb6ddx4[_0x8977[36]],_0xb6ddx8+1):null;var _0xb6ddx12=_0xb6ddx8>0?util[_0x8977[16]](_0x8977[32],_0xb6ddx4[_0x8977[33]],_0xb6ddx4[_0x8977[35]][_0x8977[34]],_0xb6ddx4[_0x8977[36]],_0xb6ddx8-1):null;_0xb6ddx5[_0x8977[27]](200)[_0x8977[26]]({count:_0xb6ddxf[_0x8977[29]],rows:_0xb6ddxf[_0x8977[37]],next_page:_0xb6ddx11,previous_page:_0xb6ddx12,total_pages:_0xb6ddx10});})[_0x8977[28]](function(_0xb6ddxe){_0xb6ddx5[_0x8977[27]](500)[_0x8977[26]]({error:_0x8977[25]})});};exports[_0x8977[40]]=function(_0xb6ddx4,_0xb6ddx5){console[_0x8977[42]](_0xb6ddx4[_0x8977[41]]);SquareOdbc[_0x8977[44]]({where:{name:_0xb6ddx4[_0x8977[41]][_0x8977[6]]}})[_0x8977[38]](function(_0xb6ddx13){if(!_0xb6ddx13){return _0xb6ddx5[_0x8977[43]](404)};return _0xb6ddx5[_0x8977[26]](_0xb6ddx13);})[_0x8977[28]](function(_0xb6ddxe){return handleError(_0xb6ddx5,_0xb6ddxe)});};exports[_0x8977[45]]=function(_0xb6ddx4,_0xb6ddx5){SquareOdbc[_0x8977[48]](_0xb6ddx4[_0x8977[47]][_0x8977[46]])[_0x8977[38]](function(_0xb6ddx14){if(!_0xb6ddx14){return _0xb6ddx5[_0x8977[43]](404)};return _0xb6ddx5[_0x8977[26]](_0xb6ddx14);})[_0x8977[28]](function(_0xb6ddxe){return handleError(_0xb6ddx5,_0xb6ddxe)})};exports[_0x8977[49]]=function(_0xb6ddx4,_0xb6ddx5){SquareOdbc[_0x8977[49]](_0xb6ddx4[_0x8977[41]])[_0x8977[38]](function(_0xb6ddx14){return _0xb6ddx5[_0x8977[27]](201)[_0x8977[26]](_0xb6ddx14)})[_0x8977[28]](function(_0xb6ddxe){return handleError(_0xb6ddx5,_0xb6ddxe)})};exports[_0x8977[50]]=function(_0xb6ddx4,_0xb6ddx5){SquareOdbc[_0x8977[44]]({where:{name:_0xb6ddx4[_0x8977[41]][_0x8977[6]],id:{$ne:_0xb6ddx4[_0x8977[41]][_0x8977[46]]}}})[_0x8977[38]](function(_0xb6ddx13){if(!_0xb6ddx13){return _0xb6ddx5[_0x8977[43]](404)};if(_0xb6ddx13[_0x8977[51]]>0){return _0xb6ddx5[_0x8977[27]](500)[_0x8977[26]]({message:_0x8977[52]})};if(_0xb6ddx4[_0x8977[41]][_0x8977[46]]){delete _0xb6ddx4[_0x8977[41]][_0x8977[46]]};SquareOdbc[_0x8977[48]](_0xb6ddx4[_0x8977[47]][_0x8977[46]])[_0x8977[38]](function(_0xb6ddx14){if(!_0xb6ddx14){return _0xb6ddx5[_0x8977[43]](404)};var _0xb6ddx15=_[_0x8977[53]](_0xb6ddx14,_0xb6ddx4[_0x8977[41]]);_0xb6ddx15[_0x8977[54]]()[_0x8977[38]](function(){return _0xb6ddx5[_0x8977[27]](200)[_0x8977[26]](_0xb6ddx14)})[_0x8977[28]](function(_0xb6ddxe){return handleError(_0xb6ddx5,_0xb6ddxe)});})[_0x8977[28]](function(_0xb6ddxe){return handleError(_0xb6ddx5,_0xb6ddxe)});})[_0x8977[28]](function(_0xb6ddxe){return handleError(_0xb6ddx5,_0xb6ddxe)})};exports[_0x8977[55]]=function(_0xb6ddx4,_0xb6ddx5){SquareOdbc[_0x8977[56]]({where:{id:_0xb6ddx4[_0x8977[47]][_0x8977[46]]}})[_0x8977[38]](function(_0xb6ddx14){if(!_0xb6ddx14){return _0xb6ddx5[_0x8977[43]](404)};_0xb6ddx14[_0x8977[55]]()[_0x8977[38]](function(){return _0xb6ddx5[_0x8977[43]](204)})[_0x8977[28]](function(_0xb6ddxe){return handleError(_0xb6ddx5,_0xb6ddxe)});})[_0x8977[28]](function(_0xb6ddxe){return handleError(_0xb6ddx5,_0xb6ddxe)})};exports[_0x8977[57]]=function(_0xb6ddx4,_0xb6ddx5){SquareOdbc[_0x8977[55]]({where:{id:_0xb6ddx4[_0x8977[9]][_0x8977[46]]},individualHooks:true})[_0x8977[38]](function(){return _0xb6ddx5[_0x8977[43]](204)})[_0x8977[28]](function(_0xb6ddxe){return handleError(_0xb6ddx5,_0xb6ddxe)})};function handleError(_0xb6ddx5,_0xb6ddxe){return _0xb6ddx5[_0x8977[27]](500)[_0x8977[26]](_0xb6ddxe)}
\ No newline at end of file
+'use strict';
+
+var _ = require('lodash');
+var SquareOdbc = require('../../models').SquareOdbc;
+var util = require('util');
+
+// Get list of square_odbcs
+exports.index = function(req, res) {
+  var attributes = ['name', 'description'];
+  var per_page = req.query.per_page ? parseInt(req.query.per_page, 10) : 100;
+  var page = req.query.page ? parseInt(req.query.page, 10) : 0;
+
+  var query = {
+    where: {},
+    limit: per_page,
+    offset: page * per_page
+  };
+
+  _.forIn(req.query, function(value, key) {
+    switch (key) {
+      case 'per_page':
+      case 'page':
+        break;
+      case 'sort_by':
+        query.order = util.format('%s %s', req.query.sort_by, req.query.sort_order || 'ASC') || null;
+        break;
+      case 'sort_order':
+        break;
+      case '$':
+        query.where.$or = [];
+        attributes.forEach(function(attribute) {
+          var tmp = {};
+          tmp[attribute] = {
+            $like: '%' + value + '%'
+          };
+
+          query.where.$or.push(tmp);
+        });
+        break;
+      default:
+        query.where[key] = {
+          $like: {}
+        };
+        query.where[key].$like = '%' + value + '%';
+    }
+  });
+
+  SquareOdbc
+    .findAndCountAll(query)
+    .then(function(result) {
+
+      var total_pages = Math.ceil(result.count / per_page);
+      var next_page = total_pages > (query.offset + 1) ? util.format('%s://%s%s?page=%d', req.protocol, req.headers.host, req.baseUrl, page + 1) : null;
+      var previous_page = page > 0 ? util.format('%s://%s%s?page=%d', req.protocol, req.headers.host, req.baseUrl, page - 1) : null;
+
+      res.status(200).send({
+        count: result.count,
+        rows: result.rows,
+        next_page: next_page,
+        previous_page: previous_page,
+        total_pages: total_pages
+      });
+
+    })
+    .catch(function(err) {
+      res.status(500).send({
+        error: 'Something blew up!'
+      });
+    });
+};
+
+exports.odbcValidation = function(req, res) {
+  console.log(req.body);
+  SquareOdbc
+    .findAll({
+      where: {
+        name: req.body.name
+      }
+    })
+    .then(function(square_odbcs) {
+      if (!square_odbcs) {
+        return res.sendStatus(404);
+      }
+      return res.send(square_odbcs);
+    })
+    .catch(function(err) {
+      return handleError(res, err);
+    });
+};
+
+// Get a single square_odbc
+exports.show = function(req, res) {
+  SquareOdbc
+    .findById(req.params.id)
+    .then(function(square_odbc) {
+      if (!square_odbc) {
+        return res.sendStatus(404);
+      }
+      return res.send(square_odbc);
+    })
+    .catch(function(err) {
+      return handleError(res, err);
+    });
+};
+
+// Creates a new square_odbc in the DB.
+exports.create = function(req, res) {
+  SquareOdbc
+    .create(req.body)
+    .then(function(square_odbc) {
+      return res.status(201).send(square_odbc);
+    })
+    .catch(function(err) {
+      return handleError(res, err);
+    });
+};
+
+// Updates an existing square_odbc in the DB.
+exports.update = function(req, res) {
+  SquareOdbc
+    .findAll({
+      where: {
+        name: req.body.name,
+        id: {
+          $ne: req.body.id
+        }
+      }
+    })
+    .then(function(square_odbcs) {
+      if (!square_odbcs) {
+        return res.sendStatus(404);
+      }
+      if (square_odbcs.length > 0) {
+        return res.status(500).send({
+          message: 'MESSAGE_EXIST_ODBC'
+        })
+      }
+      if (req.body.id) {
+        delete req.body.id;
+      }
+      SquareOdbc
+        .findById(req.params.id)
+        .then(function(square_odbc) {
+          if (!square_odbc) {
+            return res.sendStatus(404);
+          }
+          var updated = _.merge(square_odbc, req.body);
+          updated.save()
+            .then(function() {
+              return res.status(200).send(square_odbc);
+            })
+            .catch(function(err) {
+              return handleError(res, err);
+            });
+        })
+        .catch(function(err) {
+          return handleError(res, err);
+        });
+    })
+    .catch(function(err) {
+      return handleError(res, err);
+    });
+};
+
+// Deletes a square_odbc from the DB.
+exports.destroy = function(req, res) {
+  SquareOdbc
+    .find({
+      where: {
+        id: req.params.id
+      }
+    })
+    .then(function(square_odbc) {
+      if (!square_odbc) {
+        return res.sendStatus(404);
+      }
+      square_odbc.destroy()
+        .then(function() {
+          return res.sendStatus(204);
+        })
+        .catch(function(err) {
+          return handleError(res, err);
+        });
+    })
+    .catch(function(err) {
+      return handleError(res, err);
+    });
+};
+
+// Deletes a square_project from the DB.
+exports.bulkDestroy = function(req, res) {
+  SquareOdbc
+    .destroy({
+      where: {
+        id: req.query.id
+      },
+      individualHooks: true
+    })
+    .then(function() {
+      return res.sendStatus(204);
+    })
+    .catch(function(err) {
+      return handleError(res, err);
+    });
+};
+
+function handleError(res, err) {
+  return res.status(500).send(err);
+}