f27a770bdcbacd2651b8c09d97c61417d6407b8e
[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 _0x2b57=['Content-Range','apply','reject','save','then','destroy','sendStatus','error','stack','name','send','map','rawAttributes','fieldName','type','model','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','merge','filter','options','VoiceQueueReport','includeAll','include','findAll','rows','catch','find','create','update','body','params','describe','getVoiceQueuesReport','pick','eml-format','rimraf','zip-dir','fast-json-patch','moment','bluebird','mustache','path','sox','ejs','lodash','squel','crypto','desk.js','to-csv','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','api','../../config/utils','../../config/environment','../../mysqldb','defaults','redis','localhost','socket.io-emitter','register','status','end','json','offset','undefined','limit','count','set'];(function(_0x3889c7,_0x538dbc){var _0x47ae6f=function(_0x3ebd05){while(--_0x3ebd05){_0x3889c7['push'](_0x3889c7['shift']());}};_0x47ae6f(++_0x538dbc);}(_0x2b57,0x80));var _0x72b5=function(_0x2c9149,_0x4ef13c){_0x2c9149=_0x2c9149-0x0;var _0x1b784f=_0x2b57[_0x2c9149];return _0x1b784f;};'use strict';var emlformat=require(_0x72b5('0x0'));var rimraf=require(_0x72b5('0x1'));var zipdir=require(_0x72b5('0x2'));var jsonpatch=require(_0x72b5('0x3'));var rp=require('request-promise');var moment=require(_0x72b5('0x4'));var BPromise=require(_0x72b5('0x5'));var Mustache=require(_0x72b5('0x6'));var util=require('util');var path=require(_0x72b5('0x7'));var sox=require(_0x72b5('0x8'));var csv=require('to-csv');var ejs=require(_0x72b5('0x9'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0x72b5('0xa'));var squel=require(_0x72b5('0xb'));var crypto=require(_0x72b5('0xc'));var jsforce=require('jsforce');var deskjs=require(_0x72b5('0xd'));var toCsv=require(_0x72b5('0xe'));var querystring=require(_0x72b5('0xf'));var Papa=require(_0x72b5('0x10'));var Redis=require(_0x72b5('0x11'));var authService=require(_0x72b5('0x12'));var qs=require(_0x72b5('0x13'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x72b5('0x14'));var logger=require('../../config/logger')(_0x72b5('0x15'));var utils=require(_0x72b5('0x16'));var config=require(_0x72b5('0x17'));var licenseUtil=require('../../config/license/util');var db=require(_0x72b5('0x18'))['db'];config['redis']=_[_0x72b5('0x19')](config[_0x72b5('0x1a')],{'host':_0x72b5('0x1b'),'port':0x18eb});var socket=require(_0x72b5('0x1c'))(new Redis(config[_0x72b5('0x1a')]));require('./voiceQueueReport.socket')[_0x72b5('0x1d')](socket);function respondWithStatusCode(_0x8e4b8d,_0x42782d){_0x42782d=_0x42782d||0xcc;return function(_0x57fd59){if(_0x57fd59){return _0x8e4b8d['sendStatus'](_0x42782d);}return _0x8e4b8d[_0x72b5('0x1e')](_0x42782d)[_0x72b5('0x1f')]();};}function respondWithResult(_0x2cae71,_0x37c77d){_0x37c77d=_0x37c77d||0xc8;return function(_0x345cb8){if(_0x345cb8){return _0x2cae71[_0x72b5('0x1e')](_0x37c77d)[_0x72b5('0x20')](_0x345cb8);}};}function respondWithFilteredResult(_0x3b5640,_0x1a73b9){return function(_0x4d1cd1){if(_0x4d1cd1){var _0x29d6c9=typeof _0x1a73b9[_0x72b5('0x21')]===_0x72b5('0x22')&&typeof _0x1a73b9[_0x72b5('0x23')]===_0x72b5('0x22');var _0x44034b=_0x4d1cd1[_0x72b5('0x24')];var _0x3999cc=_0x29d6c9?0x0:_0x1a73b9['offset'];var _0x117a35=_0x29d6c9?_0x4d1cd1[_0x72b5('0x24')]:_0x1a73b9[_0x72b5('0x21')]+_0x1a73b9['limit'];var _0x4eeb89;if(_0x117a35>=_0x44034b){_0x117a35=_0x44034b;_0x4eeb89=0xc8;}else{_0x4eeb89=0xce;}_0x3b5640[_0x72b5('0x1e')](_0x4eeb89);return _0x3b5640[_0x72b5('0x25')](_0x72b5('0x26'),_0x3999cc+'-'+_0x117a35+'/'+_0x44034b)[_0x72b5('0x20')](_0x4d1cd1);}return null;};}function patchUpdates(_0xe2742b){return function(_0x34dada){try{jsonpatch[_0x72b5('0x27')](_0x34dada,_0xe2742b,!![]);}catch(_0x4f4b08){return BPromise[_0x72b5('0x28')](_0x4f4b08);}return _0x34dada[_0x72b5('0x29')]();};}function saveUpdates(_0x19eac4,_0x1891ef){return function(_0x3045ac){if(_0x3045ac){return _0x3045ac['update'](_0x19eac4)[_0x72b5('0x2a')](function(_0x5653f3){return _0x5653f3;});}return null;};}function removeEntity(_0x2d6baa,_0x4ea958){return function(_0x222484){if(_0x222484){return _0x222484[_0x72b5('0x2b')]()[_0x72b5('0x2a')](function(){_0x2d6baa[_0x72b5('0x1e')](0xcc)[_0x72b5('0x1f')]();});}};}function handleEntityNotFound(_0x5c061a,_0x5067f8){return function(_0x5a1fd4){if(!_0x5a1fd4){_0x5c061a[_0x72b5('0x2c')](0x194);}return _0x5a1fd4;};}function handleError(_0x39f4b3,_0xcfe2f9){_0xcfe2f9=_0xcfe2f9||0x1f4;return function(_0xe67897){logger[_0x72b5('0x2d')](_0xe67897[_0x72b5('0x2e')]);if(_0xe67897['name']){delete _0xe67897[_0x72b5('0x2f')];}_0x39f4b3[_0x72b5('0x1e')](_0xcfe2f9)[_0x72b5('0x30')](_0xe67897);};}exports['index']=function(_0x28db57,_0xe3e95c){var _0x582798={},_0x288708={},_0x1f82bb={'count':0x0,'rows':[]};var _0x205302=_[_0x72b5('0x31')](db['VoiceQueueReport'][_0x72b5('0x32')],function(_0x9a642d){return{'name':_0x9a642d[_0x72b5('0x33')],'type':_0x9a642d[_0x72b5('0x34')]['key']};});_0x288708[_0x72b5('0x35')]=_[_0x72b5('0x31')](_0x205302,_0x72b5('0x2f'));_0x288708[_0x72b5('0x36')]=_[_0x72b5('0x37')](_0x28db57[_0x72b5('0x36')]);_0x288708[_0x72b5('0x38')]=_[_0x72b5('0x39')](_0x288708[_0x72b5('0x35')],_0x288708[_0x72b5('0x36')]);_0x582798[_0x72b5('0x3a')]=_[_0x72b5('0x39')](_0x288708[_0x72b5('0x35')],qs['fields'](_0x28db57[_0x72b5('0x36')][_0x72b5('0x3b')]));_0x582798[_0x72b5('0x3a')]=_0x582798[_0x72b5('0x3a')][_0x72b5('0x3c')]?_0x582798[_0x72b5('0x3a')]:_0x288708[_0x72b5('0x35')];if(!_0x28db57[_0x72b5('0x36')][_0x72b5('0x3d')](_0x72b5('0x3e'))){_0x582798[_0x72b5('0x23')]=qs[_0x72b5('0x23')](_0x28db57[_0x72b5('0x36')]['limit']);_0x582798[_0x72b5('0x21')]=qs[_0x72b5('0x21')](_0x28db57[_0x72b5('0x36')]['offset']);}_0x582798[_0x72b5('0x3f')]=qs[_0x72b5('0x40')](_0x28db57['query'][_0x72b5('0x40')]);_0x582798['where']=qs['filters'](_['pick'](_0x28db57[_0x72b5('0x36')],_0x288708[_0x72b5('0x38')]),_0x205302);if(_0x28db57[_0x72b5('0x36')]['filter']){_0x582798[_0x72b5('0x41')]=_[_0x72b5('0x42')](_0x582798['where'],{'$or':_[_0x72b5('0x31')](_0x205302,function(_0x1f0a1d){if(_0x1f0a1d[_0x72b5('0x34')]!=='VIRTUAL'){var _0x43129f={};_0x43129f[_0x1f0a1d[_0x72b5('0x2f')]]={'$like':'%'+_0x28db57[_0x72b5('0x36')][_0x72b5('0x43')]+'%'};return _0x43129f;}})});}_0x582798=_['merge']({},_0x582798,_0x28db57[_0x72b5('0x44')]);var _0x1bc0f3={'where':_0x582798[_0x72b5('0x41')]};return db[_0x72b5('0x45')]['count'](_0x1bc0f3)[_0x72b5('0x2a')](function(_0x581d0d){_0x1f82bb['count']=_0x581d0d;if(_0x28db57[_0x72b5('0x36')][_0x72b5('0x46')]){_0x582798[_0x72b5('0x47')]=[{'all':!![]}];}return db[_0x72b5('0x45')][_0x72b5('0x48')](_0x582798);})[_0x72b5('0x2a')](function(_0x5d42b4){_0x1f82bb[_0x72b5('0x49')]=_0x5d42b4;return _0x1f82bb;})[_0x72b5('0x2a')](respondWithFilteredResult(_0xe3e95c,_0x582798))[_0x72b5('0x4a')](handleError(_0xe3e95c,null));};exports['show']=function(_0xe5c8a5,_0x4d903c){var _0x40d3e5={'raw':![],'where':{'id':_0xe5c8a5['params']['id']}},_0x44a172={};_0x44a172[_0x72b5('0x35')]=_[_0x72b5('0x37')](db[_0x72b5('0x45')][_0x72b5('0x32')]);_0x44a172[_0x72b5('0x36')]=_[_0x72b5('0x37')](_0xe5c8a5[_0x72b5('0x36')]);_0x44a172[_0x72b5('0x38')]=_[_0x72b5('0x39')](_0x44a172[_0x72b5('0x35')],_0x44a172[_0x72b5('0x36')]);_0x40d3e5[_0x72b5('0x3a')]=_[_0x72b5('0x39')](_0x44a172[_0x72b5('0x35')],qs[_0x72b5('0x3b')](_0xe5c8a5[_0x72b5('0x36')][_0x72b5('0x3b')]));_0x40d3e5[_0x72b5('0x3a')]=_0x40d3e5[_0x72b5('0x3a')][_0x72b5('0x3c')]?_0x40d3e5[_0x72b5('0x3a')]:_0x44a172[_0x72b5('0x35')];if(_0xe5c8a5[_0x72b5('0x36')]['includeAll']){_0x40d3e5[_0x72b5('0x47')]=[{'all':!![]}];}_0x40d3e5=_['merge']({},_0x40d3e5,_0xe5c8a5[_0x72b5('0x44')]);return db[_0x72b5('0x45')][_0x72b5('0x4b')](_0x40d3e5)[_0x72b5('0x2a')](handleEntityNotFound(_0x4d903c,null))['then'](respondWithResult(_0x4d903c,null))[_0x72b5('0x4a')](handleError(_0x4d903c,null));};exports[_0x72b5('0x4c')]=function(_0x2bdf7d,_0x313650){return db[_0x72b5('0x45')][_0x72b5('0x4c')](_0x2bdf7d['body'],{})[_0x72b5('0x2a')](respondWithResult(_0x313650,0xc9))[_0x72b5('0x4a')](handleError(_0x313650,null));};exports[_0x72b5('0x4d')]=function(_0x80276e,_0x2c256f){if(_0x80276e['body']['id']){delete _0x80276e[_0x72b5('0x4e')]['id'];}return db['VoiceQueueReport'][_0x72b5('0x4b')]({'where':{'id':_0x80276e[_0x72b5('0x4f')]['id']}})[_0x72b5('0x2a')](handleEntityNotFound(_0x2c256f,null))['then'](saveUpdates(_0x80276e[_0x72b5('0x4e')],null))[_0x72b5('0x2a')](respondWithResult(_0x2c256f,null))[_0x72b5('0x4a')](handleError(_0x2c256f,null));};exports['destroy']=function(_0x1d51ce,_0x25ad37){return db[_0x72b5('0x45')][_0x72b5('0x4b')]({'where':{'id':_0x1d51ce['params']['id']}})[_0x72b5('0x2a')](handleEntityNotFound(_0x25ad37,null))[_0x72b5('0x2a')](removeEntity(_0x25ad37,null))[_0x72b5('0x4a')](handleError(_0x25ad37,null));};exports[_0x72b5('0x50')]=function(_0x39bb29,_0x193f40){return db[_0x72b5('0x45')][_0x72b5('0x50')]()[_0x72b5('0x2a')](respondWithResult(_0x193f40,null))[_0x72b5('0x4a')](handleError(_0x193f40,null));};exports[_0x72b5('0x51')]=function(_0x50c06a,_0x3fe9c5){var _0x3a43a9={},_0xf0fc6d={},_0xc89eb1={'count':0x0,'rows':[]};_0xf0fc6d[_0x72b5('0x35')]=_['keys'](db[_0x72b5('0x45')][_0x72b5('0x32')]);_0xf0fc6d[_0x72b5('0x36')]=_['keys'](_0x50c06a['query']);_0xf0fc6d['filters']=_[_0x72b5('0x39')](_0xf0fc6d[_0x72b5('0x35')],_0xf0fc6d[_0x72b5('0x36')]);_0x3a43a9[_0x72b5('0x3a')]=_['intersection'](_0xf0fc6d[_0x72b5('0x35')],qs[_0x72b5('0x3b')](_0x50c06a[_0x72b5('0x36')]['fields']));_0x3a43a9['attributes']=_0x3a43a9[_0x72b5('0x3a')][_0x72b5('0x3c')]?_0x3a43a9[_0x72b5('0x3a')]:_0xf0fc6d[_0x72b5('0x35')];if(!_0x50c06a[_0x72b5('0x36')][_0x72b5('0x3d')](_0x72b5('0x3e'))){_0x3a43a9[_0x72b5('0x23')]=qs[_0x72b5('0x23')](_0x50c06a[_0x72b5('0x36')][_0x72b5('0x23')]);_0x3a43a9[_0x72b5('0x21')]=qs['offset'](_0x50c06a[_0x72b5('0x36')][_0x72b5('0x21')]);}_0x3a43a9[_0x72b5('0x3f')]=qs[_0x72b5('0x40')](_0x50c06a[_0x72b5('0x36')]['sort']);_0x3a43a9[_0x72b5('0x41')]=qs[_0x72b5('0x38')](_[_0x72b5('0x52')](_0x50c06a[_0x72b5('0x36')],_0xf0fc6d['filters']));if(_0x50c06a['query'][_0x72b5('0x43')]){_0x3a43a9[_0x72b5('0x41')]=_[_0x72b5('0x42')](_0x3a43a9[_0x72b5('0x41')],{'$or':_[_0x72b5('0x31')](_0x3a43a9[_0x72b5('0x3a')],function(_0x4203ba){var _0x569321={};_0x569321[_0x4203ba]={'$like':'%'+_0x50c06a[_0x72b5('0x36')][_0x72b5('0x43')]+'%'};return _0x569321;})});}_0x3a43a9=_[_0x72b5('0x42')]({},_0x3a43a9,_0x50c06a[_0x72b5('0x44')]);var _0x48b647={'where':_0x3a43a9['where']};return db['VoiceQueueReport'][_0x72b5('0x24')](_0x48b647)[_0x72b5('0x2a')](function(_0x35c9e3){_0xc89eb1[_0x72b5('0x24')]=_0x35c9e3;if(_0x50c06a[_0x72b5('0x36')]['includeAll']){_0x3a43a9[_0x72b5('0x47')]=[{'all':!![]}];}return db[_0x72b5('0x45')][_0x72b5('0x48')](_0x3a43a9);})[_0x72b5('0x2a')](function(_0x3e950a){_0xc89eb1[_0x72b5('0x49')]=_0x3e950a;return _0xc89eb1;})[_0x72b5('0x2a')](respondWithFilteredResult(_0x3fe9c5,_0x3a43a9,'getVoiceQueuesReport'))[_0x72b5('0x4a')](handleError(_0x3fe9c5,null,_0x72b5('0x51')));};