Built motion from commit (unavailable).|2.4.9
[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 _0x4b84=['create','body','describe','getVoiceQueuesReport','html-pdf','eml-format','fast-json-patch','bluebird','mustache','util','ejs','squel','jsforce','querystring','papaparse','ioredis','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','defaults','redis','socket.io-emitter','./voiceQueueReport.socket','register','status','end','offset','set','Content-Range','json','apply','reject','save','update','then','destroy','error','name','index','model','keys','query','filters','intersection','attributes','fields','length','nolimit','limit','order','sort','where','pick','filter','merge','map','type','key','VIRTUAL','field','options','count','includeAll','include','VoiceQueueReport','findAll','rows','catch','show','params','rawAttributes','find'];(function(_0x40a045,_0x516f0e){var _0x1a687c=function(_0x48c9fe){while(--_0x48c9fe){_0x40a045['push'](_0x40a045['shift']());}};_0x1a687c(++_0x516f0e);}(_0x4b84,0x1cc));var _0x44b8=function(_0x37ded3,_0x371ebb){_0x37ded3=_0x37ded3-0x0;var _0x51e49e=_0x4b84[_0x37ded3];return _0x51e49e;};'use strict';var pdf=require(_0x44b8('0x0'));var emlformat=require(_0x44b8('0x1'));var rimraf=require('rimraf');var zipdir=require('zip-dir');var jsonpatch=require(_0x44b8('0x2'));var rp=require('request-promise');var moment=require('moment');var BPromise=require(_0x44b8('0x3'));var Mustache=require(_0x44b8('0x4'));var util=require(_0x44b8('0x5'));var path=require('path');var sox=require('sox');var csv=require('to-csv');var ejs=require(_0x44b8('0x6'));var fs=require('fs');var _=require('lodash');var squel=require(_0x44b8('0x7'));var crypto=require('crypto');var jsforce=require(_0x44b8('0x8'));var deskjs=require('desk.js');var toCsv=require('to-csv');var querystring=require(_0x44b8('0x9'));var Papa=require(_0x44b8('0xa'));var Redis=require(_0x44b8('0xb'));var authService=require('../../components/auth/service');var qs=require(_0x44b8('0xc'));var hardwareService=require(_0x44b8('0xd'));var logger=require(_0x44b8('0xe'))(_0x44b8('0xf'));var utils=require(_0x44b8('0x10'));var config=require(_0x44b8('0x11'));var db=require(_0x44b8('0x12'))['db'];config['redis']=_[_0x44b8('0x13')](config[_0x44b8('0x14')],{'host':'localhost','port':0x18eb});var socket=require(_0x44b8('0x15'))(new Redis(config['redis']));require(_0x44b8('0x16'))[_0x44b8('0x17')](socket);function respondWithStatusCode(_0x4df670,_0x63e8f6){_0x63e8f6=_0x63e8f6||0xcc;return function(_0x4be54c){if(_0x4be54c){return _0x4df670['sendStatus'](_0x63e8f6);}return _0x4df670[_0x44b8('0x18')](_0x63e8f6)[_0x44b8('0x19')]();};}function respondWithResult(_0x1722da,_0x41ab46){_0x41ab46=_0x41ab46||0xc8;return function(_0x5e52f2){if(_0x5e52f2){return _0x1722da['status'](_0x41ab46)['json'](_0x5e52f2);}};}function respondWithFilteredResult(_0x3fe9fb,_0x5b7803){return function(_0x28ef36){if(_0x28ef36){var _0x31651b=_0x28ef36['count'],_0x55e258=_0x5b7803[_0x44b8('0x1a')],_0x36743e=_0x5b7803[_0x44b8('0x1a')]+_0x5b7803['limit'],_0xe3de8f;if(_0x36743e>=_0x31651b){_0x36743e=_0x31651b;_0xe3de8f=0xc8;}else{_0xe3de8f=0xce;}_0x3fe9fb[_0x44b8('0x18')](_0xe3de8f);return _0x3fe9fb[_0x44b8('0x1b')](_0x44b8('0x1c'),_0x55e258+'-'+_0x36743e+'/'+_0x31651b)[_0x44b8('0x1d')](_0x28ef36);}return null;};}function patchUpdates(_0x102ef9){return function(_0x369c09){try{jsonpatch[_0x44b8('0x1e')](_0x369c09,_0x102ef9,!![]);}catch(_0x9b0536){return BPromise[_0x44b8('0x1f')](_0x9b0536);}return _0x369c09[_0x44b8('0x20')]();};}function saveUpdates(_0x1d642b,_0x14996c){return function(_0x48327e){if(_0x48327e){return _0x48327e[_0x44b8('0x21')](_0x1d642b)[_0x44b8('0x22')](function(_0x416b34){return _0x416b34;});}return null;};}function removeEntity(_0x1418db,_0x305a5c){return function(_0x51a34a){if(_0x51a34a){return _0x51a34a[_0x44b8('0x23')]()['then'](function(){_0x1418db[_0x44b8('0x18')](0xcc)[_0x44b8('0x19')]();});}};}function handleEntityNotFound(_0x25a0c1,_0x47689e){return function(_0x230a3d){if(!_0x230a3d){_0x25a0c1['sendStatus'](0x194);}return _0x230a3d;};}function handleError(_0x474f01,_0x502acf){_0x502acf=_0x502acf||0x1f4;return function(_0x41d673){logger[_0x44b8('0x24')](_0x41d673['stack']);if(_0x41d673[_0x44b8('0x25')]){delete _0x41d673[_0x44b8('0x25')];}_0x474f01[_0x44b8('0x18')](_0x502acf)['send'](_0x41d673);};}exports[_0x44b8('0x26')]=function(_0x242342,_0x53d9c7){var _0x2e0174={},_0x4a182d={},_0xfb0028={'count':0x0,'rows':[]};var _0x5a544c=db['VoiceQueueReport']['rawAttributes'];_0x4a182d[_0x44b8('0x27')]=_[_0x44b8('0x28')](_0x5a544c);_0x4a182d[_0x44b8('0x29')]=_[_0x44b8('0x28')](_0x242342[_0x44b8('0x29')]);_0x4a182d[_0x44b8('0x2a')]=_[_0x44b8('0x2b')](_0x4a182d[_0x44b8('0x27')],_0x4a182d[_0x44b8('0x29')]);_0x2e0174[_0x44b8('0x2c')]=_[_0x44b8('0x2b')](_0x4a182d[_0x44b8('0x27')],qs[_0x44b8('0x2d')](_0x242342['query'][_0x44b8('0x2d')]));_0x2e0174['attributes']=_0x2e0174[_0x44b8('0x2c')][_0x44b8('0x2e')]?_0x2e0174[_0x44b8('0x2c')]:_0x4a182d[_0x44b8('0x27')];if(!_0x242342[_0x44b8('0x29')]['hasOwnProperty'](_0x44b8('0x2f'))){_0x2e0174[_0x44b8('0x30')]=qs[_0x44b8('0x30')](_0x242342[_0x44b8('0x29')][_0x44b8('0x30')]);_0x2e0174['offset']=qs[_0x44b8('0x1a')](_0x242342[_0x44b8('0x29')][_0x44b8('0x1a')]);}_0x2e0174[_0x44b8('0x31')]=qs[_0x44b8('0x32')](_0x242342[_0x44b8('0x29')][_0x44b8('0x32')]);_0x2e0174[_0x44b8('0x33')]=qs[_0x44b8('0x2a')](_[_0x44b8('0x34')](_0x242342[_0x44b8('0x29')],_0x4a182d[_0x44b8('0x2a')]));if(_0x242342[_0x44b8('0x29')][_0x44b8('0x35')]){_0x2e0174[_0x44b8('0x33')]=_[_0x44b8('0x36')](_0x2e0174[_0x44b8('0x33')],{'$or':_[_0x44b8('0x37')](_0x5a544c,function(_0x28faa9){if(_0x28faa9[_0x44b8('0x38')][_0x44b8('0x39')]!==_0x44b8('0x3a')){var _0x59848c={};_0x59848c[_0x28faa9[_0x44b8('0x3b')]]={'$like':'%'+_0x242342[_0x44b8('0x29')]['filter']+'%'};return _0x59848c;}})});}_0x2e0174=_[_0x44b8('0x36')]({},_0x2e0174,_0x242342[_0x44b8('0x3c')]);var _0x6658be={'where':_0x2e0174[_0x44b8('0x33')]};return db['VoiceQueueReport'][_0x44b8('0x3d')](_0x6658be)[_0x44b8('0x22')](function(_0x3611b4){_0xfb0028[_0x44b8('0x3d')]=_0x3611b4;if(_0x242342[_0x44b8('0x29')][_0x44b8('0x3e')]){_0x2e0174[_0x44b8('0x3f')]=[{'all':!![]}];}return db[_0x44b8('0x40')][_0x44b8('0x41')](_0x2e0174);})[_0x44b8('0x22')](function(_0x1c9983){_0xfb0028[_0x44b8('0x42')]=_0x1c9983;return _0xfb0028;})[_0x44b8('0x22')](respondWithFilteredResult(_0x53d9c7,_0x2e0174))[_0x44b8('0x43')](handleError(_0x53d9c7,null));};exports[_0x44b8('0x44')]=function(_0x29b43f,_0x57d8c4){var _0x12a0a4={'raw':![],'where':{'id':_0x29b43f[_0x44b8('0x45')]['id']}},_0x43e43a={};_0x43e43a['model']=_[_0x44b8('0x28')](db[_0x44b8('0x40')][_0x44b8('0x46')]);_0x43e43a['query']=_[_0x44b8('0x28')](_0x29b43f[_0x44b8('0x29')]);_0x43e43a[_0x44b8('0x2a')]=_[_0x44b8('0x2b')](_0x43e43a[_0x44b8('0x27')],_0x43e43a['query']);_0x12a0a4['attributes']=_[_0x44b8('0x2b')](_0x43e43a[_0x44b8('0x27')],qs[_0x44b8('0x2d')](_0x29b43f[_0x44b8('0x29')][_0x44b8('0x2d')]));_0x12a0a4[_0x44b8('0x2c')]=_0x12a0a4[_0x44b8('0x2c')][_0x44b8('0x2e')]?_0x12a0a4[_0x44b8('0x2c')]:_0x43e43a[_0x44b8('0x27')];if(_0x29b43f[_0x44b8('0x29')][_0x44b8('0x3e')]){_0x12a0a4[_0x44b8('0x3f')]=[{'all':!![]}];}_0x12a0a4=_[_0x44b8('0x36')]({},_0x12a0a4,_0x29b43f[_0x44b8('0x3c')]);return db[_0x44b8('0x40')][_0x44b8('0x47')](_0x12a0a4)[_0x44b8('0x22')](handleEntityNotFound(_0x57d8c4,null))[_0x44b8('0x22')](respondWithResult(_0x57d8c4,null))['catch'](handleError(_0x57d8c4,null));};exports['create']=function(_0x3b1b12,_0x1df74b){return db[_0x44b8('0x40')][_0x44b8('0x48')](_0x3b1b12[_0x44b8('0x49')],{})[_0x44b8('0x22')](respondWithResult(_0x1df74b,0xc9))[_0x44b8('0x43')](handleError(_0x1df74b,null));};exports['update']=function(_0x156070,_0x53edca){if(_0x156070[_0x44b8('0x49')]['id']){delete _0x156070[_0x44b8('0x49')]['id'];}return db[_0x44b8('0x40')][_0x44b8('0x47')]({'where':{'id':_0x156070[_0x44b8('0x45')]['id']}})[_0x44b8('0x22')](handleEntityNotFound(_0x53edca,null))['then'](saveUpdates(_0x156070[_0x44b8('0x49')],null))[_0x44b8('0x22')](respondWithResult(_0x53edca,null))[_0x44b8('0x43')](handleError(_0x53edca,null));};exports[_0x44b8('0x23')]=function(_0x4ccc77,_0x4e4ed1){return db[_0x44b8('0x40')][_0x44b8('0x47')]({'where':{'id':_0x4ccc77[_0x44b8('0x45')]['id']}})[_0x44b8('0x22')](handleEntityNotFound(_0x4e4ed1,null))[_0x44b8('0x22')](removeEntity(_0x4e4ed1,null))['catch'](handleError(_0x4e4ed1,null));};exports[_0x44b8('0x4a')]=function(_0x450715,_0x2c5c27){return db[_0x44b8('0x40')][_0x44b8('0x4a')]()['then'](respondWithResult(_0x2c5c27,null))['catch'](handleError(_0x2c5c27,null));};exports[_0x44b8('0x4b')]=function(_0x4eb344,_0x2d9f89){var _0x5785ef={},_0x40164d={},_0x434d6a={'count':0x0,'rows':[]};_0x40164d[_0x44b8('0x27')]=_[_0x44b8('0x28')](db[_0x44b8('0x40')][_0x44b8('0x46')]);_0x40164d[_0x44b8('0x29')]=_['keys'](_0x4eb344[_0x44b8('0x29')]);_0x40164d[_0x44b8('0x2a')]=_[_0x44b8('0x2b')](_0x40164d['model'],_0x40164d[_0x44b8('0x29')]);_0x5785ef[_0x44b8('0x2c')]=_[_0x44b8('0x2b')](_0x40164d[_0x44b8('0x27')],qs['fields'](_0x4eb344[_0x44b8('0x29')][_0x44b8('0x2d')]));_0x5785ef['attributes']=_0x5785ef[_0x44b8('0x2c')][_0x44b8('0x2e')]?_0x5785ef[_0x44b8('0x2c')]:_0x40164d[_0x44b8('0x27')];if(!_0x4eb344[_0x44b8('0x29')]['hasOwnProperty']('nolimit')){_0x5785ef[_0x44b8('0x30')]=qs[_0x44b8('0x30')](_0x4eb344[_0x44b8('0x29')][_0x44b8('0x30')]);_0x5785ef[_0x44b8('0x1a')]=qs[_0x44b8('0x1a')](_0x4eb344[_0x44b8('0x29')][_0x44b8('0x1a')]);}_0x5785ef[_0x44b8('0x31')]=qs[_0x44b8('0x32')](_0x4eb344[_0x44b8('0x29')][_0x44b8('0x32')]);_0x5785ef['where']=qs[_0x44b8('0x2a')](_[_0x44b8('0x34')](_0x4eb344[_0x44b8('0x29')],_0x40164d[_0x44b8('0x2a')]));if(_0x4eb344[_0x44b8('0x29')][_0x44b8('0x35')]){_0x5785ef[_0x44b8('0x33')]=_[_0x44b8('0x36')](_0x5785ef[_0x44b8('0x33')],{'$or':_[_0x44b8('0x37')](_0x5785ef[_0x44b8('0x2c')],function(_0x15bcba){var _0x1da152={};_0x1da152[_0x15bcba]={'$like':'%'+_0x4eb344[_0x44b8('0x29')][_0x44b8('0x35')]+'%'};return _0x1da152;})});}_0x5785ef=_[_0x44b8('0x36')]({},_0x5785ef,_0x4eb344[_0x44b8('0x3c')]);var _0x20e563={'where':_0x5785ef['where']};return db[_0x44b8('0x40')][_0x44b8('0x3d')](_0x20e563)[_0x44b8('0x22')](function(_0x2b37e){_0x434d6a[_0x44b8('0x3d')]=_0x2b37e;if(_0x4eb344[_0x44b8('0x29')][_0x44b8('0x3e')]){_0x5785ef['include']=[{'all':!![]}];}return db[_0x44b8('0x40')][_0x44b8('0x41')](_0x5785ef);})['then'](function(_0x2a95f6){_0x434d6a[_0x44b8('0x42')]=_0x2a95f6;return _0x434d6a;})['then'](respondWithFilteredResult(_0x2d9f89,_0x5785ef,_0x44b8('0x4b')))[_0x44b8('0x43')](handleError(_0x2d9f89,null,_0x44b8('0x4b')));};