Built motion from commit 85328c08.|2.5.50
[motion2.git] / server / api / voiceQueueReport / voiceQueueReport.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 _0x9b25=['sox','to-csv','ejs','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','redis','defaults','localhost','socket.io-emitter','register','sendStatus','end','status','offset','undefined','count','limit','set','Content-Range','json','apply','reject','save','then','error','stack','name','send','index','map','VoiceQueueReport','rawAttributes','type','model','query','keys','intersection','attributes','fields','length','hasOwnProperty','nolimit','sort','where','pick','filters','filter','merge','options','includeAll','findAll','catch','show','params','include','find','create','body','update','destroy','describe','getVoiceQueuesReport','order','rows','eml-format','zip-dir','fast-json-patch','moment','bluebird','mustache','util'];(function(_0x830994,_0x4e0a64){var _0x52a8b=function(_0x415c2c){while(--_0x415c2c){_0x830994['push'](_0x830994['shift']());}};_0x52a8b(++_0x4e0a64);}(_0x9b25,0x1f1));var _0x59b2=function(_0x1df64e,_0x16aace){_0x1df64e=_0x1df64e-0x0;var _0x4459de=_0x9b25[_0x1df64e];return _0x4459de;};'use strict';var emlformat=require(_0x59b2('0x0'));var rimraf=require('rimraf');var zipdir=require(_0x59b2('0x1'));var jsonpatch=require(_0x59b2('0x2'));var rp=require('request-promise');var moment=require(_0x59b2('0x3'));var BPromise=require(_0x59b2('0x4'));var Mustache=require(_0x59b2('0x5'));var util=require(_0x59b2('0x6'));var path=require('path');var sox=require(_0x59b2('0x7'));var csv=require(_0x59b2('0x8'));var ejs=require(_0x59b2('0x9'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0x59b2('0xa'));var squel=require(_0x59b2('0xb'));var crypto=require(_0x59b2('0xc'));var jsforce=require(_0x59b2('0xd'));var deskjs=require(_0x59b2('0xe'));var toCsv=require(_0x59b2('0x8'));var querystring=require(_0x59b2('0xf'));var Papa=require(_0x59b2('0x10'));var Redis=require('ioredis');var authService=require(_0x59b2('0x11'));var qs=require(_0x59b2('0x12'));var as=require(_0x59b2('0x13'));var hardwareService=require(_0x59b2('0x14'));var logger=require(_0x59b2('0x15'))('api');var utils=require(_0x59b2('0x16'));var config=require(_0x59b2('0x17'));var licenseUtil=require(_0x59b2('0x18'));var db=require('../../mysqldb')['db'];config[_0x59b2('0x19')]=_[_0x59b2('0x1a')](config[_0x59b2('0x19')],{'host':_0x59b2('0x1b'),'port':0x18eb});var socket=require(_0x59b2('0x1c'))(new Redis(config['redis']));require('./voiceQueueReport.socket')[_0x59b2('0x1d')](socket);function respondWithStatusCode(_0x2c717d,_0x3552ee){_0x3552ee=_0x3552ee||0xcc;return function(_0x447096){if(_0x447096){return _0x2c717d[_0x59b2('0x1e')](_0x3552ee);}return _0x2c717d['status'](_0x3552ee)[_0x59b2('0x1f')]();};}function respondWithResult(_0x5339e7,_0x578d38){_0x578d38=_0x578d38||0xc8;return function(_0xf4a873){if(_0xf4a873){return _0x5339e7[_0x59b2('0x20')](_0x578d38)['json'](_0xf4a873);}};}function respondWithFilteredResult(_0x52e66d,_0x440984){return function(_0x394167){if(_0x394167){var _0x5cf3e9=typeof _0x440984[_0x59b2('0x21')]==='undefined'&&typeof _0x440984['limit']===_0x59b2('0x22');var _0x4bd85b=_0x394167['count'];var _0x191c87=_0x5cf3e9?0x0:_0x440984[_0x59b2('0x21')];var _0x2805e9=_0x5cf3e9?_0x394167[_0x59b2('0x23')]:_0x440984[_0x59b2('0x21')]+_0x440984[_0x59b2('0x24')];var _0x30b76c;if(_0x2805e9>=_0x4bd85b){_0x2805e9=_0x4bd85b;_0x30b76c=0xc8;}else{_0x30b76c=0xce;}_0x52e66d[_0x59b2('0x20')](_0x30b76c);return _0x52e66d[_0x59b2('0x25')](_0x59b2('0x26'),_0x191c87+'-'+_0x2805e9+'/'+_0x4bd85b)[_0x59b2('0x27')](_0x394167);}return null;};}function patchUpdates(_0x23f1be){return function(_0x411eae){try{jsonpatch[_0x59b2('0x28')](_0x411eae,_0x23f1be,!![]);}catch(_0x106f55){return BPromise[_0x59b2('0x29')](_0x106f55);}return _0x411eae[_0x59b2('0x2a')]();};}function saveUpdates(_0x4f014a,_0x1c9b61){return function(_0x148386){if(_0x148386){return _0x148386['update'](_0x4f014a)['then'](function(_0x4aa7b5){return _0x4aa7b5;});}return null;};}function removeEntity(_0x1bfc11,_0x50d820){return function(_0x19a997){if(_0x19a997){return _0x19a997['destroy']()[_0x59b2('0x2b')](function(){_0x1bfc11['status'](0xcc)[_0x59b2('0x1f')]();});}};}function handleEntityNotFound(_0x252a86,_0x48f0ae){return function(_0x61456c){if(!_0x61456c){_0x252a86[_0x59b2('0x1e')](0x194);}return _0x61456c;};}function handleError(_0xfc43b9,_0x2cfe13){_0x2cfe13=_0x2cfe13||0x1f4;return function(_0x2c865c){logger[_0x59b2('0x2c')](_0x2c865c[_0x59b2('0x2d')]);if(_0x2c865c[_0x59b2('0x2e')]){delete _0x2c865c[_0x59b2('0x2e')];}_0xfc43b9[_0x59b2('0x20')](_0x2cfe13)[_0x59b2('0x2f')](_0x2c865c);};}exports[_0x59b2('0x30')]=function(_0x4900ee,_0x50d883){var _0x5f19f3={},_0x30e9b4={},_0x490909={'count':0x0,'rows':[]};var _0x403560=_[_0x59b2('0x31')](db[_0x59b2('0x32')][_0x59b2('0x33')],function(_0xef279f){return{'name':_0xef279f['fieldName'],'type':_0xef279f[_0x59b2('0x34')]['key']};});_0x30e9b4[_0x59b2('0x35')]=_[_0x59b2('0x31')](_0x403560,_0x59b2('0x2e'));_0x30e9b4[_0x59b2('0x36')]=_[_0x59b2('0x37')](_0x4900ee[_0x59b2('0x36')]);_0x30e9b4['filters']=_[_0x59b2('0x38')](_0x30e9b4[_0x59b2('0x35')],_0x30e9b4[_0x59b2('0x36')]);_0x5f19f3[_0x59b2('0x39')]=_[_0x59b2('0x38')](_0x30e9b4['model'],qs[_0x59b2('0x3a')](_0x4900ee[_0x59b2('0x36')]['fields']));_0x5f19f3[_0x59b2('0x39')]=_0x5f19f3[_0x59b2('0x39')][_0x59b2('0x3b')]?_0x5f19f3[_0x59b2('0x39')]:_0x30e9b4['model'];if(!_0x4900ee[_0x59b2('0x36')][_0x59b2('0x3c')](_0x59b2('0x3d'))){_0x5f19f3[_0x59b2('0x24')]=qs[_0x59b2('0x24')](_0x4900ee[_0x59b2('0x36')][_0x59b2('0x24')]);_0x5f19f3[_0x59b2('0x21')]=qs[_0x59b2('0x21')](_0x4900ee['query'][_0x59b2('0x21')]);}_0x5f19f3['order']=qs[_0x59b2('0x3e')](_0x4900ee[_0x59b2('0x36')][_0x59b2('0x3e')]);_0x5f19f3[_0x59b2('0x3f')]=qs['filters'](_[_0x59b2('0x40')](_0x4900ee[_0x59b2('0x36')],_0x30e9b4[_0x59b2('0x41')]),_0x403560);if(_0x4900ee[_0x59b2('0x36')][_0x59b2('0x42')]){_0x5f19f3['where']=_[_0x59b2('0x43')](_0x5f19f3[_0x59b2('0x3f')],{'$or':_['map'](_0x403560,function(_0x54a15f){if(_0x54a15f[_0x59b2('0x34')]!=='VIRTUAL'){var _0x25ff6a={};_0x25ff6a[_0x54a15f['name']]={'$like':'%'+_0x4900ee[_0x59b2('0x36')]['filter']+'%'};return _0x25ff6a;}})});}_0x5f19f3=_[_0x59b2('0x43')]({},_0x5f19f3,_0x4900ee[_0x59b2('0x44')]);var _0x18e5a6={'where':_0x5f19f3[_0x59b2('0x3f')]};return db[_0x59b2('0x32')]['count'](_0x18e5a6)[_0x59b2('0x2b')](function(_0x48dc3a){_0x490909['count']=_0x48dc3a;if(_0x4900ee[_0x59b2('0x36')][_0x59b2('0x45')]){_0x5f19f3['include']=[{'all':!![]}];}return db[_0x59b2('0x32')][_0x59b2('0x46')](_0x5f19f3);})[_0x59b2('0x2b')](function(_0x56b78b){_0x490909['rows']=_0x56b78b;return _0x490909;})[_0x59b2('0x2b')](respondWithFilteredResult(_0x50d883,_0x5f19f3))[_0x59b2('0x47')](handleError(_0x50d883,null));};exports[_0x59b2('0x48')]=function(_0x31ef7a,_0x241b49){var _0x3c590c={'raw':![],'where':{'id':_0x31ef7a[_0x59b2('0x49')]['id']}},_0x3f5e52={};_0x3f5e52['model']=_[_0x59b2('0x37')](db[_0x59b2('0x32')][_0x59b2('0x33')]);_0x3f5e52[_0x59b2('0x36')]=_[_0x59b2('0x37')](_0x31ef7a[_0x59b2('0x36')]);_0x3f5e52[_0x59b2('0x41')]=_['intersection'](_0x3f5e52['model'],_0x3f5e52['query']);_0x3c590c['attributes']=_[_0x59b2('0x38')](_0x3f5e52[_0x59b2('0x35')],qs[_0x59b2('0x3a')](_0x31ef7a[_0x59b2('0x36')][_0x59b2('0x3a')]));_0x3c590c['attributes']=_0x3c590c['attributes'][_0x59b2('0x3b')]?_0x3c590c['attributes']:_0x3f5e52[_0x59b2('0x35')];if(_0x31ef7a[_0x59b2('0x36')][_0x59b2('0x45')]){_0x3c590c[_0x59b2('0x4a')]=[{'all':!![]}];}_0x3c590c=_[_0x59b2('0x43')]({},_0x3c590c,_0x31ef7a[_0x59b2('0x44')]);return db[_0x59b2('0x32')][_0x59b2('0x4b')](_0x3c590c)[_0x59b2('0x2b')](handleEntityNotFound(_0x241b49,null))[_0x59b2('0x2b')](respondWithResult(_0x241b49,null))[_0x59b2('0x47')](handleError(_0x241b49,null));};exports[_0x59b2('0x4c')]=function(_0x3f3318,_0x21d0a6){return db[_0x59b2('0x32')][_0x59b2('0x4c')](_0x3f3318[_0x59b2('0x4d')],{})[_0x59b2('0x2b')](respondWithResult(_0x21d0a6,0xc9))['catch'](handleError(_0x21d0a6,null));};exports[_0x59b2('0x4e')]=function(_0x2d0b82,_0x3ede9a){if(_0x2d0b82[_0x59b2('0x4d')]['id']){delete _0x2d0b82[_0x59b2('0x4d')]['id'];}return db[_0x59b2('0x32')][_0x59b2('0x4b')]({'where':{'id':_0x2d0b82['params']['id']}})[_0x59b2('0x2b')](handleEntityNotFound(_0x3ede9a,null))[_0x59b2('0x2b')](saveUpdates(_0x2d0b82[_0x59b2('0x4d')],null))[_0x59b2('0x2b')](respondWithResult(_0x3ede9a,null))[_0x59b2('0x47')](handleError(_0x3ede9a,null));};exports[_0x59b2('0x4f')]=function(_0x26a882,_0x50f3ae){return db[_0x59b2('0x32')]['find']({'where':{'id':_0x26a882[_0x59b2('0x49')]['id']}})[_0x59b2('0x2b')](handleEntityNotFound(_0x50f3ae,null))[_0x59b2('0x2b')](removeEntity(_0x50f3ae,null))[_0x59b2('0x47')](handleError(_0x50f3ae,null));};exports['describe']=function(_0x5baac7,_0x2876fd){return db[_0x59b2('0x32')][_0x59b2('0x50')]()[_0x59b2('0x2b')](respondWithResult(_0x2876fd,null))['catch'](handleError(_0x2876fd,null));};exports[_0x59b2('0x51')]=function(_0x427810,_0x27a40d){var _0x237692={},_0x9e063d={},_0x220720={'count':0x0,'rows':[]};_0x9e063d[_0x59b2('0x35')]=_[_0x59b2('0x37')](db[_0x59b2('0x32')][_0x59b2('0x33')]);_0x9e063d[_0x59b2('0x36')]=_[_0x59b2('0x37')](_0x427810[_0x59b2('0x36')]);_0x9e063d['filters']=_['intersection'](_0x9e063d['model'],_0x9e063d[_0x59b2('0x36')]);_0x237692['attributes']=_[_0x59b2('0x38')](_0x9e063d[_0x59b2('0x35')],qs[_0x59b2('0x3a')](_0x427810[_0x59b2('0x36')]['fields']));_0x237692[_0x59b2('0x39')]=_0x237692['attributes'][_0x59b2('0x3b')]?_0x237692['attributes']:_0x9e063d[_0x59b2('0x35')];if(!_0x427810[_0x59b2('0x36')][_0x59b2('0x3c')]('nolimit')){_0x237692[_0x59b2('0x24')]=qs['limit'](_0x427810['query'][_0x59b2('0x24')]);_0x237692[_0x59b2('0x21')]=qs['offset'](_0x427810[_0x59b2('0x36')][_0x59b2('0x21')]);}_0x237692[_0x59b2('0x52')]=qs[_0x59b2('0x3e')](_0x427810['query'][_0x59b2('0x3e')]);_0x237692[_0x59b2('0x3f')]=qs[_0x59b2('0x41')](_[_0x59b2('0x40')](_0x427810[_0x59b2('0x36')],_0x9e063d['filters']));if(_0x427810[_0x59b2('0x36')][_0x59b2('0x42')]){_0x237692[_0x59b2('0x3f')]=_[_0x59b2('0x43')](_0x237692[_0x59b2('0x3f')],{'$or':_[_0x59b2('0x31')](_0x237692['attributes'],function(_0x5b6096){var _0x27ede2={};_0x27ede2[_0x5b6096]={'$like':'%'+_0x427810['query'][_0x59b2('0x42')]+'%'};return _0x27ede2;})});}_0x237692=_[_0x59b2('0x43')]({},_0x237692,_0x427810[_0x59b2('0x44')]);var _0x4e7041={'where':_0x237692[_0x59b2('0x3f')]};return db[_0x59b2('0x32')][_0x59b2('0x23')](_0x4e7041)[_0x59b2('0x2b')](function(_0x351ec1){_0x220720[_0x59b2('0x23')]=_0x351ec1;if(_0x427810[_0x59b2('0x36')][_0x59b2('0x45')]){_0x237692[_0x59b2('0x4a')]=[{'all':!![]}];}return db[_0x59b2('0x32')][_0x59b2('0x46')](_0x237692);})[_0x59b2('0x2b')](function(_0x31d974){_0x220720[_0x59b2('0x53')]=_0x31d974;return _0x220720;})[_0x59b2('0x2b')](respondWithFilteredResult(_0x27a40d,_0x237692,_0x59b2('0x51')))['catch'](handleError(_0x27a40d,null,_0x59b2('0x51')));};