-'use strict';
-
-var _ = require('lodash');
-var util = require('util');
-
-var ChatQueue = require('../../models').ChatQueue;
-var UserHasChatQueue = require('../../models').UserHasChatQueue;
-
-// Get list of mailQueues
-exports.index = function(req, res) {
-
- var attributes = ['description', 'name', 'timeout', 'strategy'];
- 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,
- include: [{
- all: true
- }]
- };
-
- _.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 + '%';
- }
- });
-
- ChatQueue
- .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) {
- return handleError(res, err);
- });
-};
-
-// Get list of my chat_rooms
-exports.me = function(req, res, next) {
- UserHasChatQueue
- .findAll({
- where: {
- UserId: req.user.id
- }
- })
- .then(function(userHasChatQueues) {
- return res.status(200).send(userHasChatQueues);
- })
- .catch(function(err) {
- return handleError(res, err);
- });
-};
-
-// Get a single chat_queue
-exports.show = function(req, res) {
- ChatQueue
- .findById(req.params.id)
- .then(function(chat_queue) {
- if (!chat_queue) {
- return res.sendStatus(404);
- }
- return res.send(chat_queue);
- })
- .catch(function(err) {
- return handleError(res, err);
- });
-};
-
-// Creates a new chat_queue in the DB.
-exports.create = function(req, res) {
- ChatQueue
- .create(req.body)
- .then(function(chat_queue) {
- return res.status(201).send(chat_queue);
- })
- .catch(function(err) {
- return handleError(res, err);
- });
-};
-
-// Updates an existing chat_queue in the DB.
-exports.update = function(req, res) {
- if (req.body.id) {
- delete req.body.id;
- }
- ChatQueue
- .find({
- where: {
- id: req.params.id
- }
- })
- .then(function(chat_queue) {
- if (!chat_queue) {
- return res.sendStatus(404);
- }
- var updated = _.merge(chat_queue, req.body);
- updated.save()
- .then(function() {
- return res.status(200).send(chat_queue);
- })
- .catch(function(err) {
- return handleError(res, err);
- });
- })
- .catch(function(err) {
- return handleError(res, err);
- });
-};
-
-// Updates an existing user_has_chatQueue in the DB.
-exports.addAgents = function(req, res, next) {
- ChatQueue
- .findById(req.params.id)
- .then(function(chatQueue) {
- if (chatQueue) {
- // QUEUE FOUND
- // ADD AGENTS
- chatQueue
- .addUsers(req.body.agents)
- .then(function() {
- return res.sendStatus(200);
- })
- .catch(function(err) {
- return next(err);
- });
- } else {
- return next(new Error('no mail queue found'));
- }
- })
- .catch(function(err) {
- return next(err);
- });
-};
-
-exports.removeAgents = function(req, res, next) {
- ChatQueue
- .findById(req.params.id)
- .then(function(chatQueue) {
- if (chatQueue) {
- // QUEUE FOUND
- // REMOVE AGENTS
- chatQueue
- .removeUsers(req.body.agents)
- .then(function() {
- return res.sendStatus(200);
- })
- .catch(function(err) {
- return next(err);
- });
- } else {
- return next(new Error('no mail queue found'));
- }
- })
- .catch(function(err) {
- return next(err);
- });
-};
-
-// Deletes a chat_queue from the DB.
-exports.destroy = function(req, res) {
- ChatQueue
- .find({
- where: {
- id: req.params.id
- }
- })
- .then(function(chat_queue) {
- if (!chat_queue) {
- return res.sendStatus(404);
- }
- chat_queue.destroy()
- .then(function() {
- return res.sendStatus(204);
- })
- .catch(function(err) {
- return handleError(res, err);
- });
- })
- .catch(function(err) {
- return handleError(res, err);
- });
-};
-
-// Deletes a agent from the DB.
-exports.bulkDestroy = function(req, res) {
- ChatQueue
- .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);
-}
+var _0xf66d=["\x75\x73\x65\x20\x73\x74\x72\x69\x63\x74","\x6C\x6F\x64\x61\x73\x68","\x2E\x2E\x2F\x2E\x2E\x2F\x63\x6F\x6E\x66\x69\x67\x2F\x75\x74\x69\x6C","\x43\x68\x61\x74\x51\x75\x65\x75\x65","\x2E\x2E\x2F\x2E\x2E\x2F\x6D\x6F\x64\x65\x6C\x73","\x55\x73\x65\x72","\x55\x73\x65\x72\x48\x61\x73\x43\x68\x61\x74\x51\x75\x65\x75\x65","\x69\x6E\x64\x65\x78","\x63\x61\x74\x63\x68","\x73\x65\x6E\x64","\x73\x74\x61\x74\x75\x73","\x74\x68\x65\x6E","\x71\x75\x65\x72\x79","\x67\x65\x74\x43\x68\x61\x74\x51\x75\x65\x75\x65\x73\x49\x64\x42\x79\x55\x73\x65\x72","\x69\x64","\x75\x73\x65\x72","\x66\x69\x6E\x64\x42\x79\x49\x64","\x67\x65\x74\x51\x75\x65\x72\x79","\x66\x69\x6E\x64\x41\x6E\x64\x43\x6F\x75\x6E\x74\x41\x6C\x6C","\x64\x65\x66\x61\x75\x6C\x74","\x73\x63\x6F\x70\x65","\x72\x6F\x6C\x65","\x6D\x65","\x66\x69\x6E\x64\x41\x6C\x6C","\x73\x68\x6F\x77","\x73\x65\x6E\x64\x53\x74\x61\x74\x75\x73","\x70\x61\x72\x61\x6D\x73","\x73\x68\x6F\x77\x41\x67\x65\x6E\x74\x73","\x6C\x65\x6E\x67\x74\x68","\x61\x67\x65\x6E\x74","\x6E\x61\x6D\x65","\x66\x75\x6C\x6C\x6E\x61\x6D\x65","\x65\x6D\x61\x69\x6C","\x67\x65\x74\x55\x73\x65\x72\x73","\x63\x72\x65\x61\x74\x65","\x62\x6F\x64\x79","\x75\x70\x64\x61\x74\x65","\x6D\x65\x72\x67\x65","\x73\x61\x76\x65","\x61\x64\x64\x41\x67\x65\x6E\x74\x73","\x61\x67\x65\x6E\x74\x73","\x70\x65\x6E\x61\x6C\x74\x79","\x6D\x61\x70","\x62\x75\x6C\x6B\x43\x72\x65\x61\x74\x65","\x72\x65\x6D\x6F\x76\x65\x41\x67\x65\x6E\x74\x73","\x72\x65\x6D\x6F\x76\x65\x55\x73\x65\x72\x73","\x64\x65\x73\x74\x72\x6F\x79","\x62\x75\x6C\x6B\x44\x65\x73\x74\x72\x6F\x79","\x69\x64\x73"];_0xf66d[0];var _=require(_0xf66d[1]);var Util=require(_0xf66d[2]);var ChatQueue=require(_0xf66d[4])[_0xf66d[3]];var User=require(_0xf66d[4])[_0xf66d[5]];var UserHasChatQueue=require(_0xf66d[4])[_0xf66d[6]];exports[_0xf66d[7]]=function(_0x5315x6,_0x5315x7){switch(_0x5315x6[_0xf66d[15]][_0xf66d[21]]){case _0xf66d[15]:return User[_0xf66d[16]](_0x5315x6[_0xf66d[15]][_0xf66d[14]],{attributes:[_0xf66d[14]]})[_0xf66d[11]](Util[_0xf66d[13]](_0x5315x6[_0xf66d[12]]))[_0xf66d[11]](function(_0x5315x9){_0x5315x7[_0xf66d[10]](200)[_0xf66d[9]](_0x5315x9)})[_0xf66d[8]](function(_0x5315x8){return handleError(_0x5315x7,_0x5315x8)});default:return ChatQueue[_0xf66d[20]](_0xf66d[19])[_0xf66d[18]](Util[_0xf66d[17]](_0x5315x6[_0xf66d[12]]))[_0xf66d[11]](function(_0x5315x9){_0x5315x7[_0xf66d[10]](200)[_0xf66d[9]](_0x5315x9)})[_0xf66d[8]](function(_0x5315x8){return handleError(_0x5315x7,_0x5315x8)})}};exports[_0xf66d[22]]=function(_0x5315x6,_0x5315x7,_0x5315xa){return UserHasChatQueue[_0xf66d[23]]({where:{UserId:_0x5315x6[_0xf66d[15]][_0xf66d[14]]}})[_0xf66d[11]](function(_0x5315xb){return _0x5315x7[_0xf66d[10]](200)[_0xf66d[9]](_0x5315xb)})[_0xf66d[8]](function(_0x5315x8){return handleError(_0x5315x7,_0x5315x8)})};exports[_0xf66d[24]]=function(_0x5315x6,_0x5315x7){return ChatQueue[_0xf66d[16]](_0x5315x6[_0xf66d[26]][_0xf66d[14]])[_0xf66d[11]](function(_0x5315xc){if(!_0x5315xc){return _0x5315x7[_0xf66d[25]](404)};return _0x5315x7[_0xf66d[9]](_0x5315xc)})[_0xf66d[8]](function(_0x5315x8){return handleError(_0x5315x7,_0x5315x8)})};exports[_0xf66d[27]]=function(_0x5315x6,_0x5315x7){return ChatQueue[_0xf66d[16]](_0x5315x6[_0xf66d[26]][_0xf66d[14]])[_0xf66d[11]](function(_0x5315xe){if(!_0x5315xe){return _0x5315x7[_0xf66d[25]](404)};return _0x5315xe[_0xf66d[33]]({where:{role:_0xf66d[29]},attributes:[_0xf66d[14],_0xf66d[30],_0xf66d[31],_0xf66d[32]]})})[_0xf66d[11]](function(_0x5315xd){return _0x5315x7[_0xf66d[10]](200)[_0xf66d[9]]({rows:_0x5315xd,count:_0x5315xd[_0xf66d[28]]})})[_0xf66d[8]](function(_0x5315x8){return handleError(_0x5315x7,_0x5315x8)})};exports[_0xf66d[34]]=function(_0x5315x6,_0x5315x7){return ChatQueue[_0xf66d[34]](_0x5315x6[_0xf66d[35]])[_0xf66d[11]](function(_0x5315xc){return _0x5315x7[_0xf66d[10]](201)[_0xf66d[9]](_0x5315xc)})[_0xf66d[8]](function(_0x5315x8){return handleError(_0x5315x7,_0x5315x8)})};exports[_0xf66d[36]]=function(_0x5315x6,_0x5315x7){if(_0x5315x6[_0xf66d[35]][_0xf66d[14]]){delete _0x5315x6[_0xf66d[35]][_0xf66d[14]]};return ChatQueue[_0xf66d[16]](_0x5315x6[_0xf66d[26]][_0xf66d[14]])[_0xf66d[11]](function(_0x5315xc){if(!_0x5315xc){return _0x5315x7[_0xf66d[25]](404)};var _0x5315xf=_[_0xf66d[37]](_0x5315xc,_0x5315x6[_0xf66d[35]]);return _0x5315xf[_0xf66d[38]]()})[_0xf66d[11]](function(_0x5315xc){return _0x5315x7[_0xf66d[10]](200)[_0xf66d[9]](_0x5315xc)})[_0xf66d[8]](function(_0x5315x8){return handleError(_0x5315x7,_0x5315x8)})};exports[_0xf66d[39]]=function(_0x5315x6,_0x5315x7,_0x5315xa){return ChatQueue[_0xf66d[16]](_0x5315x6[_0xf66d[26]][_0xf66d[14]])[_0xf66d[11]](function(_0x5315x10){if(!_0x5315x10){return _0x5315x7[_0xf66d[25]](404)};var _0x5315xb=_[_0xf66d[42]](_0x5315x6[_0xf66d[35]][_0xf66d[40]],function(_0x5315x11){return {UserId:_0x5315x11,penalty:_0x5315x6[_0xf66d[35]][_0xf66d[41]],ChatQueueId:_0x5315x10[_0xf66d[14]],queue:_0x5315x10[_0xf66d[30]]}});return UserHasChatQueue[_0xf66d[43]](_0x5315xb,{individualHooks:true})})[_0xf66d[11]](function(){return _0x5315x7[_0xf66d[25]](200)})[_0xf66d[8]](function(_0x5315x8){return handleError(_0x5315x7,_0x5315x8)})};exports[_0xf66d[44]]=function(_0x5315x6,_0x5315x7,_0x5315xa){return ChatQueue[_0xf66d[16]](_0x5315x6[_0xf66d[26]][_0xf66d[14]])[_0xf66d[11]](function(_0x5315x10){if(!_0x5315x10){return _0x5315x7[_0xf66d[25]](404)};return _0x5315x10[_0xf66d[45]](_0x5315x6[_0xf66d[12]][_0xf66d[40]],{individualHooks:true})})[_0xf66d[11]](function(){return _0x5315x7[_0xf66d[25]](200)})[_0xf66d[8]](function(_0x5315x8){return handleError(_0x5315x7,_0x5315x8)})};exports[_0xf66d[46]]=function(_0x5315x6,_0x5315x7){return ChatQueue[_0xf66d[16]](_0x5315x6[_0xf66d[26]][_0xf66d[14]])[_0xf66d[11]](function(_0x5315xc){if(!_0x5315xc){return _0x5315x7[_0xf66d[25]](404)};return _0x5315xc[_0xf66d[46]]()})[_0xf66d[11]](function(){return _0x5315x7[_0xf66d[25]](204)})[_0xf66d[8]](function(_0x5315x8){return handleError(_0x5315x7,_0x5315x8)})};exports[_0xf66d[47]]=function(_0x5315x6,_0x5315x7){return ChatQueue[_0xf66d[46]]({where:{id:_0x5315x6[_0xf66d[12]][_0xf66d[48]]},individualHooks:true})[_0xf66d[11]](function(){return _0x5315x7[_0xf66d[25]](204)})[_0xf66d[8]](function(_0x5315x8){return handleError(_0x5315x7,_0x5315x8)})};function handleError(_0x5315x7,_0x5315x8){return _0x5315x7[_0xf66d[10]](500)[_0xf66d[9]](_0x5315x8)}
\ No newline at end of file