Built motion from commit 449495f6.|2.6.27
[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 _0x4bc7=['../../config/license/util','redis','defaults','localhost','socket.io-emitter','./voiceQueueReport.socket','sendStatus','status','end','json','offset','undefined','limit','count','set','Content-Range','reject','save','update','then','destroy','stack','name','send','index','VoiceQueueReport','fieldName','type','key','model','query','intersection','fields','attributes','length','nolimit','order','sort','filters','pick','filter','where','merge','VIRTUAL','options','includeAll','include','findAll','rows','catch','show','params','keys','find','create','body','describe','getVoiceQueuesReport','hasOwnProperty','map','eml-format','rimraf','fast-json-patch','request-promise','bluebird','mustache','util','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','api','../../config/environment'];(function(_0x417af4,_0xa1ccb7){var _0x26026b=function(_0x3ebe92){while(--_0x3ebe92){_0x417af4['push'](_0x417af4['shift']());}};_0x26026b(++_0xa1ccb7);}(_0x4bc7,0xde));var _0x74bc=function(_0x404eff,_0x4ef653){_0x404eff=_0x404eff-0x0;var _0x46cc25=_0x4bc7[_0x404eff];return _0x46cc25;};'use strict';var emlformat=require(_0x74bc('0x0'));var rimraf=require(_0x74bc('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0x74bc('0x2'));var rp=require(_0x74bc('0x3'));var moment=require('moment');var BPromise=require(_0x74bc('0x4'));var Mustache=require(_0x74bc('0x5'));var util=require(_0x74bc('0x6'));var path=require('path');var sox=require('sox');var csv=require(_0x74bc('0x7'));var ejs=require(_0x74bc('0x8'));var fs=require('fs');var fs_extra=require(_0x74bc('0x9'));var _=require(_0x74bc('0xa'));var squel=require(_0x74bc('0xb'));var crypto=require(_0x74bc('0xc'));var jsforce=require(_0x74bc('0xd'));var deskjs=require('desk.js');var toCsv=require(_0x74bc('0x7'));var querystring=require('querystring');var Papa=require(_0x74bc('0xe'));var Redis=require(_0x74bc('0xf'));var authService=require(_0x74bc('0x10'));var qs=require(_0x74bc('0x11'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x74bc('0x12'));var logger=require('../../config/logger')(_0x74bc('0x13'));var utils=require('../../config/utils');var config=require(_0x74bc('0x14'));var licenseUtil=require(_0x74bc('0x15'));var db=require('../../mysqldb')['db'];config[_0x74bc('0x16')]=_[_0x74bc('0x17')](config[_0x74bc('0x16')],{'host':_0x74bc('0x18'),'port':0x18eb});var socket=require(_0x74bc('0x19'))(new Redis(config[_0x74bc('0x16')]));require(_0x74bc('0x1a'))['register'](socket);function respondWithStatusCode(_0x27d64f,_0x35071a){_0x35071a=_0x35071a||0xcc;return function(_0x368c7c){if(_0x368c7c){return _0x27d64f[_0x74bc('0x1b')](_0x35071a);}return _0x27d64f[_0x74bc('0x1c')](_0x35071a)[_0x74bc('0x1d')]();};}function respondWithResult(_0x2990bd,_0x2d2243){_0x2d2243=_0x2d2243||0xc8;return function(_0x5241e3){if(_0x5241e3){return _0x2990bd[_0x74bc('0x1c')](_0x2d2243)[_0x74bc('0x1e')](_0x5241e3);}};}function respondWithFilteredResult(_0xc3c96d,_0x36f24a){return function(_0x45d6c6){if(_0x45d6c6){var _0x5f31a6=typeof _0x36f24a[_0x74bc('0x1f')]===_0x74bc('0x20')&&typeof _0x36f24a[_0x74bc('0x21')]==='undefined';var _0x7bc090=_0x45d6c6[_0x74bc('0x22')];var _0x1932f0=_0x5f31a6?0x0:_0x36f24a[_0x74bc('0x1f')];var _0x46a9e9=_0x5f31a6?_0x45d6c6[_0x74bc('0x22')]:_0x36f24a['offset']+_0x36f24a[_0x74bc('0x21')];var _0x4aeaf0;if(_0x46a9e9>=_0x7bc090){_0x46a9e9=_0x7bc090;_0x4aeaf0=0xc8;}else{_0x4aeaf0=0xce;}_0xc3c96d[_0x74bc('0x1c')](_0x4aeaf0);return _0xc3c96d[_0x74bc('0x23')](_0x74bc('0x24'),_0x1932f0+'-'+_0x46a9e9+'/'+_0x7bc090)['json'](_0x45d6c6);}return null;};}function patchUpdates(_0x1662b7){return function(_0x38a85a){try{jsonpatch['apply'](_0x38a85a,_0x1662b7,!![]);}catch(_0x295574){return BPromise[_0x74bc('0x25')](_0x295574);}return _0x38a85a[_0x74bc('0x26')]();};}function saveUpdates(_0x38e4d2,_0x4ada81){return function(_0x2fdc95){if(_0x2fdc95){return _0x2fdc95[_0x74bc('0x27')](_0x38e4d2)[_0x74bc('0x28')](function(_0x5d3877){return _0x5d3877;});}return null;};}function removeEntity(_0x15d883,_0x3f59b7){return function(_0x123369){if(_0x123369){return _0x123369[_0x74bc('0x29')]()['then'](function(){_0x15d883[_0x74bc('0x1c')](0xcc)['end']();});}};}function handleEntityNotFound(_0x378778,_0x722905){return function(_0x52bfcb){if(!_0x52bfcb){_0x378778[_0x74bc('0x1b')](0x194);}return _0x52bfcb;};}function handleError(_0x540f50,_0x5dcfc6){_0x5dcfc6=_0x5dcfc6||0x1f4;return function(_0x223876){logger['error'](_0x223876[_0x74bc('0x2a')]);if(_0x223876[_0x74bc('0x2b')]){delete _0x223876[_0x74bc('0x2b')];}_0x540f50[_0x74bc('0x1c')](_0x5dcfc6)[_0x74bc('0x2c')](_0x223876);};}exports[_0x74bc('0x2d')]=function(_0x4cdc73,_0x12fcb3){var _0x404571={},_0x2f7d67={},_0x23f32d={'count':0x0,'rows':[]};var _0x3b3d76=_['map'](db[_0x74bc('0x2e')]['rawAttributes'],function(_0x4c65be){return{'name':_0x4c65be[_0x74bc('0x2f')],'type':_0x4c65be[_0x74bc('0x30')][_0x74bc('0x31')]};});_0x2f7d67[_0x74bc('0x32')]=_['map'](_0x3b3d76,_0x74bc('0x2b'));_0x2f7d67[_0x74bc('0x33')]=_['keys'](_0x4cdc73[_0x74bc('0x33')]);_0x2f7d67['filters']=_[_0x74bc('0x34')](_0x2f7d67[_0x74bc('0x32')],_0x2f7d67[_0x74bc('0x33')]);_0x404571['attributes']=_[_0x74bc('0x34')](_0x2f7d67['model'],qs['fields'](_0x4cdc73[_0x74bc('0x33')][_0x74bc('0x35')]));_0x404571[_0x74bc('0x36')]=_0x404571['attributes'][_0x74bc('0x37')]?_0x404571[_0x74bc('0x36')]:_0x2f7d67['model'];if(!_0x4cdc73[_0x74bc('0x33')]['hasOwnProperty'](_0x74bc('0x38'))){_0x404571[_0x74bc('0x21')]=qs[_0x74bc('0x21')](_0x4cdc73[_0x74bc('0x33')][_0x74bc('0x21')]);_0x404571['offset']=qs[_0x74bc('0x1f')](_0x4cdc73[_0x74bc('0x33')][_0x74bc('0x1f')]);}_0x404571[_0x74bc('0x39')]=qs['sort'](_0x4cdc73['query'][_0x74bc('0x3a')]);_0x404571['where']=qs[_0x74bc('0x3b')](_[_0x74bc('0x3c')](_0x4cdc73[_0x74bc('0x33')],_0x2f7d67[_0x74bc('0x3b')]),_0x3b3d76);if(_0x4cdc73[_0x74bc('0x33')][_0x74bc('0x3d')]){_0x404571[_0x74bc('0x3e')]=_[_0x74bc('0x3f')](_0x404571[_0x74bc('0x3e')],{'$or':_['map'](_0x3b3d76,function(_0xb9ae81){if(_0xb9ae81[_0x74bc('0x30')]!==_0x74bc('0x40')){var _0x1ca24e={};_0x1ca24e[_0xb9ae81[_0x74bc('0x2b')]]={'$like':'%'+_0x4cdc73[_0x74bc('0x33')]['filter']+'%'};return _0x1ca24e;}})});}_0x404571=_[_0x74bc('0x3f')]({},_0x404571,_0x4cdc73[_0x74bc('0x41')]);var _0x24d517={'where':_0x404571[_0x74bc('0x3e')]};return db[_0x74bc('0x2e')]['count'](_0x24d517)[_0x74bc('0x28')](function(_0x20611d){_0x23f32d[_0x74bc('0x22')]=_0x20611d;if(_0x4cdc73[_0x74bc('0x33')][_0x74bc('0x42')]){_0x404571[_0x74bc('0x43')]=[{'all':!![]}];}return db[_0x74bc('0x2e')][_0x74bc('0x44')](_0x404571);})['then'](function(_0x4a89ce){_0x23f32d[_0x74bc('0x45')]=_0x4a89ce;return _0x23f32d;})[_0x74bc('0x28')](respondWithFilteredResult(_0x12fcb3,_0x404571))[_0x74bc('0x46')](handleError(_0x12fcb3,null));};exports[_0x74bc('0x47')]=function(_0x511b36,_0x52c50b){var _0x577e55={'raw':![],'where':{'id':_0x511b36[_0x74bc('0x48')]['id']}},_0x2d5b94={};_0x2d5b94['model']=_[_0x74bc('0x49')](db[_0x74bc('0x2e')]['rawAttributes']);_0x2d5b94[_0x74bc('0x33')]=_['keys'](_0x511b36[_0x74bc('0x33')]);_0x2d5b94[_0x74bc('0x3b')]=_[_0x74bc('0x34')](_0x2d5b94[_0x74bc('0x32')],_0x2d5b94[_0x74bc('0x33')]);_0x577e55[_0x74bc('0x36')]=_[_0x74bc('0x34')](_0x2d5b94[_0x74bc('0x32')],qs[_0x74bc('0x35')](_0x511b36['query'][_0x74bc('0x35')]));_0x577e55[_0x74bc('0x36')]=_0x577e55[_0x74bc('0x36')][_0x74bc('0x37')]?_0x577e55[_0x74bc('0x36')]:_0x2d5b94[_0x74bc('0x32')];if(_0x511b36[_0x74bc('0x33')][_0x74bc('0x42')]){_0x577e55[_0x74bc('0x43')]=[{'all':!![]}];}_0x577e55=_[_0x74bc('0x3f')]({},_0x577e55,_0x511b36[_0x74bc('0x41')]);return db[_0x74bc('0x2e')][_0x74bc('0x4a')](_0x577e55)['then'](handleEntityNotFound(_0x52c50b,null))[_0x74bc('0x28')](respondWithResult(_0x52c50b,null))[_0x74bc('0x46')](handleError(_0x52c50b,null));};exports[_0x74bc('0x4b')]=function(_0x49b0bb,_0x118c20){return db[_0x74bc('0x2e')]['create'](_0x49b0bb[_0x74bc('0x4c')],{})[_0x74bc('0x28')](respondWithResult(_0x118c20,0xc9))[_0x74bc('0x46')](handleError(_0x118c20,null));};exports[_0x74bc('0x27')]=function(_0x448557,_0x274634){if(_0x448557[_0x74bc('0x4c')]['id']){delete _0x448557[_0x74bc('0x4c')]['id'];}return db[_0x74bc('0x2e')][_0x74bc('0x4a')]({'where':{'id':_0x448557['params']['id']}})[_0x74bc('0x28')](handleEntityNotFound(_0x274634,null))[_0x74bc('0x28')](saveUpdates(_0x448557[_0x74bc('0x4c')],null))['then'](respondWithResult(_0x274634,null))[_0x74bc('0x46')](handleError(_0x274634,null));};exports[_0x74bc('0x29')]=function(_0x58007d,_0xf7d03a){return db['VoiceQueueReport'][_0x74bc('0x4a')]({'where':{'id':_0x58007d[_0x74bc('0x48')]['id']}})[_0x74bc('0x28')](handleEntityNotFound(_0xf7d03a,null))[_0x74bc('0x28')](removeEntity(_0xf7d03a,null))[_0x74bc('0x46')](handleError(_0xf7d03a,null));};exports[_0x74bc('0x4d')]=function(_0x49216e,_0x109186){return db[_0x74bc('0x2e')][_0x74bc('0x4d')]()[_0x74bc('0x28')](respondWithResult(_0x109186,null))['catch'](handleError(_0x109186,null));};exports[_0x74bc('0x4e')]=function(_0x46c1b6,_0x409ed6){var _0x3e0030={},_0x37e9af={},_0x3772bc={'count':0x0,'rows':[]};_0x37e9af['model']=_[_0x74bc('0x49')](db[_0x74bc('0x2e')]['rawAttributes']);_0x37e9af[_0x74bc('0x33')]=_[_0x74bc('0x49')](_0x46c1b6[_0x74bc('0x33')]);_0x37e9af[_0x74bc('0x3b')]=_[_0x74bc('0x34')](_0x37e9af[_0x74bc('0x32')],_0x37e9af['query']);_0x3e0030['attributes']=_[_0x74bc('0x34')](_0x37e9af[_0x74bc('0x32')],qs[_0x74bc('0x35')](_0x46c1b6['query'][_0x74bc('0x35')]));_0x3e0030[_0x74bc('0x36')]=_0x3e0030[_0x74bc('0x36')][_0x74bc('0x37')]?_0x3e0030[_0x74bc('0x36')]:_0x37e9af['model'];if(!_0x46c1b6['query'][_0x74bc('0x4f')](_0x74bc('0x38'))){_0x3e0030[_0x74bc('0x21')]=qs[_0x74bc('0x21')](_0x46c1b6['query'][_0x74bc('0x21')]);_0x3e0030[_0x74bc('0x1f')]=qs[_0x74bc('0x1f')](_0x46c1b6['query'][_0x74bc('0x1f')]);}_0x3e0030[_0x74bc('0x39')]=qs['sort'](_0x46c1b6[_0x74bc('0x33')][_0x74bc('0x3a')]);_0x3e0030[_0x74bc('0x3e')]=qs['filters'](_[_0x74bc('0x3c')](_0x46c1b6[_0x74bc('0x33')],_0x37e9af[_0x74bc('0x3b')]));if(_0x46c1b6[_0x74bc('0x33')][_0x74bc('0x3d')]){_0x3e0030[_0x74bc('0x3e')]=_['merge'](_0x3e0030[_0x74bc('0x3e')],{'$or':_[_0x74bc('0x50')](_0x3e0030[_0x74bc('0x36')],function(_0x339c9e){var _0x1bb275={};_0x1bb275[_0x339c9e]={'$like':'%'+_0x46c1b6[_0x74bc('0x33')][_0x74bc('0x3d')]+'%'};return _0x1bb275;})});}_0x3e0030=_[_0x74bc('0x3f')]({},_0x3e0030,_0x46c1b6[_0x74bc('0x41')]);var _0x4e96e6={'where':_0x3e0030[_0x74bc('0x3e')]};return db[_0x74bc('0x2e')][_0x74bc('0x22')](_0x4e96e6)[_0x74bc('0x28')](function(_0x5b6542){_0x3772bc['count']=_0x5b6542;if(_0x46c1b6[_0x74bc('0x33')][_0x74bc('0x42')]){_0x3e0030[_0x74bc('0x43')]=[{'all':!![]}];}return db['VoiceQueueReport'][_0x74bc('0x44')](_0x3e0030);})[_0x74bc('0x28')](function(_0x53d1d4){_0x3772bc[_0x74bc('0x45')]=_0x53d1d4;return _0x3772bc;})['then'](respondWithFilteredResult(_0x409ed6,_0x3e0030,_0x74bc('0x4e')))['catch'](handleError(_0x409ed6,null,'getVoiceQueuesReport'));};