6f8bec07284496c9267d202ad6b0990fad25e977
[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 _0xb35f=['then','error','stack','name','send','index','map','VoiceQueueReport','rawAttributes','type','key','query','keys','filters','intersection','model','attributes','fields','hasOwnProperty','order','sort','pick','filter','where','VIRTUAL','options','includeAll','include','findAll','rows','catch','params','length','merge','find','create','body','destroy','getVoiceQueuesReport','nolimit','eml-format','rimraf','zip-dir','request-promise','moment','mustache','util','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/license/util','defaults','redis','localhost','socket.io-emitter','sendStatus','status','end','limit','count','offset','set','Content-Range','json','reject','save','update'];(function(_0xbd35aa,_0x49e53b){var _0x403a4f=function(_0x6f11e6){while(--_0x6f11e6){_0xbd35aa['push'](_0xbd35aa['shift']());}};_0x403a4f(++_0x49e53b);}(_0xb35f,0xc6));var _0xfb35=function(_0x5c3a91,_0x12292a){_0x5c3a91=_0x5c3a91-0x0;var _0x3f91f2=_0xb35f[_0x5c3a91];return _0x3f91f2;};'use strict';var emlformat=require(_0xfb35('0x0'));var rimraf=require(_0xfb35('0x1'));var zipdir=require(_0xfb35('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0xfb35('0x3'));var moment=require(_0xfb35('0x4'));var BPromise=require('bluebird');var Mustache=require(_0xfb35('0x5'));var util=require(_0xfb35('0x6'));var path=require('path');var sox=require('sox');var csv=require('to-csv');var ejs=require(_0xfb35('0x7'));var fs=require('fs');var fs_extra=require(_0xfb35('0x8'));var _=require(_0xfb35('0x9'));var squel=require(_0xfb35('0xa'));var crypto=require(_0xfb35('0xb'));var jsforce=require(_0xfb35('0xc'));var deskjs=require(_0xfb35('0xd'));var toCsv=require('to-csv');var querystring=require(_0xfb35('0xe'));var Papa=require('papaparse');var Redis=require(_0xfb35('0xf'));var authService=require(_0xfb35('0x10'));var qs=require('../../components/parsers/qs');var as=require(_0xfb35('0x11'));var hardwareService=require(_0xfb35('0x12'));var logger=require(_0xfb35('0x13'))(_0xfb35('0x14'));var utils=require(_0xfb35('0x15'));var config=require('../../config/environment');var licenseUtil=require(_0xfb35('0x16'));var db=require('../../mysqldb')['db'];config['redis']=_[_0xfb35('0x17')](config[_0xfb35('0x18')],{'host':_0xfb35('0x19'),'port':0x18eb});var socket=require(_0xfb35('0x1a'))(new Redis(config[_0xfb35('0x18')]));require('./voiceQueueReport.socket')['register'](socket);function respondWithStatusCode(_0x55c774,_0x34f4ba){_0x34f4ba=_0x34f4ba||0xcc;return function(_0x70302e){if(_0x70302e){return _0x55c774[_0xfb35('0x1b')](_0x34f4ba);}return _0x55c774[_0xfb35('0x1c')](_0x34f4ba)[_0xfb35('0x1d')]();};}function respondWithResult(_0x12fe0d,_0x4d6e77){_0x4d6e77=_0x4d6e77||0xc8;return function(_0x5b82fb){if(_0x5b82fb){return _0x12fe0d[_0xfb35('0x1c')](_0x4d6e77)['json'](_0x5b82fb);}};}function respondWithFilteredResult(_0x4c49f0,_0x3cbbbe){return function(_0x15fe8f){if(_0x15fe8f){var _0x5852b0=typeof _0x3cbbbe['offset']==='undefined'&&typeof _0x3cbbbe[_0xfb35('0x1e')]==='undefined';var _0x4d8764=_0x15fe8f[_0xfb35('0x1f')];var _0x2b3c29=_0x5852b0?0x0:_0x3cbbbe[_0xfb35('0x20')];var _0x31233c=_0x5852b0?_0x15fe8f[_0xfb35('0x1f')]:_0x3cbbbe['offset']+_0x3cbbbe[_0xfb35('0x1e')];var _0x5dac29;if(_0x31233c>=_0x4d8764){_0x31233c=_0x4d8764;_0x5dac29=0xc8;}else{_0x5dac29=0xce;}_0x4c49f0['status'](_0x5dac29);return _0x4c49f0[_0xfb35('0x21')](_0xfb35('0x22'),_0x2b3c29+'-'+_0x31233c+'/'+_0x4d8764)[_0xfb35('0x23')](_0x15fe8f);}return null;};}function patchUpdates(_0x2fe89a){return function(_0x10211f){try{jsonpatch['apply'](_0x10211f,_0x2fe89a,!![]);}catch(_0x5602a9){return BPromise[_0xfb35('0x24')](_0x5602a9);}return _0x10211f[_0xfb35('0x25')]();};}function saveUpdates(_0xad3595,_0x11f0b7){return function(_0x59e554){if(_0x59e554){return _0x59e554[_0xfb35('0x26')](_0xad3595)[_0xfb35('0x27')](function(_0x59744f){return _0x59744f;});}return null;};}function removeEntity(_0x4c768e,_0x302721){return function(_0x30f538){if(_0x30f538){return _0x30f538['destroy']()['then'](function(){_0x4c768e['status'](0xcc)[_0xfb35('0x1d')]();});}};}function handleEntityNotFound(_0x47ec38,_0x179247){return function(_0x328923){if(!_0x328923){_0x47ec38['sendStatus'](0x194);}return _0x328923;};}function handleError(_0x3d2b60,_0x34ad4e){_0x34ad4e=_0x34ad4e||0x1f4;return function(_0x28c02d){logger[_0xfb35('0x28')](_0x28c02d[_0xfb35('0x29')]);if(_0x28c02d[_0xfb35('0x2a')]){delete _0x28c02d[_0xfb35('0x2a')];}_0x3d2b60[_0xfb35('0x1c')](_0x34ad4e)[_0xfb35('0x2b')](_0x28c02d);};}exports[_0xfb35('0x2c')]=function(_0x3dc3a1,_0x310026){var _0x3ebfaf={},_0x5529c1={},_0x322786={'count':0x0,'rows':[]};var _0x31c094=_[_0xfb35('0x2d')](db[_0xfb35('0x2e')][_0xfb35('0x2f')],function(_0x5871e6){return{'name':_0x5871e6['fieldName'],'type':_0x5871e6[_0xfb35('0x30')][_0xfb35('0x31')]};});_0x5529c1['model']=_[_0xfb35('0x2d')](_0x31c094,_0xfb35('0x2a'));_0x5529c1[_0xfb35('0x32')]=_[_0xfb35('0x33')](_0x3dc3a1['query']);_0x5529c1[_0xfb35('0x34')]=_[_0xfb35('0x35')](_0x5529c1[_0xfb35('0x36')],_0x5529c1[_0xfb35('0x32')]);_0x3ebfaf[_0xfb35('0x37')]=_[_0xfb35('0x35')](_0x5529c1['model'],qs['fields'](_0x3dc3a1[_0xfb35('0x32')][_0xfb35('0x38')]));_0x3ebfaf[_0xfb35('0x37')]=_0x3ebfaf[_0xfb35('0x37')]['length']?_0x3ebfaf[_0xfb35('0x37')]:_0x5529c1[_0xfb35('0x36')];if(!_0x3dc3a1[_0xfb35('0x32')][_0xfb35('0x39')]('nolimit')){_0x3ebfaf['limit']=qs[_0xfb35('0x1e')](_0x3dc3a1[_0xfb35('0x32')][_0xfb35('0x1e')]);_0x3ebfaf[_0xfb35('0x20')]=qs['offset'](_0x3dc3a1['query'][_0xfb35('0x20')]);}_0x3ebfaf[_0xfb35('0x3a')]=qs[_0xfb35('0x3b')](_0x3dc3a1[_0xfb35('0x32')]['sort']);_0x3ebfaf['where']=qs[_0xfb35('0x34')](_[_0xfb35('0x3c')](_0x3dc3a1[_0xfb35('0x32')],_0x5529c1[_0xfb35('0x34')]),_0x31c094);if(_0x3dc3a1['query'][_0xfb35('0x3d')]){_0x3ebfaf[_0xfb35('0x3e')]=_['merge'](_0x3ebfaf[_0xfb35('0x3e')],{'$or':_[_0xfb35('0x2d')](_0x31c094,function(_0x1341bf){if(_0x1341bf[_0xfb35('0x30')]!==_0xfb35('0x3f')){var _0x4b251f={};_0x4b251f[_0x1341bf[_0xfb35('0x2a')]]={'$like':'%'+_0x3dc3a1[_0xfb35('0x32')][_0xfb35('0x3d')]+'%'};return _0x4b251f;}})});}_0x3ebfaf=_['merge']({},_0x3ebfaf,_0x3dc3a1[_0xfb35('0x40')]);var _0x130ea4={'where':_0x3ebfaf[_0xfb35('0x3e')]};return db[_0xfb35('0x2e')][_0xfb35('0x1f')](_0x130ea4)['then'](function(_0x47d3bb){_0x322786[_0xfb35('0x1f')]=_0x47d3bb;if(_0x3dc3a1[_0xfb35('0x32')][_0xfb35('0x41')]){_0x3ebfaf[_0xfb35('0x42')]=[{'all':!![]}];}return db[_0xfb35('0x2e')][_0xfb35('0x43')](_0x3ebfaf);})[_0xfb35('0x27')](function(_0x2bc25c){_0x322786[_0xfb35('0x44')]=_0x2bc25c;return _0x322786;})[_0xfb35('0x27')](respondWithFilteredResult(_0x310026,_0x3ebfaf))[_0xfb35('0x45')](handleError(_0x310026,null));};exports['show']=function(_0x58ba21,_0x7213be){var _0x43eec9={'raw':![],'where':{'id':_0x58ba21[_0xfb35('0x46')]['id']}},_0x22cd62={};_0x22cd62[_0xfb35('0x36')]=_['keys'](db[_0xfb35('0x2e')][_0xfb35('0x2f')]);_0x22cd62['query']=_[_0xfb35('0x33')](_0x58ba21[_0xfb35('0x32')]);_0x22cd62[_0xfb35('0x34')]=_[_0xfb35('0x35')](_0x22cd62['model'],_0x22cd62[_0xfb35('0x32')]);_0x43eec9['attributes']=_[_0xfb35('0x35')](_0x22cd62[_0xfb35('0x36')],qs[_0xfb35('0x38')](_0x58ba21[_0xfb35('0x32')][_0xfb35('0x38')]));_0x43eec9[_0xfb35('0x37')]=_0x43eec9[_0xfb35('0x37')][_0xfb35('0x47')]?_0x43eec9[_0xfb35('0x37')]:_0x22cd62['model'];if(_0x58ba21[_0xfb35('0x32')][_0xfb35('0x41')]){_0x43eec9['include']=[{'all':!![]}];}_0x43eec9=_[_0xfb35('0x48')]({},_0x43eec9,_0x58ba21['options']);return db[_0xfb35('0x2e')][_0xfb35('0x49')](_0x43eec9)[_0xfb35('0x27')](handleEntityNotFound(_0x7213be,null))[_0xfb35('0x27')](respondWithResult(_0x7213be,null))[_0xfb35('0x45')](handleError(_0x7213be,null));};exports['create']=function(_0x26cdd1,_0xce6af8){return db[_0xfb35('0x2e')][_0xfb35('0x4a')](_0x26cdd1[_0xfb35('0x4b')],{})['then'](respondWithResult(_0xce6af8,0xc9))[_0xfb35('0x45')](handleError(_0xce6af8,null));};exports[_0xfb35('0x26')]=function(_0x96fa5,_0x5e3f72){if(_0x96fa5['body']['id']){delete _0x96fa5[_0xfb35('0x4b')]['id'];}return db['VoiceQueueReport']['find']({'where':{'id':_0x96fa5['params']['id']}})[_0xfb35('0x27')](handleEntityNotFound(_0x5e3f72,null))[_0xfb35('0x27')](saveUpdates(_0x96fa5[_0xfb35('0x4b')],null))[_0xfb35('0x27')](respondWithResult(_0x5e3f72,null))[_0xfb35('0x45')](handleError(_0x5e3f72,null));};exports[_0xfb35('0x4c')]=function(_0x589584,_0x8a3a5d){return db[_0xfb35('0x2e')][_0xfb35('0x49')]({'where':{'id':_0x589584[_0xfb35('0x46')]['id']}})[_0xfb35('0x27')](handleEntityNotFound(_0x8a3a5d,null))[_0xfb35('0x27')](removeEntity(_0x8a3a5d,null))[_0xfb35('0x45')](handleError(_0x8a3a5d,null));};exports['describe']=function(_0x1e817f,_0x12d18e){return db[_0xfb35('0x2e')]['describe']()[_0xfb35('0x27')](respondWithResult(_0x12d18e,null))['catch'](handleError(_0x12d18e,null));};exports[_0xfb35('0x4d')]=function(_0x1db47b,_0xe984b2){var _0x430186={},_0x39d38b={},_0x219c0c={'count':0x0,'rows':[]};_0x39d38b[_0xfb35('0x36')]=_[_0xfb35('0x33')](db[_0xfb35('0x2e')]['rawAttributes']);_0x39d38b[_0xfb35('0x32')]=_['keys'](_0x1db47b[_0xfb35('0x32')]);_0x39d38b[_0xfb35('0x34')]=_[_0xfb35('0x35')](_0x39d38b[_0xfb35('0x36')],_0x39d38b[_0xfb35('0x32')]);_0x430186[_0xfb35('0x37')]=_[_0xfb35('0x35')](_0x39d38b[_0xfb35('0x36')],qs[_0xfb35('0x38')](_0x1db47b[_0xfb35('0x32')][_0xfb35('0x38')]));_0x430186[_0xfb35('0x37')]=_0x430186[_0xfb35('0x37')][_0xfb35('0x47')]?_0x430186[_0xfb35('0x37')]:_0x39d38b['model'];if(!_0x1db47b[_0xfb35('0x32')][_0xfb35('0x39')](_0xfb35('0x4e'))){_0x430186[_0xfb35('0x1e')]=qs[_0xfb35('0x1e')](_0x1db47b[_0xfb35('0x32')][_0xfb35('0x1e')]);_0x430186[_0xfb35('0x20')]=qs[_0xfb35('0x20')](_0x1db47b['query'][_0xfb35('0x20')]);}_0x430186['order']=qs[_0xfb35('0x3b')](_0x1db47b['query']['sort']);_0x430186['where']=qs[_0xfb35('0x34')](_[_0xfb35('0x3c')](_0x1db47b[_0xfb35('0x32')],_0x39d38b['filters']));if(_0x1db47b['query'][_0xfb35('0x3d')]){_0x430186[_0xfb35('0x3e')]=_['merge'](_0x430186[_0xfb35('0x3e')],{'$or':_[_0xfb35('0x2d')](_0x430186['attributes'],function(_0x236a85){var _0x5c1046={};_0x5c1046[_0x236a85]={'$like':'%'+_0x1db47b[_0xfb35('0x32')]['filter']+'%'};return _0x5c1046;})});}_0x430186=_[_0xfb35('0x48')]({},_0x430186,_0x1db47b[_0xfb35('0x40')]);var _0x20e84e={'where':_0x430186['where']};return db[_0xfb35('0x2e')]['count'](_0x20e84e)[_0xfb35('0x27')](function(_0x470a54){_0x219c0c['count']=_0x470a54;if(_0x1db47b[_0xfb35('0x32')][_0xfb35('0x41')]){_0x430186[_0xfb35('0x42')]=[{'all':!![]}];}return db[_0xfb35('0x2e')][_0xfb35('0x43')](_0x430186);})[_0xfb35('0x27')](function(_0x2d3e94){_0x219c0c[_0xfb35('0x44')]=_0x2d3e94;return _0x219c0c;})[_0xfb35('0x27')](respondWithFilteredResult(_0xe984b2,_0x430186,_0xfb35('0x4d')))['catch'](handleError(_0xe984b2,null,_0xfb35('0x4d')));};