Built motion from commit 47436d59.|2.6.7
[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 _0x268b=['filter','where','merge','include','findAll','catch','show','params','includeAll','options','create','body','find','describe','getVoiceQueuesReport','rows','eml-format','rimraf','zip-dir','request-promise','moment','bluebird','util','path','ejs','fs-extra','lodash','squel','crypto','jsforce','to-csv','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis','defaults','localhost','socket.io-emitter','./voiceQueueReport.socket','sendStatus','status','json','offset','limit','undefined','count','Content-Range','apply','reject','save','update','destroy','then','end','error','stack','name','send','index','map','VoiceQueueReport','type','model','query','keys','filters','intersection','fields','attributes','length','hasOwnProperty','nolimit','order','sort','pick'];(function(_0x3f7768,_0x4fb38){var _0x18bf2f=function(_0x5610d0){while(--_0x5610d0){_0x3f7768['push'](_0x3f7768['shift']());}};_0x18bf2f(++_0x4fb38);}(_0x268b,0x106));var _0xb268=function(_0x53fe97,_0x544271){_0x53fe97=_0x53fe97-0x0;var _0x5c49a2=_0x268b[_0x53fe97];return _0x5c49a2;};'use strict';var emlformat=require(_0xb268('0x0'));var rimraf=require(_0xb268('0x1'));var zipdir=require(_0xb268('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0xb268('0x3'));var moment=require(_0xb268('0x4'));var BPromise=require(_0xb268('0x5'));var Mustache=require('mustache');var util=require(_0xb268('0x6'));var path=require(_0xb268('0x7'));var sox=require('sox');var csv=require('to-csv');var ejs=require(_0xb268('0x8'));var fs=require('fs');var fs_extra=require(_0xb268('0x9'));var _=require(_0xb268('0xa'));var squel=require(_0xb268('0xb'));var crypto=require(_0xb268('0xc'));var jsforce=require(_0xb268('0xd'));var deskjs=require('desk.js');var toCsv=require(_0xb268('0xe'));var querystring=require(_0xb268('0xf'));var Papa=require(_0xb268('0x10'));var Redis=require(_0xb268('0x11'));var authService=require(_0xb268('0x12'));var qs=require(_0xb268('0x13'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require('../../config/license/hardware');var logger=require(_0xb268('0x14'))('api');var utils=require(_0xb268('0x15'));var config=require(_0xb268('0x16'));var licenseUtil=require(_0xb268('0x17'));var db=require(_0xb268('0x18'))['db'];config[_0xb268('0x19')]=_[_0xb268('0x1a')](config['redis'],{'host':_0xb268('0x1b'),'port':0x18eb});var socket=require(_0xb268('0x1c'))(new Redis(config[_0xb268('0x19')]));require(_0xb268('0x1d'))['register'](socket);function respondWithStatusCode(_0x13f5d6,_0x512bd3){_0x512bd3=_0x512bd3||0xcc;return function(_0x5c3bab){if(_0x5c3bab){return _0x13f5d6[_0xb268('0x1e')](_0x512bd3);}return _0x13f5d6[_0xb268('0x1f')](_0x512bd3)['end']();};}function respondWithResult(_0x5c9d6c,_0x514a4c){_0x514a4c=_0x514a4c||0xc8;return function(_0x16c0fa){if(_0x16c0fa){return _0x5c9d6c['status'](_0x514a4c)[_0xb268('0x20')](_0x16c0fa);}};}function respondWithFilteredResult(_0x2f1c4c,_0x2d7e59){return function(_0xcc4099){if(_0xcc4099){var _0x563571=typeof _0x2d7e59[_0xb268('0x21')]==='undefined'&&typeof _0x2d7e59[_0xb268('0x22')]===_0xb268('0x23');var _0x17674f=_0xcc4099['count'];var _0x29a588=_0x563571?0x0:_0x2d7e59[_0xb268('0x21')];var _0xa51ee0=_0x563571?_0xcc4099[_0xb268('0x24')]:_0x2d7e59[_0xb268('0x21')]+_0x2d7e59['limit'];var _0x54d91f;if(_0xa51ee0>=_0x17674f){_0xa51ee0=_0x17674f;_0x54d91f=0xc8;}else{_0x54d91f=0xce;}_0x2f1c4c['status'](_0x54d91f);return _0x2f1c4c['set'](_0xb268('0x25'),_0x29a588+'-'+_0xa51ee0+'/'+_0x17674f)[_0xb268('0x20')](_0xcc4099);}return null;};}function patchUpdates(_0x3f9d0f){return function(_0x403499){try{jsonpatch[_0xb268('0x26')](_0x403499,_0x3f9d0f,!![]);}catch(_0x384b4a){return BPromise[_0xb268('0x27')](_0x384b4a);}return _0x403499[_0xb268('0x28')]();};}function saveUpdates(_0x2d6d35,_0x3000ed){return function(_0xbf2076){if(_0xbf2076){return _0xbf2076[_0xb268('0x29')](_0x2d6d35)['then'](function(_0x442e7e){return _0x442e7e;});}return null;};}function removeEntity(_0x55cd29,_0xa9320c){return function(_0x9c90df){if(_0x9c90df){return _0x9c90df[_0xb268('0x2a')]()[_0xb268('0x2b')](function(){_0x55cd29[_0xb268('0x1f')](0xcc)[_0xb268('0x2c')]();});}};}function handleEntityNotFound(_0x49d75b,_0x3a37ac){return function(_0x8be10c){if(!_0x8be10c){_0x49d75b[_0xb268('0x1e')](0x194);}return _0x8be10c;};}function handleError(_0x49f018,_0x5cc07d){_0x5cc07d=_0x5cc07d||0x1f4;return function(_0x2761a3){logger[_0xb268('0x2d')](_0x2761a3[_0xb268('0x2e')]);if(_0x2761a3[_0xb268('0x2f')]){delete _0x2761a3[_0xb268('0x2f')];}_0x49f018[_0xb268('0x1f')](_0x5cc07d)[_0xb268('0x30')](_0x2761a3);};}exports[_0xb268('0x31')]=function(_0x39917b,_0x5d8929){var _0x20f301={},_0x5c487a={},_0x3ba8b4={'count':0x0,'rows':[]};var _0xb19850=_[_0xb268('0x32')](db[_0xb268('0x33')]['rawAttributes'],function(_0x13e8ac){return{'name':_0x13e8ac['fieldName'],'type':_0x13e8ac[_0xb268('0x34')]['key']};});_0x5c487a[_0xb268('0x35')]=_[_0xb268('0x32')](_0xb19850,_0xb268('0x2f'));_0x5c487a[_0xb268('0x36')]=_[_0xb268('0x37')](_0x39917b[_0xb268('0x36')]);_0x5c487a[_0xb268('0x38')]=_[_0xb268('0x39')](_0x5c487a[_0xb268('0x35')],_0x5c487a[_0xb268('0x36')]);_0x20f301['attributes']=_[_0xb268('0x39')](_0x5c487a[_0xb268('0x35')],qs[_0xb268('0x3a')](_0x39917b['query'][_0xb268('0x3a')]));_0x20f301[_0xb268('0x3b')]=_0x20f301[_0xb268('0x3b')][_0xb268('0x3c')]?_0x20f301[_0xb268('0x3b')]:_0x5c487a['model'];if(!_0x39917b[_0xb268('0x36')][_0xb268('0x3d')](_0xb268('0x3e'))){_0x20f301['limit']=qs[_0xb268('0x22')](_0x39917b['query'][_0xb268('0x22')]);_0x20f301[_0xb268('0x21')]=qs['offset'](_0x39917b['query'][_0xb268('0x21')]);}_0x20f301[_0xb268('0x3f')]=qs[_0xb268('0x40')](_0x39917b['query']['sort']);_0x20f301['where']=qs[_0xb268('0x38')](_[_0xb268('0x41')](_0x39917b[_0xb268('0x36')],_0x5c487a[_0xb268('0x38')]),_0xb19850);if(_0x39917b[_0xb268('0x36')][_0xb268('0x42')]){_0x20f301[_0xb268('0x43')]=_[_0xb268('0x44')](_0x20f301[_0xb268('0x43')],{'$or':_[_0xb268('0x32')](_0xb19850,function(_0x489344){if(_0x489344[_0xb268('0x34')]!=='VIRTUAL'){var _0x13d36a={};_0x13d36a[_0x489344['name']]={'$like':'%'+_0x39917b[_0xb268('0x36')][_0xb268('0x42')]+'%'};return _0x13d36a;}})});}_0x20f301=_[_0xb268('0x44')]({},_0x20f301,_0x39917b['options']);var _0x31771d={'where':_0x20f301[_0xb268('0x43')]};return db['VoiceQueueReport'][_0xb268('0x24')](_0x31771d)[_0xb268('0x2b')](function(_0x57f5da){_0x3ba8b4[_0xb268('0x24')]=_0x57f5da;if(_0x39917b['query']['includeAll']){_0x20f301[_0xb268('0x45')]=[{'all':!![]}];}return db[_0xb268('0x33')][_0xb268('0x46')](_0x20f301);})['then'](function(_0x2f85d5){_0x3ba8b4['rows']=_0x2f85d5;return _0x3ba8b4;})[_0xb268('0x2b')](respondWithFilteredResult(_0x5d8929,_0x20f301))[_0xb268('0x47')](handleError(_0x5d8929,null));};exports[_0xb268('0x48')]=function(_0x1930c4,_0x2c08e5){var _0xf29f1c={'raw':![],'where':{'id':_0x1930c4[_0xb268('0x49')]['id']}},_0x1b22bf={};_0x1b22bf[_0xb268('0x35')]=_[_0xb268('0x37')](db[_0xb268('0x33')]['rawAttributes']);_0x1b22bf['query']=_[_0xb268('0x37')](_0x1930c4[_0xb268('0x36')]);_0x1b22bf['filters']=_[_0xb268('0x39')](_0x1b22bf[_0xb268('0x35')],_0x1b22bf[_0xb268('0x36')]);_0xf29f1c[_0xb268('0x3b')]=_[_0xb268('0x39')](_0x1b22bf['model'],qs['fields'](_0x1930c4[_0xb268('0x36')][_0xb268('0x3a')]));_0xf29f1c[_0xb268('0x3b')]=_0xf29f1c[_0xb268('0x3b')][_0xb268('0x3c')]?_0xf29f1c[_0xb268('0x3b')]:_0x1b22bf[_0xb268('0x35')];if(_0x1930c4['query'][_0xb268('0x4a')]){_0xf29f1c['include']=[{'all':!![]}];}_0xf29f1c=_[_0xb268('0x44')]({},_0xf29f1c,_0x1930c4[_0xb268('0x4b')]);return db[_0xb268('0x33')]['find'](_0xf29f1c)[_0xb268('0x2b')](handleEntityNotFound(_0x2c08e5,null))['then'](respondWithResult(_0x2c08e5,null))[_0xb268('0x47')](handleError(_0x2c08e5,null));};exports[_0xb268('0x4c')]=function(_0x29b45d,_0x26b8f3){return db['VoiceQueueReport'][_0xb268('0x4c')](_0x29b45d[_0xb268('0x4d')],{})[_0xb268('0x2b')](respondWithResult(_0x26b8f3,0xc9))[_0xb268('0x47')](handleError(_0x26b8f3,null));};exports[_0xb268('0x29')]=function(_0x5f0443,_0x1d5e9a){if(_0x5f0443[_0xb268('0x4d')]['id']){delete _0x5f0443['body']['id'];}return db[_0xb268('0x33')][_0xb268('0x4e')]({'where':{'id':_0x5f0443[_0xb268('0x49')]['id']}})[_0xb268('0x2b')](handleEntityNotFound(_0x1d5e9a,null))['then'](saveUpdates(_0x5f0443[_0xb268('0x4d')],null))[_0xb268('0x2b')](respondWithResult(_0x1d5e9a,null))[_0xb268('0x47')](handleError(_0x1d5e9a,null));};exports['destroy']=function(_0x245c9b,_0xa19064){return db['VoiceQueueReport'][_0xb268('0x4e')]({'where':{'id':_0x245c9b[_0xb268('0x49')]['id']}})[_0xb268('0x2b')](handleEntityNotFound(_0xa19064,null))[_0xb268('0x2b')](removeEntity(_0xa19064,null))[_0xb268('0x47')](handleError(_0xa19064,null));};exports['describe']=function(_0x437f59,_0x2ab17d){return db['VoiceQueueReport'][_0xb268('0x4f')]()[_0xb268('0x2b')](respondWithResult(_0x2ab17d,null))['catch'](handleError(_0x2ab17d,null));};exports[_0xb268('0x50')]=function(_0x3987a7,_0x16a4ce){var _0x5b7ffd={},_0x551371={},_0x3c46a9={'count':0x0,'rows':[]};_0x551371['model']=_[_0xb268('0x37')](db[_0xb268('0x33')]['rawAttributes']);_0x551371[_0xb268('0x36')]=_['keys'](_0x3987a7[_0xb268('0x36')]);_0x551371[_0xb268('0x38')]=_[_0xb268('0x39')](_0x551371[_0xb268('0x35')],_0x551371['query']);_0x5b7ffd[_0xb268('0x3b')]=_['intersection'](_0x551371['model'],qs[_0xb268('0x3a')](_0x3987a7[_0xb268('0x36')][_0xb268('0x3a')]));_0x5b7ffd[_0xb268('0x3b')]=_0x5b7ffd[_0xb268('0x3b')][_0xb268('0x3c')]?_0x5b7ffd[_0xb268('0x3b')]:_0x551371['model'];if(!_0x3987a7['query'][_0xb268('0x3d')](_0xb268('0x3e'))){_0x5b7ffd['limit']=qs[_0xb268('0x22')](_0x3987a7['query'][_0xb268('0x22')]);_0x5b7ffd['offset']=qs[_0xb268('0x21')](_0x3987a7[_0xb268('0x36')]['offset']);}_0x5b7ffd[_0xb268('0x3f')]=qs[_0xb268('0x40')](_0x3987a7[_0xb268('0x36')][_0xb268('0x40')]);_0x5b7ffd[_0xb268('0x43')]=qs['filters'](_['pick'](_0x3987a7[_0xb268('0x36')],_0x551371[_0xb268('0x38')]));if(_0x3987a7[_0xb268('0x36')][_0xb268('0x42')]){_0x5b7ffd[_0xb268('0x43')]=_[_0xb268('0x44')](_0x5b7ffd[_0xb268('0x43')],{'$or':_[_0xb268('0x32')](_0x5b7ffd[_0xb268('0x3b')],function(_0x1af7b1){var _0x56ed7b={};_0x56ed7b[_0x1af7b1]={'$like':'%'+_0x3987a7[_0xb268('0x36')]['filter']+'%'};return _0x56ed7b;})});}_0x5b7ffd=_[_0xb268('0x44')]({},_0x5b7ffd,_0x3987a7[_0xb268('0x4b')]);var _0x5404b9={'where':_0x5b7ffd[_0xb268('0x43')]};return db[_0xb268('0x33')][_0xb268('0x24')](_0x5404b9)['then'](function(_0x33af03){_0x3c46a9[_0xb268('0x24')]=_0x33af03;if(_0x3987a7['query'][_0xb268('0x4a')]){_0x5b7ffd[_0xb268('0x45')]=[{'all':!![]}];}return db['VoiceQueueReport'][_0xb268('0x46')](_0x5b7ffd);})[_0xb268('0x2b')](function(_0x379701){_0x3c46a9[_0xb268('0x51')]=_0x379701;return _0x3c46a9;})['then'](respondWithFilteredResult(_0x16a4ce,_0x5b7ffd,_0xb268('0x50')))['catch'](handleError(_0x16a4ce,null,_0xb268('0x50')));};