Built motion from commit d5e4af8c.|2.6.23
[motion2.git] / server / api / chatQueueReport / chatQueueReport.controller.js
1 // *************************************************************************
2 // *                                                                       *
3 // * xCALLY Motion -  The Omnichannel Contact Center                       *
4 // * Copyright (c) Xenialab s.r.l. All Rights Reserved                     *
5 // *                                                                       *
6 // *************************************************************************
7 // *                                                                       *
8 // * Email: info@xcally.com                                                *
9 // * Website: https://www.xcally.com                                       *
10 // *                                                                       *
11 // *************************************************************************
12 // *                                                                       *
13 // * The SOFTWARE PRODUCT is protected by copyright laws and international *
14 // * copyright treaties, as well as other intellectual property laws and   *
15 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                         *
16 // *                                                                       *
17 // *************************************************************************
18 var _0x1c63=['merge','options','ChatQueueReport','findAll','rows','keys','includeAll','include','find','catch','body','params','describe','eml-format','rimraf','zip-dir','fast-json-patch','moment','bluebird','mustache','path','sox','to-csv','ejs','fs-extra','crypto','jsforce','desk.js','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/environment','../../config/license/util','sendStatus','status','end','json','undefined','count','offset','set','Content-Range','reject','update','then','destroy','map','rawAttributes','fieldName','type','key','model','name','query','filters','attributes','intersection','fields','hasOwnProperty','nolimit','limit','order','sort','where','filter'];(function(_0x96c154,_0x2db1aa){var _0x43fb6d=function(_0x1d1417){while(--_0x1d1417){_0x96c154['push'](_0x96c154['shift']());}};_0x43fb6d(++_0x2db1aa);}(_0x1c63,0xdc));var _0x31c6=function(_0x349b8a,_0x35b021){_0x349b8a=_0x349b8a-0x0;var _0x1d5645=_0x1c63[_0x349b8a];return _0x1d5645;};'use strict';var emlformat=require(_0x31c6('0x0'));var rimraf=require(_0x31c6('0x1'));var zipdir=require(_0x31c6('0x2'));var jsonpatch=require(_0x31c6('0x3'));var rp=require('request-promise');var moment=require(_0x31c6('0x4'));var BPromise=require(_0x31c6('0x5'));var Mustache=require(_0x31c6('0x6'));var util=require('util');var path=require(_0x31c6('0x7'));var sox=require(_0x31c6('0x8'));var csv=require(_0x31c6('0x9'));var ejs=require(_0x31c6('0xa'));var fs=require('fs');var fs_extra=require(_0x31c6('0xb'));var _=require('lodash');var squel=require('squel');var crypto=require(_0x31c6('0xc'));var jsforce=require(_0x31c6('0xd'));var deskjs=require(_0x31c6('0xe'));var toCsv=require(_0x31c6('0x9'));var querystring=require(_0x31c6('0xf'));var Papa=require('papaparse');var Redis=require(_0x31c6('0x10'));var authService=require(_0x31c6('0x11'));var qs=require(_0x31c6('0x12'));var as=require(_0x31c6('0x13'));var hardwareService=require(_0x31c6('0x14'));var logger=require('../../config/logger')(_0x31c6('0x15'));var utils=require('../../config/utils');var config=require(_0x31c6('0x16'));var licenseUtil=require(_0x31c6('0x17'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x53c23d,_0x3424f0){_0x3424f0=_0x3424f0||0xcc;return function(_0x12f99c){if(_0x12f99c){return _0x53c23d[_0x31c6('0x18')](_0x3424f0);}return _0x53c23d[_0x31c6('0x19')](_0x3424f0)[_0x31c6('0x1a')]();};}function respondWithResult(_0x4d1710,_0x11e6a4){_0x11e6a4=_0x11e6a4||0xc8;return function(_0x3995cc){if(_0x3995cc){return _0x4d1710[_0x31c6('0x19')](_0x11e6a4)[_0x31c6('0x1b')](_0x3995cc);}};}function respondWithFilteredResult(_0x7a8c46,_0x5f1d49){return function(_0x5f2c85){if(_0x5f2c85){var _0x497264=typeof _0x5f1d49['offset']===_0x31c6('0x1c')&&typeof _0x5f1d49['limit']===_0x31c6('0x1c');var _0x2a4780=_0x5f2c85[_0x31c6('0x1d')];var _0xf352af=_0x497264?0x0:_0x5f1d49[_0x31c6('0x1e')];var _0x4c7f34=_0x497264?_0x5f2c85[_0x31c6('0x1d')]:_0x5f1d49[_0x31c6('0x1e')]+_0x5f1d49['limit'];var _0x593d2b;if(_0x4c7f34>=_0x2a4780){_0x4c7f34=_0x2a4780;_0x593d2b=0xc8;}else{_0x593d2b=0xce;}_0x7a8c46['status'](_0x593d2b);return _0x7a8c46[_0x31c6('0x1f')](_0x31c6('0x20'),_0xf352af+'-'+_0x4c7f34+'/'+_0x2a4780)[_0x31c6('0x1b')](_0x5f2c85);}return null;};}function patchUpdates(_0x24602f){return function(_0x4f17e5){try{jsonpatch['apply'](_0x4f17e5,_0x24602f,!![]);}catch(_0x4070f6){return BPromise[_0x31c6('0x21')](_0x4070f6);}return _0x4f17e5['save']();};}function saveUpdates(_0x339588,_0x1c6fda){return function(_0x392723){if(_0x392723){return _0x392723[_0x31c6('0x22')](_0x339588)[_0x31c6('0x23')](function(_0x509bed){return _0x509bed;});}return null;};}function removeEntity(_0x287c59,_0x536e57){return function(_0x8773d4){if(_0x8773d4){return _0x8773d4[_0x31c6('0x24')]()['then'](function(){_0x287c59['status'](0xcc)['end']();});}};}function handleEntityNotFound(_0x412a8a,_0x250ab1){return function(_0x551291){if(!_0x551291){_0x412a8a[_0x31c6('0x18')](0x194);}return _0x551291;};}function handleError(_0x44bf50,_0x2c9d78){_0x2c9d78=_0x2c9d78||0x1f4;return function(_0x2fb5f3){logger['error'](_0x2fb5f3['stack']);if(_0x2fb5f3['name']){delete _0x2fb5f3['name'];}_0x44bf50[_0x31c6('0x19')](_0x2c9d78)['send'](_0x2fb5f3);};}exports['index']=function(_0x1e24fa,_0x2034cc){var _0x5e3ed0={},_0x41100c={},_0x47a0cd={'count':0x0,'rows':[]};var _0x1d5ab5=_[_0x31c6('0x25')](db['ChatQueueReport'][_0x31c6('0x26')],function(_0x3840de){return{'name':_0x3840de[_0x31c6('0x27')],'type':_0x3840de[_0x31c6('0x28')][_0x31c6('0x29')]};});_0x41100c[_0x31c6('0x2a')]=_['map'](_0x1d5ab5,_0x31c6('0x2b'));_0x41100c[_0x31c6('0x2c')]=_['keys'](_0x1e24fa[_0x31c6('0x2c')]);_0x41100c[_0x31c6('0x2d')]=_['intersection'](_0x41100c['model'],_0x41100c['query']);_0x5e3ed0[_0x31c6('0x2e')]=_[_0x31c6('0x2f')](_0x41100c['model'],qs[_0x31c6('0x30')](_0x1e24fa[_0x31c6('0x2c')][_0x31c6('0x30')]));_0x5e3ed0[_0x31c6('0x2e')]=_0x5e3ed0[_0x31c6('0x2e')]['length']?_0x5e3ed0[_0x31c6('0x2e')]:_0x41100c[_0x31c6('0x2a')];if(!_0x1e24fa[_0x31c6('0x2c')][_0x31c6('0x31')](_0x31c6('0x32'))){_0x5e3ed0[_0x31c6('0x33')]=qs[_0x31c6('0x33')](_0x1e24fa[_0x31c6('0x2c')][_0x31c6('0x33')]);_0x5e3ed0['offset']=qs[_0x31c6('0x1e')](_0x1e24fa[_0x31c6('0x2c')]['offset']);}_0x5e3ed0[_0x31c6('0x34')]=qs[_0x31c6('0x35')](_0x1e24fa['query'][_0x31c6('0x35')]);_0x5e3ed0[_0x31c6('0x36')]=qs[_0x31c6('0x2d')](_['pick'](_0x1e24fa[_0x31c6('0x2c')],_0x41100c['filters']),_0x1d5ab5);if(_0x1e24fa[_0x31c6('0x2c')][_0x31c6('0x37')]){_0x5e3ed0[_0x31c6('0x36')]=_['merge'](_0x5e3ed0[_0x31c6('0x36')],{'$or':_[_0x31c6('0x25')](_0x1d5ab5,function(_0xdf5348){if(_0xdf5348[_0x31c6('0x28')]!=='VIRTUAL'){var _0x506491={};_0x506491[_0xdf5348[_0x31c6('0x2b')]]={'$like':'%'+_0x1e24fa[_0x31c6('0x2c')][_0x31c6('0x37')]+'%'};return _0x506491;}})});}_0x5e3ed0=_[_0x31c6('0x38')]({},_0x5e3ed0,_0x1e24fa[_0x31c6('0x39')]);var _0xeed7d7={'where':_0x5e3ed0[_0x31c6('0x36')]};return db[_0x31c6('0x3a')][_0x31c6('0x1d')](_0xeed7d7)[_0x31c6('0x23')](function(_0x4dba99){_0x47a0cd[_0x31c6('0x1d')]=_0x4dba99;if(_0x1e24fa[_0x31c6('0x2c')]['includeAll']){_0x5e3ed0['include']=[{'all':!![]}];}return db[_0x31c6('0x3a')][_0x31c6('0x3b')](_0x5e3ed0);})[_0x31c6('0x23')](function(_0xd85393){_0x47a0cd[_0x31c6('0x3c')]=_0xd85393;return _0x47a0cd;})[_0x31c6('0x23')](respondWithFilteredResult(_0x2034cc,_0x5e3ed0))['catch'](handleError(_0x2034cc,null));};exports['show']=function(_0x31c919,_0x5195b0){var _0x2c2129={'raw':!![],'where':{'id':_0x31c919['params']['id']}},_0x1f0b73={};_0x1f0b73[_0x31c6('0x2a')]=_[_0x31c6('0x3d')](db[_0x31c6('0x3a')][_0x31c6('0x26')]);_0x1f0b73[_0x31c6('0x2c')]=_[_0x31c6('0x3d')](_0x31c919['query']);_0x1f0b73[_0x31c6('0x2d')]=_[_0x31c6('0x2f')](_0x1f0b73[_0x31c6('0x2a')],_0x1f0b73[_0x31c6('0x2c')]);_0x2c2129[_0x31c6('0x2e')]=_['intersection'](_0x1f0b73[_0x31c6('0x2a')],qs[_0x31c6('0x30')](_0x31c919[_0x31c6('0x2c')][_0x31c6('0x30')]));_0x2c2129['attributes']=_0x2c2129[_0x31c6('0x2e')]['length']?_0x2c2129[_0x31c6('0x2e')]:_0x1f0b73[_0x31c6('0x2a')];if(_0x31c919[_0x31c6('0x2c')][_0x31c6('0x3e')]){_0x2c2129[_0x31c6('0x3f')]=[{'all':!![]}];}_0x2c2129=_['merge']({},_0x2c2129,_0x31c919[_0x31c6('0x39')]);return db[_0x31c6('0x3a')][_0x31c6('0x40')](_0x2c2129)[_0x31c6('0x23')](handleEntityNotFound(_0x5195b0,null))[_0x31c6('0x23')](respondWithResult(_0x5195b0,null))[_0x31c6('0x41')](handleError(_0x5195b0,null));};exports['create']=function(_0x36fc66,_0x52d06d){return db[_0x31c6('0x3a')]['create'](_0x36fc66['body'],{})[_0x31c6('0x23')](respondWithResult(_0x52d06d,0xc9))[_0x31c6('0x41')](handleError(_0x52d06d,null));};exports['update']=function(_0xf33b6c,_0x129197){if(_0xf33b6c[_0x31c6('0x42')]['id']){delete _0xf33b6c['body']['id'];}return db['ChatQueueReport'][_0x31c6('0x40')]({'where':{'id':_0xf33b6c[_0x31c6('0x43')]['id']}})[_0x31c6('0x23')](handleEntityNotFound(_0x129197,null))[_0x31c6('0x23')](saveUpdates(_0xf33b6c[_0x31c6('0x42')],null))[_0x31c6('0x23')](respondWithResult(_0x129197,null))[_0x31c6('0x41')](handleError(_0x129197,null));};exports[_0x31c6('0x24')]=function(_0x21ead7,_0x10f5b1){return db[_0x31c6('0x3a')][_0x31c6('0x40')]({'where':{'id':_0x21ead7['params']['id']}})['then'](handleEntityNotFound(_0x10f5b1,null))['then'](removeEntity(_0x10f5b1,null))[_0x31c6('0x41')](handleError(_0x10f5b1,null));};exports[_0x31c6('0x44')]=function(_0x1b0999,_0x433a63){return db[_0x31c6('0x3a')][_0x31c6('0x44')]()[_0x31c6('0x23')](respondWithResult(_0x433a63,null))['catch'](handleError(_0x433a63,null));};