Built motion from commit (unavailable).|2.4.21
[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 _0x57ca=['then','destroy','error','stack','name','send','map','rawAttributes','fieldName','key','query','keys','filters','intersection','model','fields','attributes','nolimit','limit','order','sort','pick','filter','merge','where','VIRTUAL','includeAll','include','VoiceQueueReport','findAll','rows','params','length','options','find','catch','create','body','describe','eml-format','rimraf','fast-json-patch','request-promise','moment','bluebird','mustache','path','sox','to-csv','ejs','lodash','squel','crypto','jsforce','papaparse','ioredis','../../components/parsers/qs','../../config/license/hardware','../../config/logger','../../config/utils','../../mysqldb','redis','defaults','localhost','register','sendStatus','status','end','count','offset','json','apply','reject','save','update'];(function(_0x4bda62,_0x12f927){var _0x2e2978=function(_0x35ce06){while(--_0x35ce06){_0x4bda62['push'](_0x4bda62['shift']());}};_0x2e2978(++_0x12f927);}(_0x57ca,0x108));var _0xa57c=function(_0x4cb3cf,_0x438231){_0x4cb3cf=_0x4cb3cf-0x0;var _0x41cfef=_0x57ca[_0x4cb3cf];return _0x41cfef;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0xa57c('0x0'));var rimraf=require(_0xa57c('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0xa57c('0x2'));var rp=require(_0xa57c('0x3'));var moment=require(_0xa57c('0x4'));var BPromise=require(_0xa57c('0x5'));var Mustache=require(_0xa57c('0x6'));var util=require('util');var path=require(_0xa57c('0x7'));var sox=require(_0xa57c('0x8'));var csv=require(_0xa57c('0x9'));var ejs=require(_0xa57c('0xa'));var fs=require('fs');var _=require(_0xa57c('0xb'));var squel=require(_0xa57c('0xc'));var crypto=require(_0xa57c('0xd'));var jsforce=require(_0xa57c('0xe'));var deskjs=require('desk.js');var toCsv=require(_0xa57c('0x9'));var querystring=require('querystring');var Papa=require(_0xa57c('0xf'));var Redis=require(_0xa57c('0x10'));var authService=require('../../components/auth/service');var qs=require(_0xa57c('0x11'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xa57c('0x12'));var logger=require(_0xa57c('0x13'))('api');var utils=require(_0xa57c('0x14'));var config=require('../../config/environment');var db=require(_0xa57c('0x15'))['db'];config[_0xa57c('0x16')]=_[_0xa57c('0x17')](config[_0xa57c('0x16')],{'host':_0xa57c('0x18'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0xa57c('0x16')]));require('./voiceQueueReport.socket')[_0xa57c('0x19')](socket);function respondWithStatusCode(_0x3d5995,_0x30940d){_0x30940d=_0x30940d||0xcc;return function(_0x3821d2){if(_0x3821d2){return _0x3d5995[_0xa57c('0x1a')](_0x30940d);}return _0x3d5995[_0xa57c('0x1b')](_0x30940d)[_0xa57c('0x1c')]();};}function respondWithResult(_0x4b4bdb,_0x26607a){_0x26607a=_0x26607a||0xc8;return function(_0xdf7ff6){if(_0xdf7ff6){return _0x4b4bdb[_0xa57c('0x1b')](_0x26607a)['json'](_0xdf7ff6);}};}function respondWithFilteredResult(_0x2746a0,_0x5f33f1){return function(_0x3e7afa){if(_0x3e7afa){var _0x3d781d=_0x3e7afa[_0xa57c('0x1d')],_0x93462c=_0x5f33f1[_0xa57c('0x1e')],_0xe3d505=_0x5f33f1[_0xa57c('0x1e')]+_0x5f33f1['limit'],_0x1fd0d8;if(_0xe3d505>=_0x3d781d){_0xe3d505=_0x3d781d;_0x1fd0d8=0xc8;}else{_0x1fd0d8=0xce;}_0x2746a0[_0xa57c('0x1b')](_0x1fd0d8);return _0x2746a0['set']('Content-Range',_0x93462c+'-'+_0xe3d505+'/'+_0x3d781d)[_0xa57c('0x1f')](_0x3e7afa);}return null;};}function patchUpdates(_0xa5b314){return function(_0x3eee75){try{jsonpatch[_0xa57c('0x20')](_0x3eee75,_0xa5b314,!![]);}catch(_0x49242c){return BPromise[_0xa57c('0x21')](_0x49242c);}return _0x3eee75[_0xa57c('0x22')]();};}function saveUpdates(_0x34d1bc,_0x2213b2){return function(_0x3bb969){if(_0x3bb969){return _0x3bb969[_0xa57c('0x23')](_0x34d1bc)[_0xa57c('0x24')](function(_0x42038e){return _0x42038e;});}return null;};}function removeEntity(_0x2e99ed,_0xdf65dd){return function(_0x382a26){if(_0x382a26){return _0x382a26[_0xa57c('0x25')]()[_0xa57c('0x24')](function(){_0x2e99ed[_0xa57c('0x1b')](0xcc)[_0xa57c('0x1c')]();});}};}function handleEntityNotFound(_0x511a26,_0x2db443){return function(_0x5226d0){if(!_0x5226d0){_0x511a26[_0xa57c('0x1a')](0x194);}return _0x5226d0;};}function handleError(_0x5228b9,_0x315ad7){_0x315ad7=_0x315ad7||0x1f4;return function(_0x1e8e45){logger[_0xa57c('0x26')](_0x1e8e45[_0xa57c('0x27')]);if(_0x1e8e45[_0xa57c('0x28')]){delete _0x1e8e45[_0xa57c('0x28')];}_0x5228b9['status'](_0x315ad7)[_0xa57c('0x29')](_0x1e8e45);};}exports['index']=function(_0x54a18b,_0x257661){var _0x7d10ec={},_0x5a3e03={},_0x12898b={'count':0x0,'rows':[]};var _0x1ef331=_[_0xa57c('0x2a')](db['VoiceQueueReport'][_0xa57c('0x2b')],function(_0x58d46f){return{'name':_0x58d46f[_0xa57c('0x2c')],'type':_0x58d46f['type'][_0xa57c('0x2d')]};});_0x5a3e03['model']=_[_0xa57c('0x2a')](_0x1ef331,'name');_0x5a3e03[_0xa57c('0x2e')]=_[_0xa57c('0x2f')](_0x54a18b[_0xa57c('0x2e')]);_0x5a3e03[_0xa57c('0x30')]=_[_0xa57c('0x31')](_0x5a3e03[_0xa57c('0x32')],_0x5a3e03[_0xa57c('0x2e')]);_0x7d10ec['attributes']=_[_0xa57c('0x31')](_0x5a3e03['model'],qs[_0xa57c('0x33')](_0x54a18b[_0xa57c('0x2e')][_0xa57c('0x33')]));_0x7d10ec['attributes']=_0x7d10ec[_0xa57c('0x34')]['length']?_0x7d10ec[_0xa57c('0x34')]:_0x5a3e03['model'];if(!_0x54a18b[_0xa57c('0x2e')]['hasOwnProperty'](_0xa57c('0x35'))){_0x7d10ec[_0xa57c('0x36')]=qs['limit'](_0x54a18b[_0xa57c('0x2e')]['limit']);_0x7d10ec[_0xa57c('0x1e')]=qs['offset'](_0x54a18b[_0xa57c('0x2e')][_0xa57c('0x1e')]);}_0x7d10ec[_0xa57c('0x37')]=qs[_0xa57c('0x38')](_0x54a18b[_0xa57c('0x2e')][_0xa57c('0x38')]);_0x7d10ec['where']=qs['filters'](_[_0xa57c('0x39')](_0x54a18b[_0xa57c('0x2e')],_0x5a3e03[_0xa57c('0x30')]));if(_0x54a18b['query'][_0xa57c('0x3a')]){_0x7d10ec['where']=_[_0xa57c('0x3b')](_0x7d10ec[_0xa57c('0x3c')],{'$or':_['map'](_0x1ef331,function(_0x558cf7){if(_0x558cf7['type']!==_0xa57c('0x3d')){var _0x5d410b={};_0x5d410b[_0x558cf7[_0xa57c('0x28')]]={'$like':'%'+_0x54a18b[_0xa57c('0x2e')][_0xa57c('0x3a')]+'%'};return _0x5d410b;}})});}_0x7d10ec=_[_0xa57c('0x3b')]({},_0x7d10ec,_0x54a18b['options']);var _0x44b2a8={'where':_0x7d10ec[_0xa57c('0x3c')]};return db['VoiceQueueReport']['count'](_0x44b2a8)[_0xa57c('0x24')](function(_0x203375){_0x12898b['count']=_0x203375;if(_0x54a18b[_0xa57c('0x2e')][_0xa57c('0x3e')]){_0x7d10ec[_0xa57c('0x3f')]=[{'all':!![]}];}return db[_0xa57c('0x40')][_0xa57c('0x41')](_0x7d10ec);})[_0xa57c('0x24')](function(_0x5d210b){_0x12898b[_0xa57c('0x42')]=_0x5d210b;return _0x12898b;})['then'](respondWithFilteredResult(_0x257661,_0x7d10ec))['catch'](handleError(_0x257661,null));};exports['show']=function(_0x520383,_0x588199){var _0x39b20f={'raw':![],'where':{'id':_0x520383[_0xa57c('0x43')]['id']}},_0x32ed25={};_0x32ed25['model']=_['keys'](db['VoiceQueueReport'][_0xa57c('0x2b')]);_0x32ed25[_0xa57c('0x2e')]=_[_0xa57c('0x2f')](_0x520383[_0xa57c('0x2e')]);_0x32ed25[_0xa57c('0x30')]=_[_0xa57c('0x31')](_0x32ed25['model'],_0x32ed25[_0xa57c('0x2e')]);_0x39b20f[_0xa57c('0x34')]=_[_0xa57c('0x31')](_0x32ed25[_0xa57c('0x32')],qs[_0xa57c('0x33')](_0x520383[_0xa57c('0x2e')]['fields']));_0x39b20f[_0xa57c('0x34')]=_0x39b20f[_0xa57c('0x34')][_0xa57c('0x44')]?_0x39b20f[_0xa57c('0x34')]:_0x32ed25[_0xa57c('0x32')];if(_0x520383['query'][_0xa57c('0x3e')]){_0x39b20f[_0xa57c('0x3f')]=[{'all':!![]}];}_0x39b20f=_[_0xa57c('0x3b')]({},_0x39b20f,_0x520383[_0xa57c('0x45')]);return db[_0xa57c('0x40')][_0xa57c('0x46')](_0x39b20f)['then'](handleEntityNotFound(_0x588199,null))[_0xa57c('0x24')](respondWithResult(_0x588199,null))[_0xa57c('0x47')](handleError(_0x588199,null));};exports[_0xa57c('0x48')]=function(_0x44ea0a,_0x2ea6af){return db[_0xa57c('0x40')]['create'](_0x44ea0a['body'],{})['then'](respondWithResult(_0x2ea6af,0xc9))['catch'](handleError(_0x2ea6af,null));};exports[_0xa57c('0x23')]=function(_0x49492f,_0x273a17){if(_0x49492f[_0xa57c('0x49')]['id']){delete _0x49492f['body']['id'];}return db[_0xa57c('0x40')][_0xa57c('0x46')]({'where':{'id':_0x49492f[_0xa57c('0x43')]['id']}})[_0xa57c('0x24')](handleEntityNotFound(_0x273a17,null))[_0xa57c('0x24')](saveUpdates(_0x49492f['body'],null))[_0xa57c('0x24')](respondWithResult(_0x273a17,null))[_0xa57c('0x47')](handleError(_0x273a17,null));};exports[_0xa57c('0x25')]=function(_0xd57bac,_0x2e4b84){return db['VoiceQueueReport'][_0xa57c('0x46')]({'where':{'id':_0xd57bac['params']['id']}})['then'](handleEntityNotFound(_0x2e4b84,null))[_0xa57c('0x24')](removeEntity(_0x2e4b84,null))[_0xa57c('0x47')](handleError(_0x2e4b84,null));};exports[_0xa57c('0x4a')]=function(_0x5bf336,_0x56d36c){return db[_0xa57c('0x40')][_0xa57c('0x4a')]()[_0xa57c('0x24')](respondWithResult(_0x56d36c,null))[_0xa57c('0x47')](handleError(_0x56d36c,null));};exports['getVoiceQueuesReport']=function(_0x3c450f,_0x2af354){var _0xe8c63e={},_0x59eadc={},_0x5d0655={'count':0x0,'rows':[]};_0x59eadc[_0xa57c('0x32')]=_[_0xa57c('0x2f')](db['VoiceQueueReport'][_0xa57c('0x2b')]);_0x59eadc[_0xa57c('0x2e')]=_[_0xa57c('0x2f')](_0x3c450f[_0xa57c('0x2e')]);_0x59eadc[_0xa57c('0x30')]=_[_0xa57c('0x31')](_0x59eadc[_0xa57c('0x32')],_0x59eadc['query']);_0xe8c63e['attributes']=_[_0xa57c('0x31')](_0x59eadc[_0xa57c('0x32')],qs[_0xa57c('0x33')](_0x3c450f[_0xa57c('0x2e')][_0xa57c('0x33')]));_0xe8c63e[_0xa57c('0x34')]=_0xe8c63e[_0xa57c('0x34')][_0xa57c('0x44')]?_0xe8c63e['attributes']:_0x59eadc['model'];if(!_0x3c450f[_0xa57c('0x2e')]['hasOwnProperty'](_0xa57c('0x35'))){_0xe8c63e[_0xa57c('0x36')]=qs[_0xa57c('0x36')](_0x3c450f['query'][_0xa57c('0x36')]);_0xe8c63e['offset']=qs[_0xa57c('0x1e')](_0x3c450f['query'][_0xa57c('0x1e')]);}_0xe8c63e[_0xa57c('0x37')]=qs[_0xa57c('0x38')](_0x3c450f[_0xa57c('0x2e')]['sort']);_0xe8c63e[_0xa57c('0x3c')]=qs[_0xa57c('0x30')](_[_0xa57c('0x39')](_0x3c450f[_0xa57c('0x2e')],_0x59eadc[_0xa57c('0x30')]));if(_0x3c450f['query'][_0xa57c('0x3a')]){_0xe8c63e[_0xa57c('0x3c')]=_[_0xa57c('0x3b')](_0xe8c63e[_0xa57c('0x3c')],{'$or':_[_0xa57c('0x2a')](_0xe8c63e[_0xa57c('0x34')],function(_0x143ec3){var _0x419527={};_0x419527[_0x143ec3]={'$like':'%'+_0x3c450f[_0xa57c('0x2e')][_0xa57c('0x3a')]+'%'};return _0x419527;})});}_0xe8c63e=_['merge']({},_0xe8c63e,_0x3c450f[_0xa57c('0x45')]);var _0x297518={'where':_0xe8c63e[_0xa57c('0x3c')]};return db[_0xa57c('0x40')][_0xa57c('0x1d')](_0x297518)[_0xa57c('0x24')](function(_0x5440c2){_0x5d0655[_0xa57c('0x1d')]=_0x5440c2;if(_0x3c450f[_0xa57c('0x2e')]['includeAll']){_0xe8c63e[_0xa57c('0x3f')]=[{'all':!![]}];}return db[_0xa57c('0x40')][_0xa57c('0x41')](_0xe8c63e);})[_0xa57c('0x24')](function(_0x40c0a0){_0x5d0655[_0xa57c('0x42')]=_0x40c0a0;return _0x5d0655;})[_0xa57c('0x24')](respondWithFilteredResult(_0x2af354,_0xe8c63e,'getVoiceQueuesReport'))[_0xa57c('0x47')](handleError(_0x2af354,null,'getVoiceQueuesReport'));};