Built motion from commit 9d7072cc.|2.5.39
[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 _0x4f36=['save','then','destroy','stack','name','send','index','map','VoiceQueueReport','rawAttributes','fieldName','type','key','model','keys','query','fields','attributes','length','hasOwnProperty','limit','order','sort','where','pick','filters','filter','merge','VIRTUAL','options','include','findAll','rows','show','params','intersection','catch','create','update','body','find','describe','nolimit','includeAll','getVoiceQueuesReport','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','fs-extra','lodash','squel','crypto','jsforce','desk.js','to-csv','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','../../config/utils','../../config/environment','../../mysqldb','redis','socket.io-emitter','./voiceQueueReport.socket','register','sendStatus','status','end','json','offset','undefined','count','set','Content-Range','apply'];(function(_0x57b54c,_0x54ce0d){var _0x59cc19=function(_0xa33bc6){while(--_0xa33bc6){_0x57b54c['push'](_0x57b54c['shift']());}};_0x59cc19(++_0x54ce0d);}(_0x4f36,0x12f));var _0x64f3=function(_0x49d19d,_0x245cf5){_0x49d19d=_0x49d19d-0x0;var _0x4ebef1=_0x4f36[_0x49d19d];return _0x4ebef1;};'use strict';var emlformat=require(_0x64f3('0x0'));var rimraf=require(_0x64f3('0x1'));var zipdir=require(_0x64f3('0x2'));var jsonpatch=require(_0x64f3('0x3'));var rp=require(_0x64f3('0x4'));var moment=require(_0x64f3('0x5'));var BPromise=require(_0x64f3('0x6'));var Mustache=require(_0x64f3('0x7'));var util=require(_0x64f3('0x8'));var path=require(_0x64f3('0x9'));var sox=require(_0x64f3('0xa'));var csv=require('to-csv');var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x64f3('0xb'));var _=require(_0x64f3('0xc'));var squel=require(_0x64f3('0xd'));var crypto=require(_0x64f3('0xe'));var jsforce=require(_0x64f3('0xf'));var deskjs=require(_0x64f3('0x10'));var toCsv=require(_0x64f3('0x11'));var querystring=require(_0x64f3('0x12'));var Papa=require(_0x64f3('0x13'));var Redis=require('ioredis');var authService=require(_0x64f3('0x14'));var qs=require(_0x64f3('0x15'));var as=require(_0x64f3('0x16'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x64f3('0x17'))('api');var utils=require(_0x64f3('0x18'));var config=require(_0x64f3('0x19'));var licenseUtil=require('../../config/license/util');var db=require(_0x64f3('0x1a'))['db'];config[_0x64f3('0x1b')]=_['defaults'](config['redis'],{'host':'localhost','port':0x18eb});var socket=require(_0x64f3('0x1c'))(new Redis(config[_0x64f3('0x1b')]));require(_0x64f3('0x1d'))[_0x64f3('0x1e')](socket);function respondWithStatusCode(_0x1c4f67,_0x3e5c0c){_0x3e5c0c=_0x3e5c0c||0xcc;return function(_0x12869a){if(_0x12869a){return _0x1c4f67[_0x64f3('0x1f')](_0x3e5c0c);}return _0x1c4f67[_0x64f3('0x20')](_0x3e5c0c)[_0x64f3('0x21')]();};}function respondWithResult(_0x8fda88,_0x10fb9d){_0x10fb9d=_0x10fb9d||0xc8;return function(_0x525c7f){if(_0x525c7f){return _0x8fda88[_0x64f3('0x20')](_0x10fb9d)[_0x64f3('0x22')](_0x525c7f);}};}function respondWithFilteredResult(_0x64fd30,_0x120d17){return function(_0x3bdcb7){if(_0x3bdcb7){var _0x44c351=typeof _0x120d17[_0x64f3('0x23')]===_0x64f3('0x24')&&typeof _0x120d17['limit']==='undefined';var _0x2b7be9=_0x3bdcb7[_0x64f3('0x25')];var _0x3d1cab=_0x44c351?0x0:_0x120d17[_0x64f3('0x23')];var _0x347407=_0x44c351?_0x3bdcb7[_0x64f3('0x25')]:_0x120d17[_0x64f3('0x23')]+_0x120d17['limit'];var _0x3fb7f2;if(_0x347407>=_0x2b7be9){_0x347407=_0x2b7be9;_0x3fb7f2=0xc8;}else{_0x3fb7f2=0xce;}_0x64fd30[_0x64f3('0x20')](_0x3fb7f2);return _0x64fd30[_0x64f3('0x26')](_0x64f3('0x27'),_0x3d1cab+'-'+_0x347407+'/'+_0x2b7be9)[_0x64f3('0x22')](_0x3bdcb7);}return null;};}function patchUpdates(_0x33f678){return function(_0x47ed26){try{jsonpatch[_0x64f3('0x28')](_0x47ed26,_0x33f678,!![]);}catch(_0x52209f){return BPromise['reject'](_0x52209f);}return _0x47ed26[_0x64f3('0x29')]();};}function saveUpdates(_0x45948b,_0x16008d){return function(_0x412b5d){if(_0x412b5d){return _0x412b5d['update'](_0x45948b)[_0x64f3('0x2a')](function(_0x491b3f){return _0x491b3f;});}return null;};}function removeEntity(_0x224d46,_0x1c944d){return function(_0x6fd82){if(_0x6fd82){return _0x6fd82[_0x64f3('0x2b')]()['then'](function(){_0x224d46[_0x64f3('0x20')](0xcc)[_0x64f3('0x21')]();});}};}function handleEntityNotFound(_0x43881d,_0x5814e4){return function(_0x243de5){if(!_0x243de5){_0x43881d[_0x64f3('0x1f')](0x194);}return _0x243de5;};}function handleError(_0x1bdf6c,_0x365e15){_0x365e15=_0x365e15||0x1f4;return function(_0x5acbf7){logger['error'](_0x5acbf7[_0x64f3('0x2c')]);if(_0x5acbf7['name']){delete _0x5acbf7[_0x64f3('0x2d')];}_0x1bdf6c[_0x64f3('0x20')](_0x365e15)[_0x64f3('0x2e')](_0x5acbf7);};}exports[_0x64f3('0x2f')]=function(_0x2eee89,_0x709b7f){var _0x1f7b37={},_0x20b061={},_0x295488={'count':0x0,'rows':[]};var _0x20cbbd=_[_0x64f3('0x30')](db[_0x64f3('0x31')][_0x64f3('0x32')],function(_0x5b126d){return{'name':_0x5b126d[_0x64f3('0x33')],'type':_0x5b126d[_0x64f3('0x34')][_0x64f3('0x35')]};});_0x20b061[_0x64f3('0x36')]=_[_0x64f3('0x30')](_0x20cbbd,_0x64f3('0x2d'));_0x20b061['query']=_[_0x64f3('0x37')](_0x2eee89[_0x64f3('0x38')]);_0x20b061['filters']=_['intersection'](_0x20b061[_0x64f3('0x36')],_0x20b061[_0x64f3('0x38')]);_0x1f7b37['attributes']=_['intersection'](_0x20b061['model'],qs[_0x64f3('0x39')](_0x2eee89[_0x64f3('0x38')]['fields']));_0x1f7b37[_0x64f3('0x3a')]=_0x1f7b37[_0x64f3('0x3a')][_0x64f3('0x3b')]?_0x1f7b37[_0x64f3('0x3a')]:_0x20b061[_0x64f3('0x36')];if(!_0x2eee89[_0x64f3('0x38')][_0x64f3('0x3c')]('nolimit')){_0x1f7b37['limit']=qs[_0x64f3('0x3d')](_0x2eee89[_0x64f3('0x38')][_0x64f3('0x3d')]);_0x1f7b37['offset']=qs[_0x64f3('0x23')](_0x2eee89[_0x64f3('0x38')][_0x64f3('0x23')]);}_0x1f7b37[_0x64f3('0x3e')]=qs[_0x64f3('0x3f')](_0x2eee89[_0x64f3('0x38')][_0x64f3('0x3f')]);_0x1f7b37[_0x64f3('0x40')]=qs['filters'](_[_0x64f3('0x41')](_0x2eee89[_0x64f3('0x38')],_0x20b061[_0x64f3('0x42')]),_0x20cbbd);if(_0x2eee89[_0x64f3('0x38')][_0x64f3('0x43')]){_0x1f7b37[_0x64f3('0x40')]=_[_0x64f3('0x44')](_0x1f7b37[_0x64f3('0x40')],{'$or':_[_0x64f3('0x30')](_0x20cbbd,function(_0x4e92a8){if(_0x4e92a8['type']!==_0x64f3('0x45')){var _0x13da29={};_0x13da29[_0x4e92a8[_0x64f3('0x2d')]]={'$like':'%'+_0x2eee89[_0x64f3('0x38')][_0x64f3('0x43')]+'%'};return _0x13da29;}})});}_0x1f7b37=_[_0x64f3('0x44')]({},_0x1f7b37,_0x2eee89[_0x64f3('0x46')]);var _0x593151={'where':_0x1f7b37[_0x64f3('0x40')]};return db[_0x64f3('0x31')][_0x64f3('0x25')](_0x593151)[_0x64f3('0x2a')](function(_0x9ba3f2){_0x295488['count']=_0x9ba3f2;if(_0x2eee89[_0x64f3('0x38')]['includeAll']){_0x1f7b37[_0x64f3('0x47')]=[{'all':!![]}];}return db[_0x64f3('0x31')][_0x64f3('0x48')](_0x1f7b37);})[_0x64f3('0x2a')](function(_0x170f77){_0x295488[_0x64f3('0x49')]=_0x170f77;return _0x295488;})[_0x64f3('0x2a')](respondWithFilteredResult(_0x709b7f,_0x1f7b37))['catch'](handleError(_0x709b7f,null));};exports[_0x64f3('0x4a')]=function(_0x1ecceb,_0x308c01){var _0x3841c5={'raw':![],'where':{'id':_0x1ecceb[_0x64f3('0x4b')]['id']}},_0x43f1fc={};_0x43f1fc[_0x64f3('0x36')]=_[_0x64f3('0x37')](db['VoiceQueueReport'][_0x64f3('0x32')]);_0x43f1fc[_0x64f3('0x38')]=_['keys'](_0x1ecceb[_0x64f3('0x38')]);_0x43f1fc['filters']=_[_0x64f3('0x4c')](_0x43f1fc[_0x64f3('0x36')],_0x43f1fc['query']);_0x3841c5[_0x64f3('0x3a')]=_[_0x64f3('0x4c')](_0x43f1fc['model'],qs[_0x64f3('0x39')](_0x1ecceb[_0x64f3('0x38')][_0x64f3('0x39')]));_0x3841c5[_0x64f3('0x3a')]=_0x3841c5[_0x64f3('0x3a')][_0x64f3('0x3b')]?_0x3841c5[_0x64f3('0x3a')]:_0x43f1fc[_0x64f3('0x36')];if(_0x1ecceb[_0x64f3('0x38')]['includeAll']){_0x3841c5[_0x64f3('0x47')]=[{'all':!![]}];}_0x3841c5=_['merge']({},_0x3841c5,_0x1ecceb[_0x64f3('0x46')]);return db[_0x64f3('0x31')]['find'](_0x3841c5)[_0x64f3('0x2a')](handleEntityNotFound(_0x308c01,null))[_0x64f3('0x2a')](respondWithResult(_0x308c01,null))[_0x64f3('0x4d')](handleError(_0x308c01,null));};exports[_0x64f3('0x4e')]=function(_0x13263c,_0x4de11f){return db[_0x64f3('0x31')][_0x64f3('0x4e')](_0x13263c['body'],{})[_0x64f3('0x2a')](respondWithResult(_0x4de11f,0xc9))[_0x64f3('0x4d')](handleError(_0x4de11f,null));};exports[_0x64f3('0x4f')]=function(_0x277d3f,_0x1a32fa){if(_0x277d3f[_0x64f3('0x50')]['id']){delete _0x277d3f['body']['id'];}return db[_0x64f3('0x31')][_0x64f3('0x51')]({'where':{'id':_0x277d3f['params']['id']}})[_0x64f3('0x2a')](handleEntityNotFound(_0x1a32fa,null))[_0x64f3('0x2a')](saveUpdates(_0x277d3f[_0x64f3('0x50')],null))[_0x64f3('0x2a')](respondWithResult(_0x1a32fa,null))[_0x64f3('0x4d')](handleError(_0x1a32fa,null));};exports['destroy']=function(_0x417269,_0x4e6189){return db[_0x64f3('0x31')]['find']({'where':{'id':_0x417269[_0x64f3('0x4b')]['id']}})[_0x64f3('0x2a')](handleEntityNotFound(_0x4e6189,null))[_0x64f3('0x2a')](removeEntity(_0x4e6189,null))[_0x64f3('0x4d')](handleError(_0x4e6189,null));};exports[_0x64f3('0x52')]=function(_0x4dd017,_0xcee53c){return db['VoiceQueueReport'][_0x64f3('0x52')]()[_0x64f3('0x2a')](respondWithResult(_0xcee53c,null))['catch'](handleError(_0xcee53c,null));};exports['getVoiceQueuesReport']=function(_0x5e2eee,_0x2f2038){var _0x12aafe={},_0x5303d1={},_0x3da942={'count':0x0,'rows':[]};_0x5303d1['model']=_[_0x64f3('0x37')](db['VoiceQueueReport'][_0x64f3('0x32')]);_0x5303d1[_0x64f3('0x38')]=_[_0x64f3('0x37')](_0x5e2eee['query']);_0x5303d1[_0x64f3('0x42')]=_['intersection'](_0x5303d1[_0x64f3('0x36')],_0x5303d1[_0x64f3('0x38')]);_0x12aafe[_0x64f3('0x3a')]=_[_0x64f3('0x4c')](_0x5303d1['model'],qs[_0x64f3('0x39')](_0x5e2eee[_0x64f3('0x38')]['fields']));_0x12aafe[_0x64f3('0x3a')]=_0x12aafe[_0x64f3('0x3a')][_0x64f3('0x3b')]?_0x12aafe[_0x64f3('0x3a')]:_0x5303d1[_0x64f3('0x36')];if(!_0x5e2eee[_0x64f3('0x38')][_0x64f3('0x3c')](_0x64f3('0x53'))){_0x12aafe[_0x64f3('0x3d')]=qs[_0x64f3('0x3d')](_0x5e2eee['query'][_0x64f3('0x3d')]);_0x12aafe[_0x64f3('0x23')]=qs[_0x64f3('0x23')](_0x5e2eee[_0x64f3('0x38')]['offset']);}_0x12aafe[_0x64f3('0x3e')]=qs[_0x64f3('0x3f')](_0x5e2eee['query'][_0x64f3('0x3f')]);_0x12aafe[_0x64f3('0x40')]=qs[_0x64f3('0x42')](_[_0x64f3('0x41')](_0x5e2eee['query'],_0x5303d1[_0x64f3('0x42')]));if(_0x5e2eee[_0x64f3('0x38')][_0x64f3('0x43')]){_0x12aafe[_0x64f3('0x40')]=_[_0x64f3('0x44')](_0x12aafe[_0x64f3('0x40')],{'$or':_['map'](_0x12aafe[_0x64f3('0x3a')],function(_0x3fc110){var _0x38c394={};_0x38c394[_0x3fc110]={'$like':'%'+_0x5e2eee[_0x64f3('0x38')][_0x64f3('0x43')]+'%'};return _0x38c394;})});}_0x12aafe=_[_0x64f3('0x44')]({},_0x12aafe,_0x5e2eee[_0x64f3('0x46')]);var _0x25d123={'where':_0x12aafe[_0x64f3('0x40')]};return db['VoiceQueueReport'][_0x64f3('0x25')](_0x25d123)[_0x64f3('0x2a')](function(_0x5592e7){_0x3da942[_0x64f3('0x25')]=_0x5592e7;if(_0x5e2eee['query'][_0x64f3('0x54')]){_0x12aafe[_0x64f3('0x47')]=[{'all':!![]}];}return db[_0x64f3('0x31')]['findAll'](_0x12aafe);})[_0x64f3('0x2a')](function(_0xc7279c){_0x3da942[_0x64f3('0x49')]=_0xc7279c;return _0x3da942;})[_0x64f3('0x2a')](respondWithFilteredResult(_0x2f2038,_0x12aafe,_0x64f3('0x55')))[_0x64f3('0x4d')](handleError(_0x2f2038,null,_0x64f3('0x55')));};