Built motion from commit 05106a3.|0.0.33
[motion.git] / server / api / voice_context / voice_context.controller.js
index 662a803..b854255 100644 (file)
@@ -1,282 +1 @@
-'use strict';
-
-var _ = require('lodash');
-var util = require('util');
-var sequelize = require('../../models').sequelize;
-
-var VoiceContext = require('../../models').VoiceContext;
-var VoiceExtension = require('../../models').VoiceExtension;
-
-// Get list of agents
-exports.index = function(req, res, next) {
-
-  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 + '%';
-    }
-  });
-
-  VoiceContext
-    .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!'
-      });
-    });
-};
-
-// Get a single voice_context
-exports.show = function(req, res) {
-  VoiceContext
-    .findById(req.params.id)
-    .then(function(voice_context) {
-      if (!voice_context) {
-        return res.sendStatus(404);
-      }
-      return res.send(voice_context);
-    })
-    .catch(function(err) {
-      return handleError(res, err);
-    });
-};
-
-// Validate the existence of a context
-exports.contextValidation = function(req, res) {
-  console.log(req.body);
-  VoiceContext
-    .findAll({
-      where: {
-        name: req.body.name
-      }
-    })
-    .then(function(voice_contexts) {
-      if (!voice_contexts) {
-        return res.sendStatus(404);
-      }
-      return res.send(voice_contexts);
-    })
-    .catch(function(err) {
-      return handleError(res, err);
-    });
-};
-
-// Creates a new voice_context in the DB.
-exports.create = function(req, res) {
-  VoiceContext
-    .findAll({
-      where: {
-        name: req.body.name
-      }
-    })
-    .then(function(existingContexts) {
-      console.log(existingContexts);
-      console.log('Finding app row.....');
-      if (!existingContexts) {
-        return res.sendStatus(404);
-      }
-      if (existingContexts.length > 0) {
-        return res.status(500).send({
-          message: 'MESSAGE_EXIST_ROUTE'
-        });
-      }
-      VoiceContext
-        .create(req.body)
-        .then(function(voice_context) {
-          return res.status(201).send(voice_context);
-        })
-        .catch(function(err) {
-          return handleError(res, err);
-        });
-    })
-    .catch(function(err) {
-      return handleError(res, err);
-    });
-
-};
-
-// Updates an existing voice_context in the DB.
-exports.update = function(req, res) {
-  VoiceContext
-    .findAll({
-      where: {
-        name: req.body.name,
-        id: {
-          $ne: req.body.id
-        }
-      }
-    })
-    .then(function(existingContexts) {
-      console.log(existingContexts);
-      console.log('Finding app row.....');
-      if (!existingContexts) {
-        return res.sendStatus(404);
-      }
-      if (existingContexts.length > 0) {
-        return res.status(500).send({
-          message: 'MESSAGE_EXIST_ROUTE'
-        });
-      }
-      if (req.body.id) {
-        delete req.body.id;
-      }
-      VoiceContext
-        .findById(req.params.id)
-        .then(function(voice_context) {
-          if (!voice_context) {
-            return res.sendStatus(404);
-          }
-          var updated = _.merge(voice_context, req.body);
-          updated.save()
-            .then(function() {
-              return res.status(200).send(voice_context);
-            })
-            .catch(function(err) {
-              return handleError(res, err);
-            });
-        })
-        .catch(function(err) {
-          return handleError(res, err);
-        });
-    })
-    .catch(function(err) {
-      return handleError(res, err);
-    });
-
-};
-
-// Deletes a voice_context from the DB.
-exports.destroy = function(req, res) {
-  VoiceContext
-    .findById(req.params.id)
-    .then(function(voice_context) {
-      if (!voice_context) {
-        return res.sendStatus(404);
-      }
-      VoiceExtension
-        .findAll({
-          where: {
-            context: voice_context.name
-          }
-        })
-        .then(function(contextExtensions) {
-          if (contextExtensions.length > 0) {
-            return res.status(500).send({
-              message: 'MESSAGE_CONTEXT_ROUTE_ASSOCIATED'
-            });
-          }
-          voice_context.destroy()
-            .then(function() {
-              return res.sendStatus(204);
-            })
-            .catch(function(err) {
-              return handleError(res, err);
-            });
-        })
-        .catch(function(err) {
-          return handleError(res, err);
-        });
-    })
-    .catch(function(err) {
-      return handleError(res, err);
-    });
-};
-
-// Deletes a context from the DB.
-exports.bulkDestroy = function(req, res) {
-  VoiceContext
-    .findAll({
-      where: {
-        id: req.query.id
-      }
-    })
-    .then(function(voice_contexts) {
-      if (!voice_contexts) {
-        return res.sendStatus(404);
-      }
-      var destroyContextsNames = _.pluck(_.pluck(voice_contexts, 'dataValues'), 'name');
-      VoiceExtension
-        .findAll({
-          where: {
-            context: destroyContextsNames
-          }
-        })
-        .then(function(contextExtensions) {
-          if (contextExtensions.length > 0) {
-            return res.status(500).send({
-              message: 'MESSAGE_CONTEXT_ROUTE_ASSOCIATED'
-            });
-          }
-          VoiceContext
-            .destroy({
-              where: {
-                id: req.query.id
-              },
-              individualHooks: true
-            })
-            .then(function() {
-              return res.sendStatus(204);
-            })
-            .catch(function(err) {
-              return handleError(res, err);
-            });
-        })
-        .catch(function(err) {
-          return handleError(res, err);
-        });
-    })
-    .catch(function(err) {
-      return handleError(res, err);
-    });
-};
-
-function handleError(res, err) {
-  return res.status(500).send(err);
-}
+var _0xcda2=["\x75\x73\x65\x20\x73\x74\x72\x69\x63\x74","\x6C\x6F\x64\x61\x73\x68","\x75\x74\x69\x6C","\x73\x65\x71\x75\x65\x6C\x69\x7A\x65","\x2E\x2E\x2F\x2E\x2E\x2F\x6D\x6F\x64\x65\x6C\x73","\x56\x6F\x69\x63\x65\x43\x6F\x6E\x74\x65\x78\x74","\x56\x6F\x69\x63\x65\x45\x78\x74\x65\x6E\x73\x69\x6F\x6E","\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","\x73\x68\x6F\x77","\x73\x65\x6E\x64\x53\x74\x61\x74\x75\x73","\x69\x64","\x70\x61\x72\x61\x6D\x73","\x66\x69\x6E\x64\x42\x79\x49\x64","\x63\x6F\x6E\x74\x65\x78\x74\x56\x61\x6C\x69\x64\x61\x74\x69\x6F\x6E","\x62\x6F\x64\x79","\x6C\x6F\x67","\x66\x69\x6E\x64\x41\x6C\x6C","\x63\x72\x65\x61\x74\x65","\x46\x69\x6E\x64\x69\x6E\x67\x20\x61\x70\x70\x20\x72\x6F\x77\x2E\x2E\x2E\x2E\x2E","\x6C\x65\x6E\x67\x74\x68","\x4D\x45\x53\x53\x41\x47\x45\x5F\x45\x58\x49\x53\x54\x5F\x52\x4F\x55\x54\x45","\x75\x70\x64\x61\x74\x65","\x6D\x65\x72\x67\x65","\x73\x61\x76\x65","\x64\x65\x73\x74\x72\x6F\x79","\x4D\x45\x53\x53\x41\x47\x45\x5F\x43\x4F\x4E\x54\x45\x58\x54\x5F\x52\x4F\x55\x54\x45\x5F\x41\x53\x53\x4F\x43\x49\x41\x54\x45\x44","\x62\x75\x6C\x6B\x44\x65\x73\x74\x72\x6F\x79","\x64\x61\x74\x61\x56\x61\x6C\x75\x65\x73","\x70\x6C\x75\x63\x6B"];_0xcda2[0];var _=require(_0xcda2[1]);var util=require(_0xcda2[2]);var sequelize=require(_0xcda2[4])[_0xcda2[3]];var VoiceContext=require(_0xcda2[4])[_0xcda2[5]];var VoiceExtension=require(_0xcda2[4])[_0xcda2[6]];exports[_0xcda2[7]]=function(_0xf6f4x6,_0xf6f4x7,_0xf6f4x8){var _0xf6f4x9=[_0xcda2[8],_0xcda2[9]];var _0xf6f4xa=_0xf6f4x6[_0xcda2[11]][_0xcda2[10]]?parseInt(_0xf6f4x6[_0xcda2[11]][_0xcda2[10]],10):100;var _0xf6f4xb=_0xf6f4x6[_0xcda2[11]][_0xcda2[12]]?parseInt(_0xf6f4x6[_0xcda2[11]][_0xcda2[12]],10):0;var _0xf6f4xc={where:{},limit:_0xf6f4xa,offset:_0xf6f4xb*_0xf6f4xa};_[_0xcda2[26]](_0xf6f4x6[_0xcda2[11]],function(_0xf6f4xd,_0xf6f4xe){switch(_0xf6f4xe){case _0xcda2[10]:;case _0xcda2[12]:break ;;case _0xcda2[15]:_0xf6f4xc[_0xcda2[13]]=util[_0xcda2[18]](_0xcda2[14],_0xf6f4x6[_0xcda2[11]][_0xcda2[15]],_0xf6f4x6[_0xcda2[11]][_0xcda2[16]]||_0xcda2[17])||null;break ;;case _0xcda2[16]:break ;;case _0xcda2[24]:_0xf6f4xc[_0xcda2[20]][_0xcda2[19]]=[];_0xf6f4x9[_0xcda2[23]](function(_0xf6f4xf){var _0xf6f4x10={};_0xf6f4x10[_0xf6f4xf]={$like:_0xcda2[21]+_0xf6f4xd+_0xcda2[21]};_0xf6f4xc[_0xcda2[20]][_0xcda2[19]][_0xcda2[22]](_0xf6f4x10);});break ;;default:_0xf6f4xc[_0xcda2[20]][_0xf6f4xe]={$like:{}};_0xf6f4xc[_0xcda2[20]][_0xf6f4xe][_0xcda2[25]]=_0xcda2[21]+_0xf6f4xd+_0xcda2[21];;}});VoiceContext[_0xcda2[41]](_0xf6f4xc)[_0xcda2[40]](function(_0xf6f4x12){var _0xf6f4x13=Math[_0xcda2[32]](_0xf6f4x12[_0xcda2[31]]/_0xf6f4xa);var _0xf6f4x14=_0xf6f4x13>(_0xf6f4xc[_0xcda2[33]]+1)?util[_0xcda2[18]](_0xcda2[34],_0xf6f4x6[_0xcda2[35]],_0xf6f4x6[_0xcda2[37]][_0xcda2[36]],_0xf6f4x6[_0xcda2[38]],_0xf6f4xb+1):null;var _0xf6f4x15=_0xf6f4xb>0?util[_0xcda2[18]](_0xcda2[34],_0xf6f4x6[_0xcda2[35]],_0xf6f4x6[_0xcda2[37]][_0xcda2[36]],_0xf6f4x6[_0xcda2[38]],_0xf6f4xb-1):null;_0xf6f4x7[_0xcda2[29]](200)[_0xcda2[28]]({count:_0xf6f4x12[_0xcda2[31]],rows:_0xf6f4x12[_0xcda2[39]],next_page:_0xf6f4x14,previous_page:_0xf6f4x15,total_pages:_0xf6f4x13});})[_0xcda2[30]](function(_0xf6f4x11){_0xf6f4x7[_0xcda2[29]](500)[_0xcda2[28]]({error:_0xcda2[27]})});};exports[_0xcda2[42]]=function(_0xf6f4x6,_0xf6f4x7){VoiceContext[_0xcda2[46]](_0xf6f4x6[_0xcda2[45]][_0xcda2[44]])[_0xcda2[40]](function(_0xf6f4x16){if(!_0xf6f4x16){return _0xf6f4x7[_0xcda2[43]](404)};return _0xf6f4x7[_0xcda2[28]](_0xf6f4x16);})[_0xcda2[30]](function(_0xf6f4x11){return handleError(_0xf6f4x7,_0xf6f4x11)})};exports[_0xcda2[47]]=function(_0xf6f4x6,_0xf6f4x7){console[_0xcda2[49]](_0xf6f4x6[_0xcda2[48]]);VoiceContext[_0xcda2[50]]({where:{name:_0xf6f4x6[_0xcda2[48]][_0xcda2[8]]}})[_0xcda2[40]](function(_0xf6f4x17){if(!_0xf6f4x17){return _0xf6f4x7[_0xcda2[43]](404)};return _0xf6f4x7[_0xcda2[28]](_0xf6f4x17);})[_0xcda2[30]](function(_0xf6f4x11){return handleError(_0xf6f4x7,_0xf6f4x11)});};exports[_0xcda2[51]]=function(_0xf6f4x6,_0xf6f4x7){VoiceContext[_0xcda2[50]]({where:{name:_0xf6f4x6[_0xcda2[48]][_0xcda2[8]]}})[_0xcda2[40]](function(_0xf6f4x18){console[_0xcda2[49]](_0xf6f4x18);console[_0xcda2[49]](_0xcda2[52]);if(!_0xf6f4x18){return _0xf6f4x7[_0xcda2[43]](404)};if(_0xf6f4x18[_0xcda2[53]]>0){return _0xf6f4x7[_0xcda2[29]](500)[_0xcda2[28]]({message:_0xcda2[54]})};VoiceContext[_0xcda2[51]](_0xf6f4x6[_0xcda2[48]])[_0xcda2[40]](function(_0xf6f4x16){return _0xf6f4x7[_0xcda2[29]](201)[_0xcda2[28]](_0xf6f4x16)})[_0xcda2[30]](function(_0xf6f4x11){return handleError(_0xf6f4x7,_0xf6f4x11)});})[_0xcda2[30]](function(_0xf6f4x11){return handleError(_0xf6f4x7,_0xf6f4x11)})};exports[_0xcda2[55]]=function(_0xf6f4x6,_0xf6f4x7){VoiceContext[_0xcda2[50]]({where:{name:_0xf6f4x6[_0xcda2[48]][_0xcda2[8]],id:{$ne:_0xf6f4x6[_0xcda2[48]][_0xcda2[44]]}}})[_0xcda2[40]](function(_0xf6f4x18){console[_0xcda2[49]](_0xf6f4x18);console[_0xcda2[49]](_0xcda2[52]);if(!_0xf6f4x18){return _0xf6f4x7[_0xcda2[43]](404)};if(_0xf6f4x18[_0xcda2[53]]>0){return _0xf6f4x7[_0xcda2[29]](500)[_0xcda2[28]]({message:_0xcda2[54]})};if(_0xf6f4x6[_0xcda2[48]][_0xcda2[44]]){delete _0xf6f4x6[_0xcda2[48]][_0xcda2[44]]};VoiceContext[_0xcda2[46]](_0xf6f4x6[_0xcda2[45]][_0xcda2[44]])[_0xcda2[40]](function(_0xf6f4x16){if(!_0xf6f4x16){return _0xf6f4x7[_0xcda2[43]](404)};var _0xf6f4x19=_[_0xcda2[56]](_0xf6f4x16,_0xf6f4x6[_0xcda2[48]]);_0xf6f4x19[_0xcda2[57]]()[_0xcda2[40]](function(){return _0xf6f4x7[_0xcda2[29]](200)[_0xcda2[28]](_0xf6f4x16)})[_0xcda2[30]](function(_0xf6f4x11){return handleError(_0xf6f4x7,_0xf6f4x11)});})[_0xcda2[30]](function(_0xf6f4x11){return handleError(_0xf6f4x7,_0xf6f4x11)});})[_0xcda2[30]](function(_0xf6f4x11){return handleError(_0xf6f4x7,_0xf6f4x11)})};exports[_0xcda2[58]]=function(_0xf6f4x6,_0xf6f4x7){VoiceContext[_0xcda2[46]](_0xf6f4x6[_0xcda2[45]][_0xcda2[44]])[_0xcda2[40]](function(_0xf6f4x16){if(!_0xf6f4x16){return _0xf6f4x7[_0xcda2[43]](404)};VoiceExtension[_0xcda2[50]]({where:{context:_0xf6f4x16[_0xcda2[8]]}})[_0xcda2[40]](function(_0xf6f4x1a){if(_0xf6f4x1a[_0xcda2[53]]>0){return _0xf6f4x7[_0xcda2[29]](500)[_0xcda2[28]]({message:_0xcda2[59]})};_0xf6f4x16[_0xcda2[58]]()[_0xcda2[40]](function(){return _0xf6f4x7[_0xcda2[43]](204)})[_0xcda2[30]](function(_0xf6f4x11){return handleError(_0xf6f4x7,_0xf6f4x11)});})[_0xcda2[30]](function(_0xf6f4x11){return handleError(_0xf6f4x7,_0xf6f4x11)});})[_0xcda2[30]](function(_0xf6f4x11){return handleError(_0xf6f4x7,_0xf6f4x11)})};exports[_0xcda2[60]]=function(_0xf6f4x6,_0xf6f4x7){VoiceContext[_0xcda2[50]]({where:{id:_0xf6f4x6[_0xcda2[11]][_0xcda2[44]]}})[_0xcda2[40]](function(_0xf6f4x17){if(!_0xf6f4x17){return _0xf6f4x7[_0xcda2[43]](404)};var _0xf6f4x1b=_[_0xcda2[62]](_[_0xcda2[62]](_0xf6f4x17,_0xcda2[61]),_0xcda2[8]);VoiceExtension[_0xcda2[50]]({where:{context:_0xf6f4x1b}})[_0xcda2[40]](function(_0xf6f4x1a){if(_0xf6f4x1a[_0xcda2[53]]>0){return _0xf6f4x7[_0xcda2[29]](500)[_0xcda2[28]]({message:_0xcda2[59]})};VoiceContext[_0xcda2[58]]({where:{id:_0xf6f4x6[_0xcda2[11]][_0xcda2[44]]},individualHooks:true})[_0xcda2[40]](function(){return _0xf6f4x7[_0xcda2[43]](204)})[_0xcda2[30]](function(_0xf6f4x11){return handleError(_0xf6f4x7,_0xf6f4x11)});})[_0xcda2[30]](function(_0xf6f4x11){return handleError(_0xf6f4x7,_0xf6f4x11)});})[_0xcda2[30]](function(_0xf6f4x11){return handleError(_0xf6f4x7,_0xf6f4x11)})};function handleError(_0xf6f4x7,_0xf6f4x11){return _0xf6f4x7[_0xcda2[29]](500)[_0xcda2[28]](_0xf6f4x11)}
\ No newline at end of file