53b27f1f622ccd048fa7114ab5af8ea0f6237129
[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 _0x7cc1=['intersection','attributes','fields','length','hasOwnProperty','order','sort','where','pick','filter','merge','type','options','VoiceQueueReport','include','findAll','rows','catch','params','includeAll','find','create','body','describe','getVoiceQueuesReport','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','sox','to-csv','ejs','fs-extra','lodash','crypto','desk.js','querystring','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','localhost','socket.io-emitter','redis','./voiceQueueReport.socket','register','sendStatus','status','end','json','offset','undefined','limit','count','set','Content-Range','apply','reject','save','update','then','destroy','name','index','map','rawAttributes','fieldName','key','model','keys','query','filters'];(function(_0x56cc5c,_0xdf97ee){var _0xc73ea9=function(_0x2f765e){while(--_0x2f765e){_0x56cc5c['push'](_0x56cc5c['shift']());}};_0xc73ea9(++_0xdf97ee);}(_0x7cc1,0x10f));var _0x17cc=function(_0x7c4fba,_0x5dfc94){_0x7c4fba=_0x7c4fba-0x0;var _0x422614=_0x7cc1[_0x7c4fba];return _0x422614;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x17cc('0x0'));var zipdir=require(_0x17cc('0x1'));var jsonpatch=require(_0x17cc('0x2'));var rp=require(_0x17cc('0x3'));var moment=require(_0x17cc('0x4'));var BPromise=require(_0x17cc('0x5'));var Mustache=require(_0x17cc('0x6'));var util=require(_0x17cc('0x7'));var path=require('path');var sox=require(_0x17cc('0x8'));var csv=require(_0x17cc('0x9'));var ejs=require(_0x17cc('0xa'));var fs=require('fs');var fs_extra=require(_0x17cc('0xb'));var _=require(_0x17cc('0xc'));var squel=require('squel');var crypto=require(_0x17cc('0xd'));var jsforce=require('jsforce');var deskjs=require(_0x17cc('0xe'));var toCsv=require(_0x17cc('0x9'));var querystring=require(_0x17cc('0xf'));var Papa=require('papaparse');var Redis=require(_0x17cc('0x10'));var authService=require(_0x17cc('0x11'));var qs=require('../../components/parsers/qs');var as=require(_0x17cc('0x12'));var hardwareService=require(_0x17cc('0x13'));var logger=require(_0x17cc('0x14'))(_0x17cc('0x15'));var utils=require(_0x17cc('0x16'));var config=require(_0x17cc('0x17'));var licenseUtil=require(_0x17cc('0x18'));var db=require(_0x17cc('0x19'))['db'];config['redis']=_['defaults'](config['redis'],{'host':_0x17cc('0x1a'),'port':0x18eb});var socket=require(_0x17cc('0x1b'))(new Redis(config[_0x17cc('0x1c')]));require(_0x17cc('0x1d'))[_0x17cc('0x1e')](socket);function respondWithStatusCode(_0x257e77,_0x44a29c){_0x44a29c=_0x44a29c||0xcc;return function(_0x20650e){if(_0x20650e){return _0x257e77[_0x17cc('0x1f')](_0x44a29c);}return _0x257e77[_0x17cc('0x20')](_0x44a29c)[_0x17cc('0x21')]();};}function respondWithResult(_0x4cc193,_0x54723a){_0x54723a=_0x54723a||0xc8;return function(_0x1f885f){if(_0x1f885f){return _0x4cc193[_0x17cc('0x20')](_0x54723a)[_0x17cc('0x22')](_0x1f885f);}};}function respondWithFilteredResult(_0x7cc9ab,_0x12442f){return function(_0x1554ac){if(_0x1554ac){var _0x463f6d=typeof _0x12442f[_0x17cc('0x23')]===_0x17cc('0x24')&&typeof _0x12442f[_0x17cc('0x25')]===_0x17cc('0x24');var _0x103033=_0x1554ac[_0x17cc('0x26')];var _0x39e451=_0x463f6d?0x0:_0x12442f['offset'];var _0xa6e255=_0x463f6d?_0x1554ac[_0x17cc('0x26')]:_0x12442f[_0x17cc('0x23')]+_0x12442f[_0x17cc('0x25')];var _0x4d7ccb;if(_0xa6e255>=_0x103033){_0xa6e255=_0x103033;_0x4d7ccb=0xc8;}else{_0x4d7ccb=0xce;}_0x7cc9ab[_0x17cc('0x20')](_0x4d7ccb);return _0x7cc9ab[_0x17cc('0x27')](_0x17cc('0x28'),_0x39e451+'-'+_0xa6e255+'/'+_0x103033)[_0x17cc('0x22')](_0x1554ac);}return null;};}function patchUpdates(_0x304f62){return function(_0x228f71){try{jsonpatch[_0x17cc('0x29')](_0x228f71,_0x304f62,!![]);}catch(_0x49736b){return BPromise[_0x17cc('0x2a')](_0x49736b);}return _0x228f71[_0x17cc('0x2b')]();};}function saveUpdates(_0x3fdf0b,_0x1d610c){return function(_0x592fe5){if(_0x592fe5){return _0x592fe5[_0x17cc('0x2c')](_0x3fdf0b)[_0x17cc('0x2d')](function(_0x3d8f38){return _0x3d8f38;});}return null;};}function removeEntity(_0x51b25c,_0x52c5b2){return function(_0x4c5a18){if(_0x4c5a18){return _0x4c5a18[_0x17cc('0x2e')]()['then'](function(){_0x51b25c['status'](0xcc)['end']();});}};}function handleEntityNotFound(_0x9a9897,_0x795897){return function(_0x33358f){if(!_0x33358f){_0x9a9897['sendStatus'](0x194);}return _0x33358f;};}function handleError(_0x490ca5,_0x4c17ec){_0x4c17ec=_0x4c17ec||0x1f4;return function(_0x4a6496){logger['error'](_0x4a6496['stack']);if(_0x4a6496[_0x17cc('0x2f')]){delete _0x4a6496['name'];}_0x490ca5[_0x17cc('0x20')](_0x4c17ec)['send'](_0x4a6496);};}exports[_0x17cc('0x30')]=function(_0x52bc04,_0x8fb6f9){var _0x2b384b={},_0x269561={},_0x4956c4={'count':0x0,'rows':[]};var _0xece126=_[_0x17cc('0x31')](db['VoiceQueueReport'][_0x17cc('0x32')],function(_0x2740c2){return{'name':_0x2740c2[_0x17cc('0x33')],'type':_0x2740c2['type'][_0x17cc('0x34')]};});_0x269561[_0x17cc('0x35')]=_['map'](_0xece126,'name');_0x269561['query']=_[_0x17cc('0x36')](_0x52bc04[_0x17cc('0x37')]);_0x269561[_0x17cc('0x38')]=_[_0x17cc('0x39')](_0x269561[_0x17cc('0x35')],_0x269561[_0x17cc('0x37')]);_0x2b384b[_0x17cc('0x3a')]=_['intersection'](_0x269561[_0x17cc('0x35')],qs['fields'](_0x52bc04[_0x17cc('0x37')][_0x17cc('0x3b')]));_0x2b384b[_0x17cc('0x3a')]=_0x2b384b[_0x17cc('0x3a')][_0x17cc('0x3c')]?_0x2b384b['attributes']:_0x269561[_0x17cc('0x35')];if(!_0x52bc04[_0x17cc('0x37')][_0x17cc('0x3d')]('nolimit')){_0x2b384b['limit']=qs[_0x17cc('0x25')](_0x52bc04[_0x17cc('0x37')][_0x17cc('0x25')]);_0x2b384b['offset']=qs['offset'](_0x52bc04[_0x17cc('0x37')]['offset']);}_0x2b384b[_0x17cc('0x3e')]=qs[_0x17cc('0x3f')](_0x52bc04[_0x17cc('0x37')][_0x17cc('0x3f')]);_0x2b384b[_0x17cc('0x40')]=qs['filters'](_[_0x17cc('0x41')](_0x52bc04[_0x17cc('0x37')],_0x269561[_0x17cc('0x38')]),_0xece126);if(_0x52bc04[_0x17cc('0x37')][_0x17cc('0x42')]){_0x2b384b[_0x17cc('0x40')]=_[_0x17cc('0x43')](_0x2b384b[_0x17cc('0x40')],{'$or':_[_0x17cc('0x31')](_0xece126,function(_0x2d045c){if(_0x2d045c[_0x17cc('0x44')]!=='VIRTUAL'){var _0x527108={};_0x527108[_0x2d045c[_0x17cc('0x2f')]]={'$like':'%'+_0x52bc04[_0x17cc('0x37')]['filter']+'%'};return _0x527108;}})});}_0x2b384b=_[_0x17cc('0x43')]({},_0x2b384b,_0x52bc04[_0x17cc('0x45')]);var _0x609a1a={'where':_0x2b384b['where']};return db[_0x17cc('0x46')][_0x17cc('0x26')](_0x609a1a)[_0x17cc('0x2d')](function(_0x1fa7a6){_0x4956c4[_0x17cc('0x26')]=_0x1fa7a6;if(_0x52bc04[_0x17cc('0x37')]['includeAll']){_0x2b384b[_0x17cc('0x47')]=[{'all':!![]}];}return db[_0x17cc('0x46')][_0x17cc('0x48')](_0x2b384b);})[_0x17cc('0x2d')](function(_0x112aca){_0x4956c4[_0x17cc('0x49')]=_0x112aca;return _0x4956c4;})[_0x17cc('0x2d')](respondWithFilteredResult(_0x8fb6f9,_0x2b384b))[_0x17cc('0x4a')](handleError(_0x8fb6f9,null));};exports['show']=function(_0x3f1e9f,_0x591c11){var _0x4e684c={'raw':![],'where':{'id':_0x3f1e9f[_0x17cc('0x4b')]['id']}},_0x3e7060={};_0x3e7060[_0x17cc('0x35')]=_[_0x17cc('0x36')](db[_0x17cc('0x46')][_0x17cc('0x32')]);_0x3e7060['query']=_[_0x17cc('0x36')](_0x3f1e9f[_0x17cc('0x37')]);_0x3e7060['filters']=_[_0x17cc('0x39')](_0x3e7060[_0x17cc('0x35')],_0x3e7060[_0x17cc('0x37')]);_0x4e684c[_0x17cc('0x3a')]=_[_0x17cc('0x39')](_0x3e7060[_0x17cc('0x35')],qs[_0x17cc('0x3b')](_0x3f1e9f[_0x17cc('0x37')][_0x17cc('0x3b')]));_0x4e684c[_0x17cc('0x3a')]=_0x4e684c[_0x17cc('0x3a')][_0x17cc('0x3c')]?_0x4e684c[_0x17cc('0x3a')]:_0x3e7060[_0x17cc('0x35')];if(_0x3f1e9f['query'][_0x17cc('0x4c')]){_0x4e684c['include']=[{'all':!![]}];}_0x4e684c=_[_0x17cc('0x43')]({},_0x4e684c,_0x3f1e9f[_0x17cc('0x45')]);return db[_0x17cc('0x46')][_0x17cc('0x4d')](_0x4e684c)['then'](handleEntityNotFound(_0x591c11,null))[_0x17cc('0x2d')](respondWithResult(_0x591c11,null))[_0x17cc('0x4a')](handleError(_0x591c11,null));};exports['create']=function(_0x413fd2,_0x177cd0){return db[_0x17cc('0x46')][_0x17cc('0x4e')](_0x413fd2[_0x17cc('0x4f')],{})[_0x17cc('0x2d')](respondWithResult(_0x177cd0,0xc9))['catch'](handleError(_0x177cd0,null));};exports[_0x17cc('0x2c')]=function(_0xbb8240,_0x2b6f3e){if(_0xbb8240['body']['id']){delete _0xbb8240[_0x17cc('0x4f')]['id'];}return db[_0x17cc('0x46')][_0x17cc('0x4d')]({'where':{'id':_0xbb8240['params']['id']}})[_0x17cc('0x2d')](handleEntityNotFound(_0x2b6f3e,null))[_0x17cc('0x2d')](saveUpdates(_0xbb8240[_0x17cc('0x4f')],null))[_0x17cc('0x2d')](respondWithResult(_0x2b6f3e,null))[_0x17cc('0x4a')](handleError(_0x2b6f3e,null));};exports['destroy']=function(_0x25ad59,_0xbfa911){return db[_0x17cc('0x46')]['find']({'where':{'id':_0x25ad59['params']['id']}})[_0x17cc('0x2d')](handleEntityNotFound(_0xbfa911,null))[_0x17cc('0x2d')](removeEntity(_0xbfa911,null))[_0x17cc('0x4a')](handleError(_0xbfa911,null));};exports[_0x17cc('0x50')]=function(_0x30abc2,_0x53ee79){return db['VoiceQueueReport']['describe']()[_0x17cc('0x2d')](respondWithResult(_0x53ee79,null))[_0x17cc('0x4a')](handleError(_0x53ee79,null));};exports[_0x17cc('0x51')]=function(_0x1cd54a,_0x1a94e2){var _0xd2a9e1={},_0x2ab036={},_0x3eaaca={'count':0x0,'rows':[]};_0x2ab036[_0x17cc('0x35')]=_['keys'](db[_0x17cc('0x46')]['rawAttributes']);_0x2ab036['query']=_['keys'](_0x1cd54a[_0x17cc('0x37')]);_0x2ab036[_0x17cc('0x38')]=_[_0x17cc('0x39')](_0x2ab036[_0x17cc('0x35')],_0x2ab036[_0x17cc('0x37')]);_0xd2a9e1[_0x17cc('0x3a')]=_[_0x17cc('0x39')](_0x2ab036[_0x17cc('0x35')],qs[_0x17cc('0x3b')](_0x1cd54a[_0x17cc('0x37')]['fields']));_0xd2a9e1[_0x17cc('0x3a')]=_0xd2a9e1[_0x17cc('0x3a')][_0x17cc('0x3c')]?_0xd2a9e1['attributes']:_0x2ab036[_0x17cc('0x35')];if(!_0x1cd54a[_0x17cc('0x37')][_0x17cc('0x3d')]('nolimit')){_0xd2a9e1[_0x17cc('0x25')]=qs[_0x17cc('0x25')](_0x1cd54a[_0x17cc('0x37')][_0x17cc('0x25')]);_0xd2a9e1[_0x17cc('0x23')]=qs['offset'](_0x1cd54a['query'][_0x17cc('0x23')]);}_0xd2a9e1['order']=qs[_0x17cc('0x3f')](_0x1cd54a[_0x17cc('0x37')]['sort']);_0xd2a9e1[_0x17cc('0x40')]=qs[_0x17cc('0x38')](_[_0x17cc('0x41')](_0x1cd54a[_0x17cc('0x37')],_0x2ab036[_0x17cc('0x38')]));if(_0x1cd54a[_0x17cc('0x37')][_0x17cc('0x42')]){_0xd2a9e1[_0x17cc('0x40')]=_['merge'](_0xd2a9e1[_0x17cc('0x40')],{'$or':_[_0x17cc('0x31')](_0xd2a9e1['attributes'],function(_0xb8f1a4){var _0x2f770a={};_0x2f770a[_0xb8f1a4]={'$like':'%'+_0x1cd54a[_0x17cc('0x37')]['filter']+'%'};return _0x2f770a;})});}_0xd2a9e1=_[_0x17cc('0x43')]({},_0xd2a9e1,_0x1cd54a['options']);var _0x485124={'where':_0xd2a9e1[_0x17cc('0x40')]};return db[_0x17cc('0x46')][_0x17cc('0x26')](_0x485124)['then'](function(_0x5e58af){_0x3eaaca[_0x17cc('0x26')]=_0x5e58af;if(_0x1cd54a[_0x17cc('0x37')][_0x17cc('0x4c')]){_0xd2a9e1[_0x17cc('0x47')]=[{'all':!![]}];}return db[_0x17cc('0x46')][_0x17cc('0x48')](_0xd2a9e1);})[_0x17cc('0x2d')](function(_0x2ec17e){_0x3eaaca[_0x17cc('0x49')]=_0x2ec17e;return _0x3eaaca;})[_0x17cc('0x2d')](respondWithFilteredResult(_0x1a94e2,_0xd2a9e1,_0x17cc('0x51')))[_0x17cc('0x4a')](handleError(_0x1a94e2,null,'getVoiceQueuesReport'));};