4a5bc16b76b9fb9853f58ed679ad505d5cddcde6
[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 _0x5cc0=['papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis','defaults','localhost','./voiceQueueReport.socket','register','sendStatus','end','json','offset','limit','undefined','count','set','Content-Range','reject','save','update','then','status','error','stack','name','send','map','rawAttributes','fieldName','type','model','keys','query','filters','intersection','fields','attributes','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','VIRTUAL','VoiceQueueReport','include','findAll','rows','params','includeAll','options','find','create','body','catch','destroy','describe','getVoiceQueuesReport','zip-dir','fast-json-patch','request-promise','bluebird','mustache','util','path','sox','to-csv','ejs','fs-extra','lodash','crypto','jsforce','desk.js'];(function(_0xbca1b1,_0x33f0ce){var _0x4e1686=function(_0x58a80c){while(--_0x58a80c){_0xbca1b1['push'](_0xbca1b1['shift']());}};_0x4e1686(++_0x33f0ce);}(_0x5cc0,0xed));var _0x05cc=function(_0x3dd15e,_0x1f0015){_0x3dd15e=_0x3dd15e-0x0;var _0x231fd0=_0x5cc0[_0x3dd15e];return _0x231fd0;};'use strict';var emlformat=require('eml-format');var rimraf=require('rimraf');var zipdir=require(_0x05cc('0x0'));var jsonpatch=require(_0x05cc('0x1'));var rp=require(_0x05cc('0x2'));var moment=require('moment');var BPromise=require(_0x05cc('0x3'));var Mustache=require(_0x05cc('0x4'));var util=require(_0x05cc('0x5'));var path=require(_0x05cc('0x6'));var sox=require(_0x05cc('0x7'));var csv=require(_0x05cc('0x8'));var ejs=require(_0x05cc('0x9'));var fs=require('fs');var fs_extra=require(_0x05cc('0xa'));var _=require(_0x05cc('0xb'));var squel=require('squel');var crypto=require(_0x05cc('0xc'));var jsforce=require(_0x05cc('0xd'));var deskjs=require(_0x05cc('0xe'));var toCsv=require(_0x05cc('0x8'));var querystring=require('querystring');var Papa=require(_0x05cc('0xf'));var Redis=require(_0x05cc('0x10'));var authService=require(_0x05cc('0x11'));var qs=require(_0x05cc('0x12'));var as=require(_0x05cc('0x13'));var hardwareService=require(_0x05cc('0x14'));var logger=require(_0x05cc('0x15'))('api');var utils=require(_0x05cc('0x16'));var config=require(_0x05cc('0x17'));var licenseUtil=require(_0x05cc('0x18'));var db=require(_0x05cc('0x19'))['db'];config[_0x05cc('0x1a')]=_[_0x05cc('0x1b')](config[_0x05cc('0x1a')],{'host':_0x05cc('0x1c'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config['redis']));require(_0x05cc('0x1d'))[_0x05cc('0x1e')](socket);function respondWithStatusCode(_0x5dacbd,_0x5ba07d){_0x5ba07d=_0x5ba07d||0xcc;return function(_0x12e1c0){if(_0x12e1c0){return _0x5dacbd[_0x05cc('0x1f')](_0x5ba07d);}return _0x5dacbd['status'](_0x5ba07d)[_0x05cc('0x20')]();};}function respondWithResult(_0x2700d0,_0x1ae5c9){_0x1ae5c9=_0x1ae5c9||0xc8;return function(_0x501e9b){if(_0x501e9b){return _0x2700d0['status'](_0x1ae5c9)[_0x05cc('0x21')](_0x501e9b);}};}function respondWithFilteredResult(_0x4f545a,_0x537a42){return function(_0x526db2){if(_0x526db2){var _0x384979=typeof _0x537a42[_0x05cc('0x22')]==='undefined'&&typeof _0x537a42[_0x05cc('0x23')]===_0x05cc('0x24');var _0x554d9e=_0x526db2[_0x05cc('0x25')];var _0x1f2a16=_0x384979?0x0:_0x537a42[_0x05cc('0x22')];var _0x2b4680=_0x384979?_0x526db2[_0x05cc('0x25')]:_0x537a42['offset']+_0x537a42[_0x05cc('0x23')];var _0x300280;if(_0x2b4680>=_0x554d9e){_0x2b4680=_0x554d9e;_0x300280=0xc8;}else{_0x300280=0xce;}_0x4f545a['status'](_0x300280);return _0x4f545a[_0x05cc('0x26')](_0x05cc('0x27'),_0x1f2a16+'-'+_0x2b4680+'/'+_0x554d9e)[_0x05cc('0x21')](_0x526db2);}return null;};}function patchUpdates(_0x388322){return function(_0x3fbbf7){try{jsonpatch['apply'](_0x3fbbf7,_0x388322,!![]);}catch(_0x97812){return BPromise[_0x05cc('0x28')](_0x97812);}return _0x3fbbf7[_0x05cc('0x29')]();};}function saveUpdates(_0x35da52,_0x46849c){return function(_0x2bbe77){if(_0x2bbe77){return _0x2bbe77[_0x05cc('0x2a')](_0x35da52)[_0x05cc('0x2b')](function(_0x6256bf){return _0x6256bf;});}return null;};}function removeEntity(_0x467396,_0x361acf){return function(_0x1c1014){if(_0x1c1014){return _0x1c1014['destroy']()[_0x05cc('0x2b')](function(){_0x467396[_0x05cc('0x2c')](0xcc)[_0x05cc('0x20')]();});}};}function handleEntityNotFound(_0x252e52,_0x5bfdb5){return function(_0x1a0013){if(!_0x1a0013){_0x252e52[_0x05cc('0x1f')](0x194);}return _0x1a0013;};}function handleError(_0x365e77,_0x4ad19e){_0x4ad19e=_0x4ad19e||0x1f4;return function(_0x59d5bf){logger[_0x05cc('0x2d')](_0x59d5bf[_0x05cc('0x2e')]);if(_0x59d5bf[_0x05cc('0x2f')]){delete _0x59d5bf[_0x05cc('0x2f')];}_0x365e77[_0x05cc('0x2c')](_0x4ad19e)[_0x05cc('0x30')](_0x59d5bf);};}exports['index']=function(_0x3ba616,_0x44767a){var _0x1eadf8={},_0x4c3678={},_0x37ae3e={'count':0x0,'rows':[]};var _0x233f18=_[_0x05cc('0x31')](db['VoiceQueueReport'][_0x05cc('0x32')],function(_0x2edd91){return{'name':_0x2edd91[_0x05cc('0x33')],'type':_0x2edd91[_0x05cc('0x34')]['key']};});_0x4c3678[_0x05cc('0x35')]=_[_0x05cc('0x31')](_0x233f18,'name');_0x4c3678['query']=_[_0x05cc('0x36')](_0x3ba616[_0x05cc('0x37')]);_0x4c3678[_0x05cc('0x38')]=_['intersection'](_0x4c3678[_0x05cc('0x35')],_0x4c3678[_0x05cc('0x37')]);_0x1eadf8['attributes']=_[_0x05cc('0x39')](_0x4c3678[_0x05cc('0x35')],qs[_0x05cc('0x3a')](_0x3ba616['query'][_0x05cc('0x3a')]));_0x1eadf8[_0x05cc('0x3b')]=_0x1eadf8[_0x05cc('0x3b')][_0x05cc('0x3c')]?_0x1eadf8[_0x05cc('0x3b')]:_0x4c3678[_0x05cc('0x35')];if(!_0x3ba616[_0x05cc('0x37')][_0x05cc('0x3d')](_0x05cc('0x3e'))){_0x1eadf8[_0x05cc('0x23')]=qs[_0x05cc('0x23')](_0x3ba616[_0x05cc('0x37')][_0x05cc('0x23')]);_0x1eadf8[_0x05cc('0x22')]=qs[_0x05cc('0x22')](_0x3ba616['query']['offset']);}_0x1eadf8[_0x05cc('0x3f')]=qs[_0x05cc('0x40')](_0x3ba616['query'][_0x05cc('0x40')]);_0x1eadf8[_0x05cc('0x41')]=qs['filters'](_[_0x05cc('0x42')](_0x3ba616[_0x05cc('0x37')],_0x4c3678['filters']),_0x233f18);if(_0x3ba616[_0x05cc('0x37')][_0x05cc('0x43')]){_0x1eadf8[_0x05cc('0x41')]=_[_0x05cc('0x44')](_0x1eadf8['where'],{'$or':_['map'](_0x233f18,function(_0x4ca1ef){if(_0x4ca1ef[_0x05cc('0x34')]!==_0x05cc('0x45')){var _0x706440={};_0x706440[_0x4ca1ef[_0x05cc('0x2f')]]={'$like':'%'+_0x3ba616[_0x05cc('0x37')][_0x05cc('0x43')]+'%'};return _0x706440;}})});}_0x1eadf8=_[_0x05cc('0x44')]({},_0x1eadf8,_0x3ba616['options']);var _0x17c827={'where':_0x1eadf8[_0x05cc('0x41')]};return db[_0x05cc('0x46')][_0x05cc('0x25')](_0x17c827)[_0x05cc('0x2b')](function(_0x44cb06){_0x37ae3e[_0x05cc('0x25')]=_0x44cb06;if(_0x3ba616[_0x05cc('0x37')]['includeAll']){_0x1eadf8[_0x05cc('0x47')]=[{'all':!![]}];}return db[_0x05cc('0x46')][_0x05cc('0x48')](_0x1eadf8);})[_0x05cc('0x2b')](function(_0x3a856d){_0x37ae3e[_0x05cc('0x49')]=_0x3a856d;return _0x37ae3e;})[_0x05cc('0x2b')](respondWithFilteredResult(_0x44767a,_0x1eadf8))['catch'](handleError(_0x44767a,null));};exports['show']=function(_0xbcb00d,_0x50d08c){var _0x510108={'raw':![],'where':{'id':_0xbcb00d[_0x05cc('0x4a')]['id']}},_0x4a78d5={};_0x4a78d5[_0x05cc('0x35')]=_['keys'](db[_0x05cc('0x46')]['rawAttributes']);_0x4a78d5[_0x05cc('0x37')]=_[_0x05cc('0x36')](_0xbcb00d[_0x05cc('0x37')]);_0x4a78d5['filters']=_['intersection'](_0x4a78d5[_0x05cc('0x35')],_0x4a78d5[_0x05cc('0x37')]);_0x510108[_0x05cc('0x3b')]=_['intersection'](_0x4a78d5[_0x05cc('0x35')],qs['fields'](_0xbcb00d[_0x05cc('0x37')][_0x05cc('0x3a')]));_0x510108[_0x05cc('0x3b')]=_0x510108[_0x05cc('0x3b')]['length']?_0x510108[_0x05cc('0x3b')]:_0x4a78d5[_0x05cc('0x35')];if(_0xbcb00d[_0x05cc('0x37')][_0x05cc('0x4b')]){_0x510108[_0x05cc('0x47')]=[{'all':!![]}];}_0x510108=_['merge']({},_0x510108,_0xbcb00d[_0x05cc('0x4c')]);return db['VoiceQueueReport'][_0x05cc('0x4d')](_0x510108)[_0x05cc('0x2b')](handleEntityNotFound(_0x50d08c,null))[_0x05cc('0x2b')](respondWithResult(_0x50d08c,null))['catch'](handleError(_0x50d08c,null));};exports[_0x05cc('0x4e')]=function(_0xb12dea,_0x478cca){return db[_0x05cc('0x46')][_0x05cc('0x4e')](_0xb12dea['body'],{})[_0x05cc('0x2b')](respondWithResult(_0x478cca,0xc9))['catch'](handleError(_0x478cca,null));};exports[_0x05cc('0x2a')]=function(_0x18aa2a,_0x1d088e){if(_0x18aa2a['body']['id']){delete _0x18aa2a[_0x05cc('0x4f')]['id'];}return db[_0x05cc('0x46')][_0x05cc('0x4d')]({'where':{'id':_0x18aa2a[_0x05cc('0x4a')]['id']}})['then'](handleEntityNotFound(_0x1d088e,null))[_0x05cc('0x2b')](saveUpdates(_0x18aa2a['body'],null))['then'](respondWithResult(_0x1d088e,null))[_0x05cc('0x50')](handleError(_0x1d088e,null));};exports[_0x05cc('0x51')]=function(_0x3edb27,_0xfb9ccc){return db[_0x05cc('0x46')][_0x05cc('0x4d')]({'where':{'id':_0x3edb27['params']['id']}})[_0x05cc('0x2b')](handleEntityNotFound(_0xfb9ccc,null))[_0x05cc('0x2b')](removeEntity(_0xfb9ccc,null))[_0x05cc('0x50')](handleError(_0xfb9ccc,null));};exports['describe']=function(_0x206bb9,_0x4fccdd){return db[_0x05cc('0x46')][_0x05cc('0x52')]()[_0x05cc('0x2b')](respondWithResult(_0x4fccdd,null))['catch'](handleError(_0x4fccdd,null));};exports[_0x05cc('0x53')]=function(_0x2068dd,_0x445c43){var _0x254eaa={},_0x4a9513={},_0x440b53={'count':0x0,'rows':[]};_0x4a9513[_0x05cc('0x35')]=_[_0x05cc('0x36')](db[_0x05cc('0x46')][_0x05cc('0x32')]);_0x4a9513[_0x05cc('0x37')]=_[_0x05cc('0x36')](_0x2068dd[_0x05cc('0x37')]);_0x4a9513[_0x05cc('0x38')]=_[_0x05cc('0x39')](_0x4a9513['model'],_0x4a9513[_0x05cc('0x37')]);_0x254eaa['attributes']=_[_0x05cc('0x39')](_0x4a9513[_0x05cc('0x35')],qs[_0x05cc('0x3a')](_0x2068dd[_0x05cc('0x37')][_0x05cc('0x3a')]));_0x254eaa[_0x05cc('0x3b')]=_0x254eaa['attributes']['length']?_0x254eaa[_0x05cc('0x3b')]:_0x4a9513[_0x05cc('0x35')];if(!_0x2068dd[_0x05cc('0x37')][_0x05cc('0x3d')](_0x05cc('0x3e'))){_0x254eaa['limit']=qs[_0x05cc('0x23')](_0x2068dd[_0x05cc('0x37')]['limit']);_0x254eaa[_0x05cc('0x22')]=qs[_0x05cc('0x22')](_0x2068dd[_0x05cc('0x37')][_0x05cc('0x22')]);}_0x254eaa[_0x05cc('0x3f')]=qs[_0x05cc('0x40')](_0x2068dd[_0x05cc('0x37')][_0x05cc('0x40')]);_0x254eaa['where']=qs[_0x05cc('0x38')](_[_0x05cc('0x42')](_0x2068dd['query'],_0x4a9513[_0x05cc('0x38')]));if(_0x2068dd['query'][_0x05cc('0x43')]){_0x254eaa[_0x05cc('0x41')]=_[_0x05cc('0x44')](_0x254eaa[_0x05cc('0x41')],{'$or':_[_0x05cc('0x31')](_0x254eaa['attributes'],function(_0x433890){var _0x481d48={};_0x481d48[_0x433890]={'$like':'%'+_0x2068dd[_0x05cc('0x37')][_0x05cc('0x43')]+'%'};return _0x481d48;})});}_0x254eaa=_[_0x05cc('0x44')]({},_0x254eaa,_0x2068dd[_0x05cc('0x4c')]);var _0x12b0ee={'where':_0x254eaa[_0x05cc('0x41')]};return db['VoiceQueueReport'][_0x05cc('0x25')](_0x12b0ee)[_0x05cc('0x2b')](function(_0x2fb392){_0x440b53[_0x05cc('0x25')]=_0x2fb392;if(_0x2068dd[_0x05cc('0x37')][_0x05cc('0x4b')]){_0x254eaa[_0x05cc('0x47')]=[{'all':!![]}];}return db[_0x05cc('0x46')]['findAll'](_0x254eaa);})[_0x05cc('0x2b')](function(_0x2ae767){_0x440b53[_0x05cc('0x49')]=_0x2ae767;return _0x440b53;})[_0x05cc('0x2b')](respondWithFilteredResult(_0x445c43,_0x254eaa,_0x05cc('0x53')))[_0x05cc('0x50')](handleError(_0x445c43,null,'getVoiceQueuesReport'));};