e2f21532839ee912099b6150e1f935a7fe9044f4
[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 _0xb0ae=['../../config/license/hardware','../../config/logger','api','../../config/environment','../../config/license/util','../../mysqldb','defaults','redis','socket.io-emitter','./voiceQueueReport.socket','register','sendStatus','status','end','json','offset','undefined','count','apply','reject','save','then','destroy','stack','name','send','map','VoiceQueueReport','rawAttributes','type','key','model','query','keys','intersection','attributes','fields','length','hasOwnProperty','nolimit','limit','sort','where','filters','merge','VIRTUAL','filter','options','includeAll','findAll','catch','params','include','find','create','body','update','describe','order','pick','rows','getVoiceQueuesReport','eml-format','zip-dir','fast-json-patch','moment','bluebird','util','path','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch'];(function(_0x3f993e,_0x2d5757){var _0x39c135=function(_0x39e00b){while(--_0x39e00b){_0x3f993e['push'](_0x3f993e['shift']());}};_0x39c135(++_0x2d5757);}(_0xb0ae,0xe0));var _0xeb0a=function(_0x5d72b0,_0x536f75){_0x5d72b0=_0x5d72b0-0x0;var _0x4eac19=_0xb0ae[_0x5d72b0];return _0x4eac19;};'use strict';var emlformat=require(_0xeb0a('0x0'));var rimraf=require('rimraf');var zipdir=require(_0xeb0a('0x1'));var jsonpatch=require(_0xeb0a('0x2'));var rp=require('request-promise');var moment=require(_0xeb0a('0x3'));var BPromise=require(_0xeb0a('0x4'));var Mustache=require('mustache');var util=require(_0xeb0a('0x5'));var path=require(_0xeb0a('0x6'));var sox=require('sox');var csv=require(_0xeb0a('0x7'));var ejs=require(_0xeb0a('0x8'));var fs=require('fs');var fs_extra=require(_0xeb0a('0x9'));var _=require(_0xeb0a('0xa'));var squel=require(_0xeb0a('0xb'));var crypto=require(_0xeb0a('0xc'));var jsforce=require(_0xeb0a('0xd'));var deskjs=require('desk.js');var toCsv=require('to-csv');var querystring=require(_0xeb0a('0xe'));var Papa=require(_0xeb0a('0xf'));var Redis=require('ioredis');var authService=require(_0xeb0a('0x10'));var qs=require(_0xeb0a('0x11'));var as=require(_0xeb0a('0x12'));var hardwareService=require(_0xeb0a('0x13'));var logger=require(_0xeb0a('0x14'))(_0xeb0a('0x15'));var utils=require('../../config/utils');var config=require(_0xeb0a('0x16'));var licenseUtil=require(_0xeb0a('0x17'));var db=require(_0xeb0a('0x18'))['db'];config['redis']=_[_0xeb0a('0x19')](config[_0xeb0a('0x1a')],{'host':'localhost','port':0x18eb});var socket=require(_0xeb0a('0x1b'))(new Redis(config[_0xeb0a('0x1a')]));require(_0xeb0a('0x1c'))[_0xeb0a('0x1d')](socket);function respondWithStatusCode(_0x3fd4da,_0x225aa3){_0x225aa3=_0x225aa3||0xcc;return function(_0xff2a3d){if(_0xff2a3d){return _0x3fd4da[_0xeb0a('0x1e')](_0x225aa3);}return _0x3fd4da[_0xeb0a('0x1f')](_0x225aa3)[_0xeb0a('0x20')]();};}function respondWithResult(_0x534965,_0x14371b){_0x14371b=_0x14371b||0xc8;return function(_0x5df7d8){if(_0x5df7d8){return _0x534965['status'](_0x14371b)[_0xeb0a('0x21')](_0x5df7d8);}};}function respondWithFilteredResult(_0x2bea56,_0x42e60b){return function(_0x4560d8){if(_0x4560d8){var _0x58f99=typeof _0x42e60b[_0xeb0a('0x22')]===_0xeb0a('0x23')&&typeof _0x42e60b['limit']===_0xeb0a('0x23');var _0x50db2d=_0x4560d8[_0xeb0a('0x24')];var _0x29ee1c=_0x58f99?0x0:_0x42e60b[_0xeb0a('0x22')];var _0x54c59d=_0x58f99?_0x4560d8[_0xeb0a('0x24')]:_0x42e60b['offset']+_0x42e60b['limit'];var _0x5a225b;if(_0x54c59d>=_0x50db2d){_0x54c59d=_0x50db2d;_0x5a225b=0xc8;}else{_0x5a225b=0xce;}_0x2bea56[_0xeb0a('0x1f')](_0x5a225b);return _0x2bea56['set']('Content-Range',_0x29ee1c+'-'+_0x54c59d+'/'+_0x50db2d)[_0xeb0a('0x21')](_0x4560d8);}return null;};}function patchUpdates(_0x513431){return function(_0x29cc41){try{jsonpatch[_0xeb0a('0x25')](_0x29cc41,_0x513431,!![]);}catch(_0x50bfab){return BPromise[_0xeb0a('0x26')](_0x50bfab);}return _0x29cc41[_0xeb0a('0x27')]();};}function saveUpdates(_0x194d85,_0x437849){return function(_0xf258e2){if(_0xf258e2){return _0xf258e2['update'](_0x194d85)[_0xeb0a('0x28')](function(_0x3fe12f){return _0x3fe12f;});}return null;};}function removeEntity(_0x335481,_0x2558f3){return function(_0x4f9ce7){if(_0x4f9ce7){return _0x4f9ce7[_0xeb0a('0x29')]()['then'](function(){_0x335481[_0xeb0a('0x1f')](0xcc)['end']();});}};}function handleEntityNotFound(_0x51eb9a,_0xabdd31){return function(_0x37da79){if(!_0x37da79){_0x51eb9a[_0xeb0a('0x1e')](0x194);}return _0x37da79;};}function handleError(_0xf617e0,_0x4bb82c){_0x4bb82c=_0x4bb82c||0x1f4;return function(_0x393323){logger['error'](_0x393323[_0xeb0a('0x2a')]);if(_0x393323['name']){delete _0x393323[_0xeb0a('0x2b')];}_0xf617e0[_0xeb0a('0x1f')](_0x4bb82c)[_0xeb0a('0x2c')](_0x393323);};}exports['index']=function(_0x3935f5,_0x2699d5){var _0x56ae1a={},_0x30a6d7={},_0x262141={'count':0x0,'rows':[]};var _0x1b2d25=_[_0xeb0a('0x2d')](db[_0xeb0a('0x2e')][_0xeb0a('0x2f')],function(_0xcee2ac){return{'name':_0xcee2ac['fieldName'],'type':_0xcee2ac[_0xeb0a('0x30')][_0xeb0a('0x31')]};});_0x30a6d7[_0xeb0a('0x32')]=_['map'](_0x1b2d25,_0xeb0a('0x2b'));_0x30a6d7[_0xeb0a('0x33')]=_[_0xeb0a('0x34')](_0x3935f5[_0xeb0a('0x33')]);_0x30a6d7['filters']=_[_0xeb0a('0x35')](_0x30a6d7[_0xeb0a('0x32')],_0x30a6d7['query']);_0x56ae1a[_0xeb0a('0x36')]=_['intersection'](_0x30a6d7['model'],qs[_0xeb0a('0x37')](_0x3935f5[_0xeb0a('0x33')][_0xeb0a('0x37')]));_0x56ae1a[_0xeb0a('0x36')]=_0x56ae1a['attributes'][_0xeb0a('0x38')]?_0x56ae1a['attributes']:_0x30a6d7[_0xeb0a('0x32')];if(!_0x3935f5[_0xeb0a('0x33')][_0xeb0a('0x39')](_0xeb0a('0x3a'))){_0x56ae1a[_0xeb0a('0x3b')]=qs[_0xeb0a('0x3b')](_0x3935f5[_0xeb0a('0x33')]['limit']);_0x56ae1a[_0xeb0a('0x22')]=qs[_0xeb0a('0x22')](_0x3935f5[_0xeb0a('0x33')]['offset']);}_0x56ae1a['order']=qs[_0xeb0a('0x3c')](_0x3935f5[_0xeb0a('0x33')][_0xeb0a('0x3c')]);_0x56ae1a[_0xeb0a('0x3d')]=qs[_0xeb0a('0x3e')](_['pick'](_0x3935f5[_0xeb0a('0x33')],_0x30a6d7[_0xeb0a('0x3e')]),_0x1b2d25);if(_0x3935f5[_0xeb0a('0x33')]['filter']){_0x56ae1a[_0xeb0a('0x3d')]=_[_0xeb0a('0x3f')](_0x56ae1a[_0xeb0a('0x3d')],{'$or':_['map'](_0x1b2d25,function(_0x65e1ec){if(_0x65e1ec[_0xeb0a('0x30')]!==_0xeb0a('0x40')){var _0x221dde={};_0x221dde[_0x65e1ec['name']]={'$like':'%'+_0x3935f5[_0xeb0a('0x33')][_0xeb0a('0x41')]+'%'};return _0x221dde;}})});}_0x56ae1a=_['merge']({},_0x56ae1a,_0x3935f5[_0xeb0a('0x42')]);var _0x3eedfe={'where':_0x56ae1a['where']};return db[_0xeb0a('0x2e')][_0xeb0a('0x24')](_0x3eedfe)[_0xeb0a('0x28')](function(_0x3df67a){_0x262141[_0xeb0a('0x24')]=_0x3df67a;if(_0x3935f5[_0xeb0a('0x33')][_0xeb0a('0x43')]){_0x56ae1a['include']=[{'all':!![]}];}return db[_0xeb0a('0x2e')][_0xeb0a('0x44')](_0x56ae1a);})[_0xeb0a('0x28')](function(_0x412d45){_0x262141['rows']=_0x412d45;return _0x262141;})[_0xeb0a('0x28')](respondWithFilteredResult(_0x2699d5,_0x56ae1a))[_0xeb0a('0x45')](handleError(_0x2699d5,null));};exports['show']=function(_0x4dd6b5,_0x2dcc72){var _0xafea46={'raw':![],'where':{'id':_0x4dd6b5[_0xeb0a('0x46')]['id']}},_0x506608={};_0x506608['model']=_[_0xeb0a('0x34')](db[_0xeb0a('0x2e')]['rawAttributes']);_0x506608[_0xeb0a('0x33')]=_[_0xeb0a('0x34')](_0x4dd6b5[_0xeb0a('0x33')]);_0x506608[_0xeb0a('0x3e')]=_[_0xeb0a('0x35')](_0x506608[_0xeb0a('0x32')],_0x506608[_0xeb0a('0x33')]);_0xafea46[_0xeb0a('0x36')]=_[_0xeb0a('0x35')](_0x506608['model'],qs[_0xeb0a('0x37')](_0x4dd6b5[_0xeb0a('0x33')][_0xeb0a('0x37')]));_0xafea46['attributes']=_0xafea46[_0xeb0a('0x36')][_0xeb0a('0x38')]?_0xafea46['attributes']:_0x506608[_0xeb0a('0x32')];if(_0x4dd6b5['query'][_0xeb0a('0x43')]){_0xafea46[_0xeb0a('0x47')]=[{'all':!![]}];}_0xafea46=_[_0xeb0a('0x3f')]({},_0xafea46,_0x4dd6b5['options']);return db['VoiceQueueReport'][_0xeb0a('0x48')](_0xafea46)['then'](handleEntityNotFound(_0x2dcc72,null))[_0xeb0a('0x28')](respondWithResult(_0x2dcc72,null))[_0xeb0a('0x45')](handleError(_0x2dcc72,null));};exports[_0xeb0a('0x49')]=function(_0x40cd9d,_0x4e142b){return db[_0xeb0a('0x2e')][_0xeb0a('0x49')](_0x40cd9d[_0xeb0a('0x4a')],{})[_0xeb0a('0x28')](respondWithResult(_0x4e142b,0xc9))[_0xeb0a('0x45')](handleError(_0x4e142b,null));};exports[_0xeb0a('0x4b')]=function(_0x5d560d,_0x53ca5d){if(_0x5d560d[_0xeb0a('0x4a')]['id']){delete _0x5d560d[_0xeb0a('0x4a')]['id'];}return db[_0xeb0a('0x2e')][_0xeb0a('0x48')]({'where':{'id':_0x5d560d[_0xeb0a('0x46')]['id']}})['then'](handleEntityNotFound(_0x53ca5d,null))[_0xeb0a('0x28')](saveUpdates(_0x5d560d[_0xeb0a('0x4a')],null))[_0xeb0a('0x28')](respondWithResult(_0x53ca5d,null))[_0xeb0a('0x45')](handleError(_0x53ca5d,null));};exports['destroy']=function(_0x117207,_0x5864c5){return db[_0xeb0a('0x2e')][_0xeb0a('0x48')]({'where':{'id':_0x117207['params']['id']}})[_0xeb0a('0x28')](handleEntityNotFound(_0x5864c5,null))[_0xeb0a('0x28')](removeEntity(_0x5864c5,null))[_0xeb0a('0x45')](handleError(_0x5864c5,null));};exports[_0xeb0a('0x4c')]=function(_0x54d19c,_0x27d1a4){return db[_0xeb0a('0x2e')]['describe']()[_0xeb0a('0x28')](respondWithResult(_0x27d1a4,null))[_0xeb0a('0x45')](handleError(_0x27d1a4,null));};exports['getVoiceQueuesReport']=function(_0x1dccc8,_0x5d7f90){var _0x32da31={},_0x2005c2={},_0x3c1626={'count':0x0,'rows':[]};_0x2005c2[_0xeb0a('0x32')]=_['keys'](db[_0xeb0a('0x2e')][_0xeb0a('0x2f')]);_0x2005c2['query']=_[_0xeb0a('0x34')](_0x1dccc8[_0xeb0a('0x33')]);_0x2005c2[_0xeb0a('0x3e')]=_[_0xeb0a('0x35')](_0x2005c2[_0xeb0a('0x32')],_0x2005c2['query']);_0x32da31[_0xeb0a('0x36')]=_[_0xeb0a('0x35')](_0x2005c2[_0xeb0a('0x32')],qs[_0xeb0a('0x37')](_0x1dccc8[_0xeb0a('0x33')][_0xeb0a('0x37')]));_0x32da31[_0xeb0a('0x36')]=_0x32da31[_0xeb0a('0x36')][_0xeb0a('0x38')]?_0x32da31['attributes']:_0x2005c2[_0xeb0a('0x32')];if(!_0x1dccc8[_0xeb0a('0x33')][_0xeb0a('0x39')]('nolimit')){_0x32da31[_0xeb0a('0x3b')]=qs[_0xeb0a('0x3b')](_0x1dccc8[_0xeb0a('0x33')][_0xeb0a('0x3b')]);_0x32da31[_0xeb0a('0x22')]=qs[_0xeb0a('0x22')](_0x1dccc8['query'][_0xeb0a('0x22')]);}_0x32da31[_0xeb0a('0x4d')]=qs['sort'](_0x1dccc8[_0xeb0a('0x33')][_0xeb0a('0x3c')]);_0x32da31[_0xeb0a('0x3d')]=qs[_0xeb0a('0x3e')](_[_0xeb0a('0x4e')](_0x1dccc8[_0xeb0a('0x33')],_0x2005c2[_0xeb0a('0x3e')]));if(_0x1dccc8['query'][_0xeb0a('0x41')]){_0x32da31[_0xeb0a('0x3d')]=_[_0xeb0a('0x3f')](_0x32da31['where'],{'$or':_[_0xeb0a('0x2d')](_0x32da31[_0xeb0a('0x36')],function(_0x4b91bd){var _0xd9bb02={};_0xd9bb02[_0x4b91bd]={'$like':'%'+_0x1dccc8[_0xeb0a('0x33')]['filter']+'%'};return _0xd9bb02;})});}_0x32da31=_[_0xeb0a('0x3f')]({},_0x32da31,_0x1dccc8[_0xeb0a('0x42')]);var _0x5d2cdc={'where':_0x32da31['where']};return db[_0xeb0a('0x2e')][_0xeb0a('0x24')](_0x5d2cdc)[_0xeb0a('0x28')](function(_0x36ae59){_0x3c1626[_0xeb0a('0x24')]=_0x36ae59;if(_0x1dccc8['query'][_0xeb0a('0x43')]){_0x32da31[_0xeb0a('0x47')]=[{'all':!![]}];}return db[_0xeb0a('0x2e')]['findAll'](_0x32da31);})[_0xeb0a('0x28')](function(_0x507353){_0x3c1626[_0xeb0a('0x4f')]=_0x507353;return _0x3c1626;})[_0xeb0a('0x28')](respondWithFilteredResult(_0x5d7f90,_0x32da31,_0xeb0a('0x50')))[_0xeb0a('0x45')](handleError(_0x5d7f90,null,'getVoiceQueuesReport'));};