Built motion from commit 10af8726.|2.6.34
[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 _0xb505=['localhost','socket.io-emitter','./voiceQueueReport.socket','register','sendStatus','status','json','undefined','count','offset','limit','set','Content-Range','apply','reject','save','update','then','destroy','error','name','send','index','map','VoiceQueueReport','rawAttributes','fieldName','type','key','model','query','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','sort','where','filter','VIRTUAL','merge','options','includeAll','include','findAll','catch','show','params','keys','create','body','find','describe','getVoiceQueuesReport','order','pick','rows','eml-format','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','to-csv','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis','defaults'];(function(_0x33c931,_0x1cf1e1){var _0x320817=function(_0x37aa16){while(--_0x37aa16){_0x33c931['push'](_0x33c931['shift']());}};_0x320817(++_0x1cf1e1);}(_0xb505,0x149));var _0x5b50=function(_0x58e99a,_0x718a6e){_0x58e99a=_0x58e99a-0x0;var _0x1f7a56=_0xb505[_0x58e99a];return _0x1f7a56;};'use strict';var emlformat=require(_0x5b50('0x0'));var rimraf=require('rimraf');var zipdir=require(_0x5b50('0x1'));var jsonpatch=require(_0x5b50('0x2'));var rp=require(_0x5b50('0x3'));var moment=require(_0x5b50('0x4'));var BPromise=require(_0x5b50('0x5'));var Mustache=require(_0x5b50('0x6'));var util=require(_0x5b50('0x7'));var path=require(_0x5b50('0x8'));var sox=require('sox');var csv=require(_0x5b50('0x9'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x5b50('0xa'));var _=require(_0x5b50('0xb'));var squel=require(_0x5b50('0xc'));var crypto=require(_0x5b50('0xd'));var jsforce=require(_0x5b50('0xe'));var deskjs=require(_0x5b50('0xf'));var toCsv=require(_0x5b50('0x9'));var querystring=require(_0x5b50('0x10'));var Papa=require(_0x5b50('0x11'));var Redis=require(_0x5b50('0x12'));var authService=require(_0x5b50('0x13'));var qs=require(_0x5b50('0x14'));var as=require(_0x5b50('0x15'));var hardwareService=require(_0x5b50('0x16'));var logger=require(_0x5b50('0x17'))(_0x5b50('0x18'));var utils=require(_0x5b50('0x19'));var config=require(_0x5b50('0x1a'));var licenseUtil=require(_0x5b50('0x1b'));var db=require(_0x5b50('0x1c'))['db'];config[_0x5b50('0x1d')]=_[_0x5b50('0x1e')](config[_0x5b50('0x1d')],{'host':_0x5b50('0x1f'),'port':0x18eb});var socket=require(_0x5b50('0x20'))(new Redis(config[_0x5b50('0x1d')]));require(_0x5b50('0x21'))[_0x5b50('0x22')](socket);function respondWithStatusCode(_0x13efb0,_0x168b78){_0x168b78=_0x168b78||0xcc;return function(_0x5162d7){if(_0x5162d7){return _0x13efb0[_0x5b50('0x23')](_0x168b78);}return _0x13efb0[_0x5b50('0x24')](_0x168b78)['end']();};}function respondWithResult(_0x330605,_0x5b1765){_0x5b1765=_0x5b1765||0xc8;return function(_0x4a1004){if(_0x4a1004){return _0x330605[_0x5b50('0x24')](_0x5b1765)[_0x5b50('0x25')](_0x4a1004);}};}function respondWithFilteredResult(_0x9cbdef,_0x506572){return function(_0x1b6b72){if(_0x1b6b72){var _0x221a4f=typeof _0x506572['offset']===_0x5b50('0x26')&&typeof _0x506572['limit']===_0x5b50('0x26');var _0x1d9c15=_0x1b6b72[_0x5b50('0x27')];var _0x228513=_0x221a4f?0x0:_0x506572['offset'];var _0x524f72=_0x221a4f?_0x1b6b72[_0x5b50('0x27')]:_0x506572[_0x5b50('0x28')]+_0x506572[_0x5b50('0x29')];var _0x62061a;if(_0x524f72>=_0x1d9c15){_0x524f72=_0x1d9c15;_0x62061a=0xc8;}else{_0x62061a=0xce;}_0x9cbdef['status'](_0x62061a);return _0x9cbdef[_0x5b50('0x2a')](_0x5b50('0x2b'),_0x228513+'-'+_0x524f72+'/'+_0x1d9c15)[_0x5b50('0x25')](_0x1b6b72);}return null;};}function patchUpdates(_0x31a81c){return function(_0x2b36dd){try{jsonpatch[_0x5b50('0x2c')](_0x2b36dd,_0x31a81c,!![]);}catch(_0x5d6996){return BPromise[_0x5b50('0x2d')](_0x5d6996);}return _0x2b36dd[_0x5b50('0x2e')]();};}function saveUpdates(_0x47469a,_0x1cf1e2){return function(_0x1a2b8c){if(_0x1a2b8c){return _0x1a2b8c[_0x5b50('0x2f')](_0x47469a)[_0x5b50('0x30')](function(_0x1f31c3){return _0x1f31c3;});}return null;};}function removeEntity(_0x172cea,_0x55fe41){return function(_0x44f522){if(_0x44f522){return _0x44f522[_0x5b50('0x31')]()[_0x5b50('0x30')](function(){_0x172cea[_0x5b50('0x24')](0xcc)['end']();});}};}function handleEntityNotFound(_0x390021,_0x4fd74c){return function(_0xa1351d){if(!_0xa1351d){_0x390021[_0x5b50('0x23')](0x194);}return _0xa1351d;};}function handleError(_0x410838,_0x4a9779){_0x4a9779=_0x4a9779||0x1f4;return function(_0x16784d){logger[_0x5b50('0x32')](_0x16784d['stack']);if(_0x16784d[_0x5b50('0x33')]){delete _0x16784d['name'];}_0x410838[_0x5b50('0x24')](_0x4a9779)[_0x5b50('0x34')](_0x16784d);};}exports[_0x5b50('0x35')]=function(_0x172817,_0x4bb4f1){var _0x51f97b={},_0xa33a2={},_0x4cf7a2={'count':0x0,'rows':[]};var _0x1e8f89=_[_0x5b50('0x36')](db[_0x5b50('0x37')][_0x5b50('0x38')],function(_0x4e763f){return{'name':_0x4e763f[_0x5b50('0x39')],'type':_0x4e763f[_0x5b50('0x3a')][_0x5b50('0x3b')]};});_0xa33a2[_0x5b50('0x3c')]=_[_0x5b50('0x36')](_0x1e8f89,_0x5b50('0x33'));_0xa33a2['query']=_['keys'](_0x172817[_0x5b50('0x3d')]);_0xa33a2[_0x5b50('0x3e')]=_[_0x5b50('0x3f')](_0xa33a2[_0x5b50('0x3c')],_0xa33a2['query']);_0x51f97b[_0x5b50('0x40')]=_[_0x5b50('0x3f')](_0xa33a2[_0x5b50('0x3c')],qs['fields'](_0x172817['query'][_0x5b50('0x41')]));_0x51f97b[_0x5b50('0x40')]=_0x51f97b['attributes'][_0x5b50('0x42')]?_0x51f97b[_0x5b50('0x40')]:_0xa33a2['model'];if(!_0x172817[_0x5b50('0x3d')][_0x5b50('0x43')](_0x5b50('0x44'))){_0x51f97b[_0x5b50('0x29')]=qs[_0x5b50('0x29')](_0x172817[_0x5b50('0x3d')][_0x5b50('0x29')]);_0x51f97b['offset']=qs[_0x5b50('0x28')](_0x172817[_0x5b50('0x3d')][_0x5b50('0x28')]);}_0x51f97b['order']=qs[_0x5b50('0x45')](_0x172817[_0x5b50('0x3d')][_0x5b50('0x45')]);_0x51f97b[_0x5b50('0x46')]=qs[_0x5b50('0x3e')](_['pick'](_0x172817[_0x5b50('0x3d')],_0xa33a2[_0x5b50('0x3e')]),_0x1e8f89);if(_0x172817[_0x5b50('0x3d')][_0x5b50('0x47')]){_0x51f97b['where']=_['merge'](_0x51f97b[_0x5b50('0x46')],{'$or':_[_0x5b50('0x36')](_0x1e8f89,function(_0x46a507){if(_0x46a507['type']!==_0x5b50('0x48')){var _0x1b6f1a={};_0x1b6f1a[_0x46a507[_0x5b50('0x33')]]={'$like':'%'+_0x172817[_0x5b50('0x3d')][_0x5b50('0x47')]+'%'};return _0x1b6f1a;}})});}_0x51f97b=_[_0x5b50('0x49')]({},_0x51f97b,_0x172817[_0x5b50('0x4a')]);var _0x43b7e8={'where':_0x51f97b['where']};return db[_0x5b50('0x37')]['count'](_0x43b7e8)[_0x5b50('0x30')](function(_0x315a07){_0x4cf7a2['count']=_0x315a07;if(_0x172817[_0x5b50('0x3d')][_0x5b50('0x4b')]){_0x51f97b[_0x5b50('0x4c')]=[{'all':!![]}];}return db[_0x5b50('0x37')][_0x5b50('0x4d')](_0x51f97b);})[_0x5b50('0x30')](function(_0xa3d6b9){_0x4cf7a2['rows']=_0xa3d6b9;return _0x4cf7a2;})['then'](respondWithFilteredResult(_0x4bb4f1,_0x51f97b))[_0x5b50('0x4e')](handleError(_0x4bb4f1,null));};exports[_0x5b50('0x4f')]=function(_0x34a239,_0x55f9ea){var _0x113903={'raw':![],'where':{'id':_0x34a239[_0x5b50('0x50')]['id']}},_0x183d42={};_0x183d42[_0x5b50('0x3c')]=_[_0x5b50('0x51')](db[_0x5b50('0x37')][_0x5b50('0x38')]);_0x183d42[_0x5b50('0x3d')]=_[_0x5b50('0x51')](_0x34a239[_0x5b50('0x3d')]);_0x183d42[_0x5b50('0x3e')]=_['intersection'](_0x183d42[_0x5b50('0x3c')],_0x183d42[_0x5b50('0x3d')]);_0x113903[_0x5b50('0x40')]=_[_0x5b50('0x3f')](_0x183d42[_0x5b50('0x3c')],qs[_0x5b50('0x41')](_0x34a239[_0x5b50('0x3d')][_0x5b50('0x41')]));_0x113903['attributes']=_0x113903[_0x5b50('0x40')][_0x5b50('0x42')]?_0x113903[_0x5b50('0x40')]:_0x183d42[_0x5b50('0x3c')];if(_0x34a239[_0x5b50('0x3d')][_0x5b50('0x4b')]){_0x113903[_0x5b50('0x4c')]=[{'all':!![]}];}_0x113903=_[_0x5b50('0x49')]({},_0x113903,_0x34a239['options']);return db[_0x5b50('0x37')]['find'](_0x113903)[_0x5b50('0x30')](handleEntityNotFound(_0x55f9ea,null))['then'](respondWithResult(_0x55f9ea,null))[_0x5b50('0x4e')](handleError(_0x55f9ea,null));};exports[_0x5b50('0x52')]=function(_0x22378e,_0x4b1c9b){return db[_0x5b50('0x37')][_0x5b50('0x52')](_0x22378e[_0x5b50('0x53')],{})[_0x5b50('0x30')](respondWithResult(_0x4b1c9b,0xc9))[_0x5b50('0x4e')](handleError(_0x4b1c9b,null));};exports[_0x5b50('0x2f')]=function(_0x3b8200,_0xaa931){if(_0x3b8200[_0x5b50('0x53')]['id']){delete _0x3b8200[_0x5b50('0x53')]['id'];}return db['VoiceQueueReport'][_0x5b50('0x54')]({'where':{'id':_0x3b8200[_0x5b50('0x50')]['id']}})[_0x5b50('0x30')](handleEntityNotFound(_0xaa931,null))['then'](saveUpdates(_0x3b8200[_0x5b50('0x53')],null))[_0x5b50('0x30')](respondWithResult(_0xaa931,null))['catch'](handleError(_0xaa931,null));};exports[_0x5b50('0x31')]=function(_0x174c85,_0x3b6098){return db[_0x5b50('0x37')][_0x5b50('0x54')]({'where':{'id':_0x174c85[_0x5b50('0x50')]['id']}})[_0x5b50('0x30')](handleEntityNotFound(_0x3b6098,null))['then'](removeEntity(_0x3b6098,null))[_0x5b50('0x4e')](handleError(_0x3b6098,null));};exports[_0x5b50('0x55')]=function(_0x57dd06,_0x3ed591){return db[_0x5b50('0x37')][_0x5b50('0x55')]()['then'](respondWithResult(_0x3ed591,null))[_0x5b50('0x4e')](handleError(_0x3ed591,null));};exports[_0x5b50('0x56')]=function(_0x54daad,_0x52a909){var _0x1c91c6={},_0x1a1ff2={},_0x55decf={'count':0x0,'rows':[]};_0x1a1ff2[_0x5b50('0x3c')]=_[_0x5b50('0x51')](db['VoiceQueueReport'][_0x5b50('0x38')]);_0x1a1ff2['query']=_[_0x5b50('0x51')](_0x54daad[_0x5b50('0x3d')]);_0x1a1ff2[_0x5b50('0x3e')]=_[_0x5b50('0x3f')](_0x1a1ff2[_0x5b50('0x3c')],_0x1a1ff2['query']);_0x1c91c6[_0x5b50('0x40')]=_[_0x5b50('0x3f')](_0x1a1ff2['model'],qs['fields'](_0x54daad['query']['fields']));_0x1c91c6['attributes']=_0x1c91c6['attributes'][_0x5b50('0x42')]?_0x1c91c6[_0x5b50('0x40')]:_0x1a1ff2['model'];if(!_0x54daad['query'][_0x5b50('0x43')](_0x5b50('0x44'))){_0x1c91c6[_0x5b50('0x29')]=qs[_0x5b50('0x29')](_0x54daad[_0x5b50('0x3d')][_0x5b50('0x29')]);_0x1c91c6['offset']=qs['offset'](_0x54daad['query'][_0x5b50('0x28')]);}_0x1c91c6[_0x5b50('0x57')]=qs['sort'](_0x54daad['query']['sort']);_0x1c91c6[_0x5b50('0x46')]=qs[_0x5b50('0x3e')](_[_0x5b50('0x58')](_0x54daad[_0x5b50('0x3d')],_0x1a1ff2[_0x5b50('0x3e')]));if(_0x54daad['query'][_0x5b50('0x47')]){_0x1c91c6[_0x5b50('0x46')]=_['merge'](_0x1c91c6[_0x5b50('0x46')],{'$or':_[_0x5b50('0x36')](_0x1c91c6['attributes'],function(_0x4216b1){var _0x27886f={};_0x27886f[_0x4216b1]={'$like':'%'+_0x54daad[_0x5b50('0x3d')]['filter']+'%'};return _0x27886f;})});}_0x1c91c6=_[_0x5b50('0x49')]({},_0x1c91c6,_0x54daad[_0x5b50('0x4a')]);var _0x538eef={'where':_0x1c91c6['where']};return db[_0x5b50('0x37')][_0x5b50('0x27')](_0x538eef)[_0x5b50('0x30')](function(_0x1ab4cc){_0x55decf[_0x5b50('0x27')]=_0x1ab4cc;if(_0x54daad[_0x5b50('0x3d')]['includeAll']){_0x1c91c6['include']=[{'all':!![]}];}return db[_0x5b50('0x37')]['findAll'](_0x1c91c6);})[_0x5b50('0x30')](function(_0x34bafe){_0x55decf[_0x5b50('0x59')]=_0x34bafe;return _0x55decf;})['then'](respondWithFilteredResult(_0x52a909,_0x1c91c6,'getVoiceQueuesReport'))[_0x5b50('0x4e')](handleError(_0x52a909,null,_0x5b50('0x56')));};