896af3281054adab28d114ea88498f3b64c02ee0
[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 _0x227f=['../../config/license/hardware','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis','defaults','localhost','socket.io-emitter','./voiceQueueReport.socket','register','status','end','json','offset','limit','undefined','count','Content-Range','reject','save','then','error','stack','name','send','index','map','rawAttributes','fieldName','type','key','model','query','filters','intersection','fields','attributes','length','nolimit','order','sort','pick','filter','where','merge','VIRTUAL','options','VoiceQueueReport','includeAll','include','findAll','show','keys','find','catch','create','body','destroy','params','describe','getVoiceQueuesReport','hasOwnProperty','rows','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','ejs','fs-extra','squel','desk.js','to-csv','querystring','papaparse','../../components/auth/service'];(function(_0x3c4a32,_0x3bceea){var _0x2063bc=function(_0x3e6c42){while(--_0x3e6c42){_0x3c4a32['push'](_0x3c4a32['shift']());}};_0x2063bc(++_0x3bceea);}(_0x227f,0x18c));var _0xf227=function(_0x483ccb,_0x19998f){_0x483ccb=_0x483ccb-0x0;var _0x25d677=_0x227f[_0x483ccb];return _0x25d677;};'use strict';var emlformat=require(_0xf227('0x0'));var rimraf=require(_0xf227('0x1'));var zipdir=require(_0xf227('0x2'));var jsonpatch=require(_0xf227('0x3'));var rp=require(_0xf227('0x4'));var moment=require(_0xf227('0x5'));var BPromise=require(_0xf227('0x6'));var Mustache=require(_0xf227('0x7'));var util=require(_0xf227('0x8'));var path=require(_0xf227('0x9'));var sox=require(_0xf227('0xa'));var csv=require('to-csv');var ejs=require(_0xf227('0xb'));var fs=require('fs');var fs_extra=require(_0xf227('0xc'));var _=require('lodash');var squel=require(_0xf227('0xd'));var crypto=require('crypto');var jsforce=require('jsforce');var deskjs=require(_0xf227('0xe'));var toCsv=require(_0xf227('0xf'));var querystring=require(_0xf227('0x10'));var Papa=require(_0xf227('0x11'));var Redis=require('ioredis');var authService=require(_0xf227('0x12'));var qs=require('../../components/parsers/qs');var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xf227('0x13'));var logger=require('../../config/logger')('api');var utils=require(_0xf227('0x14'));var config=require(_0xf227('0x15'));var licenseUtil=require(_0xf227('0x16'));var db=require(_0xf227('0x17'))['db'];config[_0xf227('0x18')]=_[_0xf227('0x19')](config[_0xf227('0x18')],{'host':_0xf227('0x1a'),'port':0x18eb});var socket=require(_0xf227('0x1b'))(new Redis(config[_0xf227('0x18')]));require(_0xf227('0x1c'))[_0xf227('0x1d')](socket);function respondWithStatusCode(_0x4ee4c5,_0x57088f){_0x57088f=_0x57088f||0xcc;return function(_0x3b34dd){if(_0x3b34dd){return _0x4ee4c5['sendStatus'](_0x57088f);}return _0x4ee4c5[_0xf227('0x1e')](_0x57088f)[_0xf227('0x1f')]();};}function respondWithResult(_0x4f3693,_0x4e2e6d){_0x4e2e6d=_0x4e2e6d||0xc8;return function(_0x10e74d){if(_0x10e74d){return _0x4f3693[_0xf227('0x1e')](_0x4e2e6d)[_0xf227('0x20')](_0x10e74d);}};}function respondWithFilteredResult(_0x326066,_0x5178c9){return function(_0x33991e){if(_0x33991e){var _0x33b4b2=typeof _0x5178c9[_0xf227('0x21')]==='undefined'&&typeof _0x5178c9[_0xf227('0x22')]===_0xf227('0x23');var _0xfaf3b9=_0x33991e[_0xf227('0x24')];var _0x4a03b4=_0x33b4b2?0x0:_0x5178c9[_0xf227('0x21')];var _0x3a7616=_0x33b4b2?_0x33991e[_0xf227('0x24')]:_0x5178c9[_0xf227('0x21')]+_0x5178c9[_0xf227('0x22')];var _0x351da9;if(_0x3a7616>=_0xfaf3b9){_0x3a7616=_0xfaf3b9;_0x351da9=0xc8;}else{_0x351da9=0xce;}_0x326066[_0xf227('0x1e')](_0x351da9);return _0x326066['set'](_0xf227('0x25'),_0x4a03b4+'-'+_0x3a7616+'/'+_0xfaf3b9)['json'](_0x33991e);}return null;};}function patchUpdates(_0x424209){return function(_0x1a5585){try{jsonpatch['apply'](_0x1a5585,_0x424209,!![]);}catch(_0x3974cd){return BPromise[_0xf227('0x26')](_0x3974cd);}return _0x1a5585[_0xf227('0x27')]();};}function saveUpdates(_0x3fcb1e,_0x5eb340){return function(_0x3f72f7){if(_0x3f72f7){return _0x3f72f7['update'](_0x3fcb1e)['then'](function(_0x3a01ce){return _0x3a01ce;});}return null;};}function removeEntity(_0x23d296,_0x275ea6){return function(_0x4bf9ea){if(_0x4bf9ea){return _0x4bf9ea['destroy']()[_0xf227('0x28')](function(){_0x23d296[_0xf227('0x1e')](0xcc)[_0xf227('0x1f')]();});}};}function handleEntityNotFound(_0x23120e,_0x1087cf){return function(_0x4aebfc){if(!_0x4aebfc){_0x23120e['sendStatus'](0x194);}return _0x4aebfc;};}function handleError(_0x35ea04,_0x38ad81){_0x38ad81=_0x38ad81||0x1f4;return function(_0x584517){logger[_0xf227('0x29')](_0x584517[_0xf227('0x2a')]);if(_0x584517[_0xf227('0x2b')]){delete _0x584517[_0xf227('0x2b')];}_0x35ea04[_0xf227('0x1e')](_0x38ad81)[_0xf227('0x2c')](_0x584517);};}exports[_0xf227('0x2d')]=function(_0x4dad7a,_0x10e7c1){var _0x2da3ec={},_0xb89e61={},_0x5550cf={'count':0x0,'rows':[]};var _0x1e4e19=_[_0xf227('0x2e')](db['VoiceQueueReport'][_0xf227('0x2f')],function(_0x37af3c){return{'name':_0x37af3c[_0xf227('0x30')],'type':_0x37af3c[_0xf227('0x31')][_0xf227('0x32')]};});_0xb89e61[_0xf227('0x33')]=_[_0xf227('0x2e')](_0x1e4e19,_0xf227('0x2b'));_0xb89e61[_0xf227('0x34')]=_['keys'](_0x4dad7a['query']);_0xb89e61[_0xf227('0x35')]=_['intersection'](_0xb89e61['model'],_0xb89e61[_0xf227('0x34')]);_0x2da3ec['attributes']=_[_0xf227('0x36')](_0xb89e61[_0xf227('0x33')],qs[_0xf227('0x37')](_0x4dad7a[_0xf227('0x34')][_0xf227('0x37')]));_0x2da3ec[_0xf227('0x38')]=_0x2da3ec['attributes'][_0xf227('0x39')]?_0x2da3ec[_0xf227('0x38')]:_0xb89e61[_0xf227('0x33')];if(!_0x4dad7a[_0xf227('0x34')]['hasOwnProperty'](_0xf227('0x3a'))){_0x2da3ec[_0xf227('0x22')]=qs[_0xf227('0x22')](_0x4dad7a[_0xf227('0x34')][_0xf227('0x22')]);_0x2da3ec[_0xf227('0x21')]=qs['offset'](_0x4dad7a[_0xf227('0x34')][_0xf227('0x21')]);}_0x2da3ec[_0xf227('0x3b')]=qs[_0xf227('0x3c')](_0x4dad7a[_0xf227('0x34')][_0xf227('0x3c')]);_0x2da3ec['where']=qs[_0xf227('0x35')](_[_0xf227('0x3d')](_0x4dad7a['query'],_0xb89e61['filters']),_0x1e4e19);if(_0x4dad7a['query'][_0xf227('0x3e')]){_0x2da3ec[_0xf227('0x3f')]=_[_0xf227('0x40')](_0x2da3ec[_0xf227('0x3f')],{'$or':_['map'](_0x1e4e19,function(_0xb6e17c){if(_0xb6e17c[_0xf227('0x31')]!==_0xf227('0x41')){var _0x349872={};_0x349872[_0xb6e17c['name']]={'$like':'%'+_0x4dad7a[_0xf227('0x34')][_0xf227('0x3e')]+'%'};return _0x349872;}})});}_0x2da3ec=_[_0xf227('0x40')]({},_0x2da3ec,_0x4dad7a[_0xf227('0x42')]);var _0x34d1ae={'where':_0x2da3ec[_0xf227('0x3f')]};return db[_0xf227('0x43')][_0xf227('0x24')](_0x34d1ae)['then'](function(_0x5ca2ec){_0x5550cf[_0xf227('0x24')]=_0x5ca2ec;if(_0x4dad7a[_0xf227('0x34')][_0xf227('0x44')]){_0x2da3ec[_0xf227('0x45')]=[{'all':!![]}];}return db[_0xf227('0x43')][_0xf227('0x46')](_0x2da3ec);})[_0xf227('0x28')](function(_0x5d2f6a){_0x5550cf['rows']=_0x5d2f6a;return _0x5550cf;})[_0xf227('0x28')](respondWithFilteredResult(_0x10e7c1,_0x2da3ec))['catch'](handleError(_0x10e7c1,null));};exports[_0xf227('0x47')]=function(_0x42e2a3,_0x52a4fb){var _0x95d6bd={'raw':![],'where':{'id':_0x42e2a3['params']['id']}},_0xc5d8db={};_0xc5d8db[_0xf227('0x33')]=_[_0xf227('0x48')](db[_0xf227('0x43')]['rawAttributes']);_0xc5d8db[_0xf227('0x34')]=_[_0xf227('0x48')](_0x42e2a3[_0xf227('0x34')]);_0xc5d8db['filters']=_[_0xf227('0x36')](_0xc5d8db[_0xf227('0x33')],_0xc5d8db[_0xf227('0x34')]);_0x95d6bd[_0xf227('0x38')]=_[_0xf227('0x36')](_0xc5d8db[_0xf227('0x33')],qs[_0xf227('0x37')](_0x42e2a3['query'][_0xf227('0x37')]));_0x95d6bd['attributes']=_0x95d6bd[_0xf227('0x38')][_0xf227('0x39')]?_0x95d6bd[_0xf227('0x38')]:_0xc5d8db['model'];if(_0x42e2a3['query'][_0xf227('0x44')]){_0x95d6bd['include']=[{'all':!![]}];}_0x95d6bd=_[_0xf227('0x40')]({},_0x95d6bd,_0x42e2a3['options']);return db[_0xf227('0x43')][_0xf227('0x49')](_0x95d6bd)[_0xf227('0x28')](handleEntityNotFound(_0x52a4fb,null))['then'](respondWithResult(_0x52a4fb,null))[_0xf227('0x4a')](handleError(_0x52a4fb,null));};exports[_0xf227('0x4b')]=function(_0xdb095c,_0x2330e3){return db[_0xf227('0x43')]['create'](_0xdb095c['body'],{})[_0xf227('0x28')](respondWithResult(_0x2330e3,0xc9))['catch'](handleError(_0x2330e3,null));};exports['update']=function(_0x4669dc,_0x3738b3){if(_0x4669dc[_0xf227('0x4c')]['id']){delete _0x4669dc['body']['id'];}return db[_0xf227('0x43')]['find']({'where':{'id':_0x4669dc['params']['id']}})[_0xf227('0x28')](handleEntityNotFound(_0x3738b3,null))['then'](saveUpdates(_0x4669dc['body'],null))[_0xf227('0x28')](respondWithResult(_0x3738b3,null))[_0xf227('0x4a')](handleError(_0x3738b3,null));};exports[_0xf227('0x4d')]=function(_0x28e2ac,_0x421d4e){return db['VoiceQueueReport'][_0xf227('0x49')]({'where':{'id':_0x28e2ac[_0xf227('0x4e')]['id']}})['then'](handleEntityNotFound(_0x421d4e,null))['then'](removeEntity(_0x421d4e,null))['catch'](handleError(_0x421d4e,null));};exports[_0xf227('0x4f')]=function(_0x5901c3,_0x4eef4e){return db[_0xf227('0x43')][_0xf227('0x4f')]()[_0xf227('0x28')](respondWithResult(_0x4eef4e,null))[_0xf227('0x4a')](handleError(_0x4eef4e,null));};exports[_0xf227('0x50')]=function(_0x2a8d19,_0x13b1eb){var _0xad92f8={},_0x11f438={},_0x194be0={'count':0x0,'rows':[]};_0x11f438[_0xf227('0x33')]=_[_0xf227('0x48')](db[_0xf227('0x43')][_0xf227('0x2f')]);_0x11f438[_0xf227('0x34')]=_[_0xf227('0x48')](_0x2a8d19[_0xf227('0x34')]);_0x11f438['filters']=_[_0xf227('0x36')](_0x11f438[_0xf227('0x33')],_0x11f438['query']);_0xad92f8[_0xf227('0x38')]=_[_0xf227('0x36')](_0x11f438['model'],qs[_0xf227('0x37')](_0x2a8d19[_0xf227('0x34')][_0xf227('0x37')]));_0xad92f8[_0xf227('0x38')]=_0xad92f8[_0xf227('0x38')][_0xf227('0x39')]?_0xad92f8[_0xf227('0x38')]:_0x11f438['model'];if(!_0x2a8d19[_0xf227('0x34')][_0xf227('0x51')](_0xf227('0x3a'))){_0xad92f8[_0xf227('0x22')]=qs[_0xf227('0x22')](_0x2a8d19['query'][_0xf227('0x22')]);_0xad92f8[_0xf227('0x21')]=qs[_0xf227('0x21')](_0x2a8d19[_0xf227('0x34')][_0xf227('0x21')]);}_0xad92f8[_0xf227('0x3b')]=qs['sort'](_0x2a8d19[_0xf227('0x34')][_0xf227('0x3c')]);_0xad92f8['where']=qs['filters'](_[_0xf227('0x3d')](_0x2a8d19[_0xf227('0x34')],_0x11f438[_0xf227('0x35')]));if(_0x2a8d19[_0xf227('0x34')]['filter']){_0xad92f8[_0xf227('0x3f')]=_[_0xf227('0x40')](_0xad92f8['where'],{'$or':_[_0xf227('0x2e')](_0xad92f8[_0xf227('0x38')],function(_0xda4f82){var _0x55477e={};_0x55477e[_0xda4f82]={'$like':'%'+_0x2a8d19[_0xf227('0x34')]['filter']+'%'};return _0x55477e;})});}_0xad92f8=_[_0xf227('0x40')]({},_0xad92f8,_0x2a8d19[_0xf227('0x42')]);var _0x534afa={'where':_0xad92f8[_0xf227('0x3f')]};return db[_0xf227('0x43')][_0xf227('0x24')](_0x534afa)[_0xf227('0x28')](function(_0x18feae){_0x194be0[_0xf227('0x24')]=_0x18feae;if(_0x2a8d19[_0xf227('0x34')][_0xf227('0x44')]){_0xad92f8[_0xf227('0x45')]=[{'all':!![]}];}return db[_0xf227('0x43')][_0xf227('0x46')](_0xad92f8);})[_0xf227('0x28')](function(_0x51045b){_0x194be0[_0xf227('0x52')]=_0x51045b;return _0x194be0;})[_0xf227('0x28')](respondWithFilteredResult(_0x13b1eb,_0xad92f8,_0xf227('0x50')))[_0xf227('0x4a')](handleError(_0x13b1eb,null,_0xf227('0x50')));};