Built motion from commit 3d6333b4.|2.6.31
[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 _0x5bcb=['pick','filter','merge','VIRTUAL','VoiceQueueReport','findAll','rows','catch','params','includeAll','include','find','create','body','describe','getVoiceQueuesReport','options','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','sox','to-csv','fs-extra','lodash','squel','crypto','desk.js','papaparse','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','../../config/license/util','../../mysqldb','redis','localhost','./voiceQueueReport.socket','register','end','status','json','limit','undefined','count','offset','set','Content-Range','reject','save','update','then','destroy','sendStatus','error','stack','name','send','index','map','rawAttributes','fieldName','type','key','model','keys','query','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where'];(function(_0x57bf92,_0x1c2931){var _0x5b28a6=function(_0x4934ac){while(--_0x4934ac){_0x57bf92['push'](_0x57bf92['shift']());}};_0x5b28a6(++_0x1c2931);}(_0x5bcb,0x1b0));var _0xb5bc=function(_0x5c5ce2,_0x49faa6){_0x5c5ce2=_0x5c5ce2-0x0;var _0x337587=_0x5bcb[_0x5c5ce2];return _0x337587;};'use strict';var emlformat=require(_0xb5bc('0x0'));var rimraf=require(_0xb5bc('0x1'));var zipdir=require(_0xb5bc('0x2'));var jsonpatch=require(_0xb5bc('0x3'));var rp=require(_0xb5bc('0x4'));var moment=require(_0xb5bc('0x5'));var BPromise=require(_0xb5bc('0x6'));var Mustache=require(_0xb5bc('0x7'));var util=require(_0xb5bc('0x8'));var path=require('path');var sox=require(_0xb5bc('0x9'));var csv=require(_0xb5bc('0xa'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0xb5bc('0xb'));var _=require(_0xb5bc('0xc'));var squel=require(_0xb5bc('0xd'));var crypto=require(_0xb5bc('0xe'));var jsforce=require('jsforce');var deskjs=require(_0xb5bc('0xf'));var toCsv=require(_0xb5bc('0xa'));var querystring=require('querystring');var Papa=require(_0xb5bc('0x10'));var Redis=require('ioredis');var authService=require(_0xb5bc('0x11'));var qs=require(_0xb5bc('0x12'));var as=require(_0xb5bc('0x13'));var hardwareService=require('../../config/license/hardware');var logger=require(_0xb5bc('0x14'))(_0xb5bc('0x15'));var utils=require('../../config/utils');var config=require('../../config/environment');var licenseUtil=require(_0xb5bc('0x16'));var db=require(_0xb5bc('0x17'))['db'];config[_0xb5bc('0x18')]=_['defaults'](config[_0xb5bc('0x18')],{'host':_0xb5bc('0x19'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config['redis']));require(_0xb5bc('0x1a'))[_0xb5bc('0x1b')](socket);function respondWithStatusCode(_0x45ace4,_0x394e84){_0x394e84=_0x394e84||0xcc;return function(_0x4090ee){if(_0x4090ee){return _0x45ace4['sendStatus'](_0x394e84);}return _0x45ace4['status'](_0x394e84)[_0xb5bc('0x1c')]();};}function respondWithResult(_0x3273f9,_0x6479a2){_0x6479a2=_0x6479a2||0xc8;return function(_0x46cbff){if(_0x46cbff){return _0x3273f9[_0xb5bc('0x1d')](_0x6479a2)[_0xb5bc('0x1e')](_0x46cbff);}};}function respondWithFilteredResult(_0x1e8369,_0x1d0970){return function(_0x1016bb){if(_0x1016bb){var _0x36850d=typeof _0x1d0970['offset']==='undefined'&&typeof _0x1d0970[_0xb5bc('0x1f')]===_0xb5bc('0x20');var _0x4d15e8=_0x1016bb[_0xb5bc('0x21')];var _0x34cce4=_0x36850d?0x0:_0x1d0970[_0xb5bc('0x22')];var _0x53d1ce=_0x36850d?_0x1016bb[_0xb5bc('0x21')]:_0x1d0970[_0xb5bc('0x22')]+_0x1d0970[_0xb5bc('0x1f')];var _0x2cccbc;if(_0x53d1ce>=_0x4d15e8){_0x53d1ce=_0x4d15e8;_0x2cccbc=0xc8;}else{_0x2cccbc=0xce;}_0x1e8369[_0xb5bc('0x1d')](_0x2cccbc);return _0x1e8369[_0xb5bc('0x23')](_0xb5bc('0x24'),_0x34cce4+'-'+_0x53d1ce+'/'+_0x4d15e8)[_0xb5bc('0x1e')](_0x1016bb);}return null;};}function patchUpdates(_0x10df73){return function(_0x1e20c0){try{jsonpatch['apply'](_0x1e20c0,_0x10df73,!![]);}catch(_0x460ab7){return BPromise[_0xb5bc('0x25')](_0x460ab7);}return _0x1e20c0[_0xb5bc('0x26')]();};}function saveUpdates(_0xd36149,_0x87b078){return function(_0x57419c){if(_0x57419c){return _0x57419c[_0xb5bc('0x27')](_0xd36149)[_0xb5bc('0x28')](function(_0x4659cc){return _0x4659cc;});}return null;};}function removeEntity(_0xc510b1,_0x39e8c9){return function(_0x70dd53){if(_0x70dd53){return _0x70dd53[_0xb5bc('0x29')]()[_0xb5bc('0x28')](function(){_0xc510b1[_0xb5bc('0x1d')](0xcc)[_0xb5bc('0x1c')]();});}};}function handleEntityNotFound(_0x441673,_0x47190b){return function(_0x4979d6){if(!_0x4979d6){_0x441673[_0xb5bc('0x2a')](0x194);}return _0x4979d6;};}function handleError(_0x15cd94,_0x37215a){_0x37215a=_0x37215a||0x1f4;return function(_0x555a22){logger[_0xb5bc('0x2b')](_0x555a22[_0xb5bc('0x2c')]);if(_0x555a22['name']){delete _0x555a22[_0xb5bc('0x2d')];}_0x15cd94['status'](_0x37215a)[_0xb5bc('0x2e')](_0x555a22);};}exports[_0xb5bc('0x2f')]=function(_0x4383a1,_0x4f94a2){var _0x316a75={},_0x23734f={},_0x2f2cb={'count':0x0,'rows':[]};var _0x418724=_[_0xb5bc('0x30')](db['VoiceQueueReport'][_0xb5bc('0x31')],function(_0x276fb2){return{'name':_0x276fb2[_0xb5bc('0x32')],'type':_0x276fb2[_0xb5bc('0x33')][_0xb5bc('0x34')]};});_0x23734f[_0xb5bc('0x35')]=_['map'](_0x418724,_0xb5bc('0x2d'));_0x23734f['query']=_[_0xb5bc('0x36')](_0x4383a1[_0xb5bc('0x37')]);_0x23734f[_0xb5bc('0x38')]=_[_0xb5bc('0x39')](_0x23734f[_0xb5bc('0x35')],_0x23734f[_0xb5bc('0x37')]);_0x316a75[_0xb5bc('0x3a')]=_['intersection'](_0x23734f[_0xb5bc('0x35')],qs[_0xb5bc('0x3b')](_0x4383a1[_0xb5bc('0x37')][_0xb5bc('0x3b')]));_0x316a75[_0xb5bc('0x3a')]=_0x316a75[_0xb5bc('0x3a')][_0xb5bc('0x3c')]?_0x316a75[_0xb5bc('0x3a')]:_0x23734f[_0xb5bc('0x35')];if(!_0x4383a1['query'][_0xb5bc('0x3d')](_0xb5bc('0x3e'))){_0x316a75[_0xb5bc('0x1f')]=qs['limit'](_0x4383a1[_0xb5bc('0x37')][_0xb5bc('0x1f')]);_0x316a75['offset']=qs[_0xb5bc('0x22')](_0x4383a1[_0xb5bc('0x37')][_0xb5bc('0x22')]);}_0x316a75[_0xb5bc('0x3f')]=qs[_0xb5bc('0x40')](_0x4383a1[_0xb5bc('0x37')][_0xb5bc('0x40')]);_0x316a75[_0xb5bc('0x41')]=qs[_0xb5bc('0x38')](_[_0xb5bc('0x42')](_0x4383a1[_0xb5bc('0x37')],_0x23734f[_0xb5bc('0x38')]),_0x418724);if(_0x4383a1[_0xb5bc('0x37')][_0xb5bc('0x43')]){_0x316a75[_0xb5bc('0x41')]=_[_0xb5bc('0x44')](_0x316a75['where'],{'$or':_[_0xb5bc('0x30')](_0x418724,function(_0x5ed8e2){if(_0x5ed8e2[_0xb5bc('0x33')]!==_0xb5bc('0x45')){var _0x432682={};_0x432682[_0x5ed8e2[_0xb5bc('0x2d')]]={'$like':'%'+_0x4383a1['query'][_0xb5bc('0x43')]+'%'};return _0x432682;}})});}_0x316a75=_['merge']({},_0x316a75,_0x4383a1['options']);var _0x469650={'where':_0x316a75[_0xb5bc('0x41')]};return db[_0xb5bc('0x46')][_0xb5bc('0x21')](_0x469650)[_0xb5bc('0x28')](function(_0x39d41){_0x2f2cb[_0xb5bc('0x21')]=_0x39d41;if(_0x4383a1[_0xb5bc('0x37')]['includeAll']){_0x316a75['include']=[{'all':!![]}];}return db[_0xb5bc('0x46')][_0xb5bc('0x47')](_0x316a75);})['then'](function(_0x5297ed){_0x2f2cb[_0xb5bc('0x48')]=_0x5297ed;return _0x2f2cb;})[_0xb5bc('0x28')](respondWithFilteredResult(_0x4f94a2,_0x316a75))[_0xb5bc('0x49')](handleError(_0x4f94a2,null));};exports['show']=function(_0x19c522,_0x5bb01a){var _0x3baa9b={'raw':![],'where':{'id':_0x19c522[_0xb5bc('0x4a')]['id']}},_0x7d7e8f={};_0x7d7e8f[_0xb5bc('0x35')]=_[_0xb5bc('0x36')](db[_0xb5bc('0x46')][_0xb5bc('0x31')]);_0x7d7e8f['query']=_[_0xb5bc('0x36')](_0x19c522['query']);_0x7d7e8f['filters']=_[_0xb5bc('0x39')](_0x7d7e8f['model'],_0x7d7e8f[_0xb5bc('0x37')]);_0x3baa9b[_0xb5bc('0x3a')]=_[_0xb5bc('0x39')](_0x7d7e8f[_0xb5bc('0x35')],qs[_0xb5bc('0x3b')](_0x19c522[_0xb5bc('0x37')]['fields']));_0x3baa9b[_0xb5bc('0x3a')]=_0x3baa9b['attributes'][_0xb5bc('0x3c')]?_0x3baa9b[_0xb5bc('0x3a')]:_0x7d7e8f[_0xb5bc('0x35')];if(_0x19c522[_0xb5bc('0x37')][_0xb5bc('0x4b')]){_0x3baa9b[_0xb5bc('0x4c')]=[{'all':!![]}];}_0x3baa9b=_['merge']({},_0x3baa9b,_0x19c522['options']);return db['VoiceQueueReport'][_0xb5bc('0x4d')](_0x3baa9b)[_0xb5bc('0x28')](handleEntityNotFound(_0x5bb01a,null))['then'](respondWithResult(_0x5bb01a,null))[_0xb5bc('0x49')](handleError(_0x5bb01a,null));};exports[_0xb5bc('0x4e')]=function(_0x2bc796,_0x4caca6){return db[_0xb5bc('0x46')][_0xb5bc('0x4e')](_0x2bc796[_0xb5bc('0x4f')],{})[_0xb5bc('0x28')](respondWithResult(_0x4caca6,0xc9))[_0xb5bc('0x49')](handleError(_0x4caca6,null));};exports[_0xb5bc('0x27')]=function(_0xf1d858,_0x15755b){if(_0xf1d858[_0xb5bc('0x4f')]['id']){delete _0xf1d858[_0xb5bc('0x4f')]['id'];}return db[_0xb5bc('0x46')][_0xb5bc('0x4d')]({'where':{'id':_0xf1d858[_0xb5bc('0x4a')]['id']}})[_0xb5bc('0x28')](handleEntityNotFound(_0x15755b,null))[_0xb5bc('0x28')](saveUpdates(_0xf1d858[_0xb5bc('0x4f')],null))[_0xb5bc('0x28')](respondWithResult(_0x15755b,null))[_0xb5bc('0x49')](handleError(_0x15755b,null));};exports['destroy']=function(_0x225d50,_0x386f4d){return db[_0xb5bc('0x46')][_0xb5bc('0x4d')]({'where':{'id':_0x225d50[_0xb5bc('0x4a')]['id']}})[_0xb5bc('0x28')](handleEntityNotFound(_0x386f4d,null))[_0xb5bc('0x28')](removeEntity(_0x386f4d,null))['catch'](handleError(_0x386f4d,null));};exports[_0xb5bc('0x50')]=function(_0x4f0e78,_0x3e7202){return db[_0xb5bc('0x46')][_0xb5bc('0x50')]()['then'](respondWithResult(_0x3e7202,null))[_0xb5bc('0x49')](handleError(_0x3e7202,null));};exports[_0xb5bc('0x51')]=function(_0x5214ed,_0x31fa08){var _0xb88da1={},_0xf4ad95={},_0x3bf35d={'count':0x0,'rows':[]};_0xf4ad95[_0xb5bc('0x35')]=_[_0xb5bc('0x36')](db[_0xb5bc('0x46')][_0xb5bc('0x31')]);_0xf4ad95[_0xb5bc('0x37')]=_[_0xb5bc('0x36')](_0x5214ed[_0xb5bc('0x37')]);_0xf4ad95[_0xb5bc('0x38')]=_['intersection'](_0xf4ad95[_0xb5bc('0x35')],_0xf4ad95[_0xb5bc('0x37')]);_0xb88da1[_0xb5bc('0x3a')]=_[_0xb5bc('0x39')](_0xf4ad95['model'],qs[_0xb5bc('0x3b')](_0x5214ed[_0xb5bc('0x37')]['fields']));_0xb88da1[_0xb5bc('0x3a')]=_0xb88da1[_0xb5bc('0x3a')][_0xb5bc('0x3c')]?_0xb88da1[_0xb5bc('0x3a')]:_0xf4ad95[_0xb5bc('0x35')];if(!_0x5214ed[_0xb5bc('0x37')][_0xb5bc('0x3d')](_0xb5bc('0x3e'))){_0xb88da1[_0xb5bc('0x1f')]=qs['limit'](_0x5214ed[_0xb5bc('0x37')][_0xb5bc('0x1f')]);_0xb88da1[_0xb5bc('0x22')]=qs[_0xb5bc('0x22')](_0x5214ed[_0xb5bc('0x37')]['offset']);}_0xb88da1['order']=qs[_0xb5bc('0x40')](_0x5214ed[_0xb5bc('0x37')][_0xb5bc('0x40')]);_0xb88da1[_0xb5bc('0x41')]=qs['filters'](_[_0xb5bc('0x42')](_0x5214ed[_0xb5bc('0x37')],_0xf4ad95[_0xb5bc('0x38')]));if(_0x5214ed[_0xb5bc('0x37')][_0xb5bc('0x43')]){_0xb88da1['where']=_[_0xb5bc('0x44')](_0xb88da1['where'],{'$or':_[_0xb5bc('0x30')](_0xb88da1[_0xb5bc('0x3a')],function(_0x4a206f){var _0x20fba0={};_0x20fba0[_0x4a206f]={'$like':'%'+_0x5214ed[_0xb5bc('0x37')][_0xb5bc('0x43')]+'%'};return _0x20fba0;})});}_0xb88da1=_[_0xb5bc('0x44')]({},_0xb88da1,_0x5214ed[_0xb5bc('0x52')]);var _0x122f37={'where':_0xb88da1[_0xb5bc('0x41')]};return db[_0xb5bc('0x46')][_0xb5bc('0x21')](_0x122f37)[_0xb5bc('0x28')](function(_0x41594d){_0x3bf35d[_0xb5bc('0x21')]=_0x41594d;if(_0x5214ed[_0xb5bc('0x37')][_0xb5bc('0x4b')]){_0xb88da1[_0xb5bc('0x4c')]=[{'all':!![]}];}return db['VoiceQueueReport']['findAll'](_0xb88da1);})['then'](function(_0x94f536){_0x3bf35d[_0xb5bc('0x48')]=_0x94f536;return _0x3bf35d;})[_0xb5bc('0x28')](respondWithFilteredResult(_0x31fa08,_0xb88da1,'getVoiceQueuesReport'))[_0xb5bc('0x49')](handleError(_0x31fa08,null,'getVoiceQueuesReport'));};