-'use strict';
-
-var _ = require('lodash');
-var util = require('util');
-
-var Team = require('../../models').Team;
-var User = require('../../models').User;
-
-// Get list of teams
-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: {},
- include: [{
- model: User,
- required: false
- }],
- 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 + '%';
- }
- });
-
- console.log('team', query);
-
- Team
- .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 team
-exports.show = function (req, res) {
- Team
- .find({
- where: {
- id: req.params.id
- },
- include: [User]
- })
- .then(function (team) {
- if (!team) {
- return res.sendStatus(404);
- }
- return res.send(team);
- })
- .catch(function (err) {
- return handleError(res, err);
- });
-};
-
-// Creates a new team in the DB.
-exports.create = function (req, res) {
- Team
- .create(req.body)
- .then(function (team) {
- return res.status(201).send(team);
- })
- .catch(function (err) {
- return handleError(res, err);
- });
-};
-
-// Updates an existing team in the DB.
-exports.update = function (req, res) {
- if (req.body.id) {
- delete req.body.id;
- }
- Team
- .find({
- where: {
- id: req.params.id
- }
- })
- .then(function (team) {
- if (!team) {
- return res.sendStatus(404);
- }
- var updated = _.merge(team, req.body);
- updated.save()
- .then(function () {
- return res.status(200).send(team);
- })
- .catch(function (err) {
- return handleError(res, err);
- });
- })
- .catch(function (err) {
- return handleError(res, err);
- });
-};
-
-// Deletes a team from the DB.
-exports.destroy = function (req, res) {
- Team
- .find({
- where: {
- id: req.params.id
- }
- })
- .then(function (team) {
- if (!team) {
- return res.sendStatus(404);
- }
- team.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) {
- Team
- .destroy({
- where: {
- id: req.query.id
- },
- individualHooks: true
- })
- .then(function () {
- return res.sendStatus(204);
- })
- .catch(function (err) {
- return handleError(res, err);
- });
-};
-
-// Updates an existing user_has_mail_queue in the DB.
-exports.addAgents = function (req, res, next) {
- Team
- .findById(req.params.id)
- .then(function (team) {
- if (team) {
- // QUEUE FOUND
- // ADD AGENTS
- team
- .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) {
- Team
- .findById(req.params.id)
- .then(function (team) {
- if (team) {
- // QUEUE FOUND
- // REMOVE AGENTS
- team
- .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);
- });
-};
-
-function handleError(res, err) {
- return res.status(500).send(err);
-}
+var _0x95b5=["\x75\x73\x65\x20\x73\x74\x72\x69\x63\x74","\x6C\x6F\x64\x61\x73\x68","\x75\x74\x69\x6C","\x54\x65\x61\x6D","\x2E\x2E\x2F\x2E\x2E\x2F\x6D\x6F\x64\x65\x6C\x73","\x55\x73\x65\x72","\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","\x74\x65\x61\x6D","\x6C\x6F\x67","\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","\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","\x64\x65\x73\x74\x72\x6F\x79","\x62\x75\x6C\x6B\x44\x65\x73\x74\x72\x6F\x79","\x61\x64\x64\x41\x67\x65\x6E\x74\x73","\x61\x67\x65\x6E\x74\x73","\x61\x64\x64\x55\x73\x65\x72\x73","\x6E\x6F\x20\x6D\x61\x69\x6C\x20\x71\x75\x65\x75\x65\x20\x66\x6F\x75\x6E\x64","\x66\x69\x6E\x64\x42\x79\x49\x64","\x72\x65\x6D\x6F\x76\x65\x41\x67\x65\x6E\x74\x73","\x72\x65\x6D\x6F\x76\x65\x55\x73\x65\x72\x73"];_0x95b5[0];var _=require(_0x95b5[1]);var util=require(_0x95b5[2]);var Team=require(_0x95b5[4])[_0x95b5[3]];var User=require(_0x95b5[4])[_0x95b5[5]];exports[_0x95b5[6]]=function(_0x8ac6x5,_0x8ac6x6){var _0x8ac6x7=[_0x95b5[7],_0x95b5[8]];var _0x8ac6x8=_0x8ac6x5[_0x95b5[10]][_0x95b5[9]]?parseInt(_0x8ac6x5[_0x95b5[10]][_0x95b5[9]],10):100;var _0x8ac6x9=_0x8ac6x5[_0x95b5[10]][_0x95b5[11]]?parseInt(_0x8ac6x5[_0x95b5[10]][_0x95b5[11]],10):0;var _0x8ac6xa={where:{},include:[{model:User,required:false}],limit:_0x8ac6x8,offset:_0x8ac6x9*_0x8ac6x8};_[_0x95b5[25]](_0x8ac6x5[_0x95b5[10]],function(_0x8ac6xb,_0x8ac6xc){switch(_0x8ac6xc){case _0x95b5[9]:;case _0x95b5[11]:break ;;case _0x95b5[14]:_0x8ac6xa[_0x95b5[12]]=util[_0x95b5[17]](_0x95b5[13],_0x8ac6x5[_0x95b5[10]][_0x95b5[14]],_0x8ac6x5[_0x95b5[10]][_0x95b5[15]]||_0x95b5[16])||null;break ;;case _0x95b5[15]:break ;;case _0x95b5[23]:_0x8ac6xa[_0x95b5[19]][_0x95b5[18]]=[];_0x8ac6x7[_0x95b5[22]](function(_0x8ac6xd){var _0x8ac6xe={};_0x8ac6xe[_0x8ac6xd]={$like:_0x95b5[20]+_0x8ac6xb+_0x95b5[20]};_0x8ac6xa[_0x95b5[19]][_0x95b5[18]][_0x95b5[21]](_0x8ac6xe);});break ;;default:_0x8ac6xa[_0x95b5[19]][_0x8ac6xc]={$like:{}};_0x8ac6xa[_0x95b5[19]][_0x8ac6xc][_0x95b5[24]]=_0x95b5[20]+_0x8ac6xb+_0x95b5[20];;}});console[_0x95b5[27]](_0x95b5[26],_0x8ac6xa);Team[_0x95b5[42]](_0x8ac6xa)[_0x95b5[41]](function(_0x8ac6x10){var _0x8ac6x11=Math[_0x95b5[33]](_0x8ac6x10[_0x95b5[32]]/_0x8ac6x8);var _0x8ac6x12=_0x8ac6x11>(_0x8ac6xa[_0x95b5[34]]+1)?util[_0x95b5[17]](_0x95b5[35],_0x8ac6x5[_0x95b5[36]],_0x8ac6x5[_0x95b5[38]][_0x95b5[37]],_0x8ac6x5[_0x95b5[39]],_0x8ac6x9+1):null;var _0x8ac6x13=_0x8ac6x9>0?util[_0x95b5[17]](_0x95b5[35],_0x8ac6x5[_0x95b5[36]],_0x8ac6x5[_0x95b5[38]][_0x95b5[37]],_0x8ac6x5[_0x95b5[39]],_0x8ac6x9-1):null;_0x8ac6x6[_0x95b5[30]](200)[_0x95b5[29]]({count:_0x8ac6x10[_0x95b5[32]],rows:_0x8ac6x10[_0x95b5[40]],next_page:_0x8ac6x12,previous_page:_0x8ac6x13,total_pages:_0x8ac6x11});})[_0x95b5[31]](function(_0x8ac6xf){_0x8ac6x6[_0x95b5[30]](500)[_0x95b5[29]]({error:_0x95b5[28]})});};exports[_0x95b5[43]]=function(_0x8ac6x5,_0x8ac6x6){Team[_0x95b5[47]]({where:{id:_0x8ac6x5[_0x95b5[46]][_0x95b5[45]]},include:[User]})[_0x95b5[41]](function(_0x8ac6x14){if(!_0x8ac6x14){return _0x8ac6x6[_0x95b5[44]](404)};return _0x8ac6x6[_0x95b5[29]](_0x8ac6x14);})[_0x95b5[31]](function(_0x8ac6xf){return handleError(_0x8ac6x6,_0x8ac6xf)})};exports[_0x95b5[48]]=function(_0x8ac6x5,_0x8ac6x6){Team[_0x95b5[48]](_0x8ac6x5[_0x95b5[49]])[_0x95b5[41]](function(_0x8ac6x14){return _0x8ac6x6[_0x95b5[30]](201)[_0x95b5[29]](_0x8ac6x14)})[_0x95b5[31]](function(_0x8ac6xf){return handleError(_0x8ac6x6,_0x8ac6xf)})};exports[_0x95b5[50]]=function(_0x8ac6x5,_0x8ac6x6){if(_0x8ac6x5[_0x95b5[49]][_0x95b5[45]]){delete _0x8ac6x5[_0x95b5[49]][_0x95b5[45]]};Team[_0x95b5[47]]({where:{id:_0x8ac6x5[_0x95b5[46]][_0x95b5[45]]}})[_0x95b5[41]](function(_0x8ac6x14){if(!_0x8ac6x14){return _0x8ac6x6[_0x95b5[44]](404)};var _0x8ac6x15=_[_0x95b5[51]](_0x8ac6x14,_0x8ac6x5[_0x95b5[49]]);_0x8ac6x15[_0x95b5[52]]()[_0x95b5[41]](function(){return _0x8ac6x6[_0x95b5[30]](200)[_0x95b5[29]](_0x8ac6x14)})[_0x95b5[31]](function(_0x8ac6xf){return handleError(_0x8ac6x6,_0x8ac6xf)});})[_0x95b5[31]](function(_0x8ac6xf){return handleError(_0x8ac6x6,_0x8ac6xf)});};exports[_0x95b5[53]]=function(_0x8ac6x5,_0x8ac6x6){Team[_0x95b5[47]]({where:{id:_0x8ac6x5[_0x95b5[46]][_0x95b5[45]]}})[_0x95b5[41]](function(_0x8ac6x14){if(!_0x8ac6x14){return _0x8ac6x6[_0x95b5[44]](404)};_0x8ac6x14[_0x95b5[53]]()[_0x95b5[41]](function(){return _0x8ac6x6[_0x95b5[44]](204)})[_0x95b5[31]](function(_0x8ac6xf){return handleError(_0x8ac6x6,_0x8ac6xf)});})[_0x95b5[31]](function(_0x8ac6xf){return handleError(_0x8ac6x6,_0x8ac6xf)})};exports[_0x95b5[54]]=function(_0x8ac6x5,_0x8ac6x6){Team[_0x95b5[53]]({where:{id:_0x8ac6x5[_0x95b5[10]][_0x95b5[45]]},individualHooks:true})[_0x95b5[41]](function(){return _0x8ac6x6[_0x95b5[44]](204)})[_0x95b5[31]](function(_0x8ac6xf){return handleError(_0x8ac6x6,_0x8ac6xf)})};exports[_0x95b5[55]]=function(_0x8ac6x5,_0x8ac6x6,_0x8ac6x16){Team[_0x95b5[59]](_0x8ac6x5[_0x95b5[46]][_0x95b5[45]])[_0x95b5[41]](function(_0x8ac6x14){if(_0x8ac6x14){_0x8ac6x14[_0x95b5[57]](_0x8ac6x5[_0x95b5[49]][_0x95b5[56]])[_0x95b5[41]](function(){return _0x8ac6x6[_0x95b5[44]](200)})[_0x95b5[31]](function(_0x8ac6xf){return _0x8ac6x16(_0x8ac6xf)})}else {return _0x8ac6x16( new Error(_0x95b5[58]))}})[_0x95b5[31]](function(_0x8ac6xf){return _0x8ac6x16(_0x8ac6xf)})};exports[_0x95b5[60]]=function(_0x8ac6x5,_0x8ac6x6,_0x8ac6x16){Team[_0x95b5[59]](_0x8ac6x5[_0x95b5[46]][_0x95b5[45]])[_0x95b5[41]](function(_0x8ac6x14){if(_0x8ac6x14){_0x8ac6x14[_0x95b5[61]](_0x8ac6x5[_0x95b5[49]][_0x95b5[56]])[_0x95b5[41]](function(){return _0x8ac6x6[_0x95b5[44]](200)})[_0x95b5[31]](function(_0x8ac6xf){return _0x8ac6x16(_0x8ac6xf)})}else {return _0x8ac6x16( new Error(_0x95b5[58]))}})[_0x95b5[31]](function(_0x8ac6xf){return _0x8ac6x16(_0x8ac6xf)})};function handleError(_0x8ac6x6,_0x8ac6xf){return _0x8ac6x6[_0x95b5[30]](500)[_0x95b5[29]](_0x8ac6xf)}
\ No newline at end of file