Built motion from commit (unavailable).|2.5.29
[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 _0xc582=['set','apply','reject','save','update','then','sendStatus','error','stack','name','send','index','map','rawAttributes','fieldName','type','query','keys','filters','intersection','model','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','merge','VIRTUAL','filter','options','VoiceQueueReport','includeAll','findAll','params','include','find','catch','create','body','destroy','getVoiceQueuesReport','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','util','path','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis','defaults','localhost','socket.io-emitter','./voiceQueueReport.socket','register','status','end','json','offset','undefined','limit','count'];(function(_0x160c73,_0x2ee678){var _0xd9302=function(_0x169454){while(--_0x169454){_0x160c73['push'](_0x160c73['shift']());}};_0xd9302(++_0x2ee678);}(_0xc582,0x132));var _0x2c58=function(_0x74892f,_0x1e981b){_0x74892f=_0x74892f-0x0;var _0x10ee61=_0xc582[_0x74892f];return _0x10ee61;};'use strict';var emlformat=require(_0x2c58('0x0'));var rimraf=require(_0x2c58('0x1'));var zipdir=require(_0x2c58('0x2'));var jsonpatch=require(_0x2c58('0x3'));var rp=require(_0x2c58('0x4'));var moment=require(_0x2c58('0x5'));var BPromise=require('bluebird');var Mustache=require('mustache');var util=require(_0x2c58('0x6'));var path=require(_0x2c58('0x7'));var sox=require(_0x2c58('0x8'));var csv=require(_0x2c58('0x9'));var ejs=require(_0x2c58('0xa'));var fs=require('fs');var fs_extra=require(_0x2c58('0xb'));var _=require(_0x2c58('0xc'));var squel=require(_0x2c58('0xd'));var crypto=require(_0x2c58('0xe'));var jsforce=require(_0x2c58('0xf'));var deskjs=require(_0x2c58('0x10'));var toCsv=require(_0x2c58('0x9'));var querystring=require(_0x2c58('0x11'));var Papa=require(_0x2c58('0x12'));var Redis=require(_0x2c58('0x13'));var authService=require('../../components/auth/service');var qs=require(_0x2c58('0x14'));var as=require(_0x2c58('0x15'));var hardwareService=require(_0x2c58('0x16'));var logger=require(_0x2c58('0x17'))(_0x2c58('0x18'));var utils=require(_0x2c58('0x19'));var config=require(_0x2c58('0x1a'));var licenseUtil=require(_0x2c58('0x1b'));var db=require(_0x2c58('0x1c'))['db'];config[_0x2c58('0x1d')]=_[_0x2c58('0x1e')](config['redis'],{'host':_0x2c58('0x1f'),'port':0x18eb});var socket=require(_0x2c58('0x20'))(new Redis(config[_0x2c58('0x1d')]));require(_0x2c58('0x21'))[_0x2c58('0x22')](socket);function respondWithStatusCode(_0x7c14fa,_0x3e3b0f){_0x3e3b0f=_0x3e3b0f||0xcc;return function(_0x23eba7){if(_0x23eba7){return _0x7c14fa['sendStatus'](_0x3e3b0f);}return _0x7c14fa[_0x2c58('0x23')](_0x3e3b0f)[_0x2c58('0x24')]();};}function respondWithResult(_0x56fac5,_0x2d1a4c){_0x2d1a4c=_0x2d1a4c||0xc8;return function(_0x134716){if(_0x134716){return _0x56fac5[_0x2c58('0x23')](_0x2d1a4c)[_0x2c58('0x25')](_0x134716);}};}function respondWithFilteredResult(_0x2b3b0d,_0x2913d3){return function(_0x13ba25){if(_0x13ba25){var _0x1e38fe=typeof _0x2913d3[_0x2c58('0x26')]===_0x2c58('0x27')&&typeof _0x2913d3[_0x2c58('0x28')]===_0x2c58('0x27');var _0x357748=_0x13ba25[_0x2c58('0x29')];var _0x2a8519=_0x1e38fe?0x0:_0x2913d3['offset'];var _0x384559=_0x1e38fe?_0x13ba25[_0x2c58('0x29')]:_0x2913d3[_0x2c58('0x26')]+_0x2913d3[_0x2c58('0x28')];var _0xcb574b;if(_0x384559>=_0x357748){_0x384559=_0x357748;_0xcb574b=0xc8;}else{_0xcb574b=0xce;}_0x2b3b0d['status'](_0xcb574b);return _0x2b3b0d[_0x2c58('0x2a')]('Content-Range',_0x2a8519+'-'+_0x384559+'/'+_0x357748)['json'](_0x13ba25);}return null;};}function patchUpdates(_0x212630){return function(_0x2e4026){try{jsonpatch[_0x2c58('0x2b')](_0x2e4026,_0x212630,!![]);}catch(_0x45cefc){return BPromise[_0x2c58('0x2c')](_0x45cefc);}return _0x2e4026[_0x2c58('0x2d')]();};}function saveUpdates(_0x190360,_0x589655){return function(_0x536e2a){if(_0x536e2a){return _0x536e2a[_0x2c58('0x2e')](_0x190360)['then'](function(_0x4df470){return _0x4df470;});}return null;};}function removeEntity(_0x292c2d,_0x1ada44){return function(_0x27b8b1){if(_0x27b8b1){return _0x27b8b1['destroy']()[_0x2c58('0x2f')](function(){_0x292c2d[_0x2c58('0x23')](0xcc)[_0x2c58('0x24')]();});}};}function handleEntityNotFound(_0x480345,_0x2a8135){return function(_0x1e35d1){if(!_0x1e35d1){_0x480345[_0x2c58('0x30')](0x194);}return _0x1e35d1;};}function handleError(_0x403263,_0x196ede){_0x196ede=_0x196ede||0x1f4;return function(_0x31918c){logger[_0x2c58('0x31')](_0x31918c[_0x2c58('0x32')]);if(_0x31918c[_0x2c58('0x33')]){delete _0x31918c[_0x2c58('0x33')];}_0x403263[_0x2c58('0x23')](_0x196ede)[_0x2c58('0x34')](_0x31918c);};}exports[_0x2c58('0x35')]=function(_0x38f463,_0x3823d4){var _0x5f5299={},_0x364f83={},_0x16c3c8={'count':0x0,'rows':[]};var _0xc301f5=_[_0x2c58('0x36')](db['VoiceQueueReport'][_0x2c58('0x37')],function(_0x483227){return{'name':_0x483227[_0x2c58('0x38')],'type':_0x483227[_0x2c58('0x39')]['key']};});_0x364f83['model']=_['map'](_0xc301f5,'name');_0x364f83[_0x2c58('0x3a')]=_[_0x2c58('0x3b')](_0x38f463[_0x2c58('0x3a')]);_0x364f83[_0x2c58('0x3c')]=_[_0x2c58('0x3d')](_0x364f83[_0x2c58('0x3e')],_0x364f83[_0x2c58('0x3a')]);_0x5f5299[_0x2c58('0x3f')]=_['intersection'](_0x364f83[_0x2c58('0x3e')],qs[_0x2c58('0x40')](_0x38f463[_0x2c58('0x3a')][_0x2c58('0x40')]));_0x5f5299[_0x2c58('0x3f')]=_0x5f5299[_0x2c58('0x3f')][_0x2c58('0x41')]?_0x5f5299[_0x2c58('0x3f')]:_0x364f83[_0x2c58('0x3e')];if(!_0x38f463['query'][_0x2c58('0x42')](_0x2c58('0x43'))){_0x5f5299['limit']=qs[_0x2c58('0x28')](_0x38f463[_0x2c58('0x3a')]['limit']);_0x5f5299[_0x2c58('0x26')]=qs[_0x2c58('0x26')](_0x38f463[_0x2c58('0x3a')]['offset']);}_0x5f5299[_0x2c58('0x44')]=qs[_0x2c58('0x45')](_0x38f463[_0x2c58('0x3a')][_0x2c58('0x45')]);_0x5f5299[_0x2c58('0x46')]=qs[_0x2c58('0x3c')](_[_0x2c58('0x47')](_0x38f463['query'],_0x364f83['filters']),_0xc301f5);if(_0x38f463[_0x2c58('0x3a')]['filter']){_0x5f5299[_0x2c58('0x46')]=_[_0x2c58('0x48')](_0x5f5299[_0x2c58('0x46')],{'$or':_[_0x2c58('0x36')](_0xc301f5,function(_0x831844){if(_0x831844[_0x2c58('0x39')]!==_0x2c58('0x49')){var _0x3f2ba7={};_0x3f2ba7[_0x831844['name']]={'$like':'%'+_0x38f463[_0x2c58('0x3a')][_0x2c58('0x4a')]+'%'};return _0x3f2ba7;}})});}_0x5f5299=_[_0x2c58('0x48')]({},_0x5f5299,_0x38f463[_0x2c58('0x4b')]);var _0x384a32={'where':_0x5f5299['where']};return db[_0x2c58('0x4c')][_0x2c58('0x29')](_0x384a32)[_0x2c58('0x2f')](function(_0x21629d){_0x16c3c8[_0x2c58('0x29')]=_0x21629d;if(_0x38f463[_0x2c58('0x3a')][_0x2c58('0x4d')]){_0x5f5299['include']=[{'all':!![]}];}return db[_0x2c58('0x4c')][_0x2c58('0x4e')](_0x5f5299);})[_0x2c58('0x2f')](function(_0x5fffa8){_0x16c3c8['rows']=_0x5fffa8;return _0x16c3c8;})[_0x2c58('0x2f')](respondWithFilteredResult(_0x3823d4,_0x5f5299))['catch'](handleError(_0x3823d4,null));};exports['show']=function(_0x5a958a,_0x586a5c){var _0x30365f={'raw':![],'where':{'id':_0x5a958a[_0x2c58('0x4f')]['id']}},_0x17c7e9={};_0x17c7e9[_0x2c58('0x3e')]=_['keys'](db[_0x2c58('0x4c')][_0x2c58('0x37')]);_0x17c7e9[_0x2c58('0x3a')]=_[_0x2c58('0x3b')](_0x5a958a[_0x2c58('0x3a')]);_0x17c7e9[_0x2c58('0x3c')]=_['intersection'](_0x17c7e9['model'],_0x17c7e9['query']);_0x30365f[_0x2c58('0x3f')]=_['intersection'](_0x17c7e9[_0x2c58('0x3e')],qs[_0x2c58('0x40')](_0x5a958a[_0x2c58('0x3a')][_0x2c58('0x40')]));_0x30365f['attributes']=_0x30365f['attributes'][_0x2c58('0x41')]?_0x30365f[_0x2c58('0x3f')]:_0x17c7e9[_0x2c58('0x3e')];if(_0x5a958a[_0x2c58('0x3a')][_0x2c58('0x4d')]){_0x30365f[_0x2c58('0x50')]=[{'all':!![]}];}_0x30365f=_[_0x2c58('0x48')]({},_0x30365f,_0x5a958a[_0x2c58('0x4b')]);return db['VoiceQueueReport'][_0x2c58('0x51')](_0x30365f)['then'](handleEntityNotFound(_0x586a5c,null))[_0x2c58('0x2f')](respondWithResult(_0x586a5c,null))[_0x2c58('0x52')](handleError(_0x586a5c,null));};exports[_0x2c58('0x53')]=function(_0x499b69,_0x2d17e9){return db[_0x2c58('0x4c')]['create'](_0x499b69['body'],{})[_0x2c58('0x2f')](respondWithResult(_0x2d17e9,0xc9))['catch'](handleError(_0x2d17e9,null));};exports[_0x2c58('0x2e')]=function(_0x19d15f,_0x44095b){if(_0x19d15f[_0x2c58('0x54')]['id']){delete _0x19d15f[_0x2c58('0x54')]['id'];}return db[_0x2c58('0x4c')]['find']({'where':{'id':_0x19d15f['params']['id']}})[_0x2c58('0x2f')](handleEntityNotFound(_0x44095b,null))[_0x2c58('0x2f')](saveUpdates(_0x19d15f[_0x2c58('0x54')],null))[_0x2c58('0x2f')](respondWithResult(_0x44095b,null))[_0x2c58('0x52')](handleError(_0x44095b,null));};exports[_0x2c58('0x55')]=function(_0x3db8cd,_0x65dcaa){return db[_0x2c58('0x4c')][_0x2c58('0x51')]({'where':{'id':_0x3db8cd['params']['id']}})['then'](handleEntityNotFound(_0x65dcaa,null))[_0x2c58('0x2f')](removeEntity(_0x65dcaa,null))[_0x2c58('0x52')](handleError(_0x65dcaa,null));};exports['describe']=function(_0x205f64,_0x1a5da2){return db[_0x2c58('0x4c')]['describe']()[_0x2c58('0x2f')](respondWithResult(_0x1a5da2,null))[_0x2c58('0x52')](handleError(_0x1a5da2,null));};exports['getVoiceQueuesReport']=function(_0x2ef8fa,_0x1fa8d6){var _0x37e8ea={},_0x38af95={},_0x461c21={'count':0x0,'rows':[]};_0x38af95['model']=_[_0x2c58('0x3b')](db[_0x2c58('0x4c')][_0x2c58('0x37')]);_0x38af95[_0x2c58('0x3a')]=_[_0x2c58('0x3b')](_0x2ef8fa[_0x2c58('0x3a')]);_0x38af95[_0x2c58('0x3c')]=_[_0x2c58('0x3d')](_0x38af95[_0x2c58('0x3e')],_0x38af95[_0x2c58('0x3a')]);_0x37e8ea[_0x2c58('0x3f')]=_[_0x2c58('0x3d')](_0x38af95[_0x2c58('0x3e')],qs[_0x2c58('0x40')](_0x2ef8fa['query'][_0x2c58('0x40')]));_0x37e8ea['attributes']=_0x37e8ea[_0x2c58('0x3f')]['length']?_0x37e8ea[_0x2c58('0x3f')]:_0x38af95[_0x2c58('0x3e')];if(!_0x2ef8fa[_0x2c58('0x3a')]['hasOwnProperty'](_0x2c58('0x43'))){_0x37e8ea[_0x2c58('0x28')]=qs['limit'](_0x2ef8fa[_0x2c58('0x3a')][_0x2c58('0x28')]);_0x37e8ea[_0x2c58('0x26')]=qs[_0x2c58('0x26')](_0x2ef8fa[_0x2c58('0x3a')][_0x2c58('0x26')]);}_0x37e8ea[_0x2c58('0x44')]=qs[_0x2c58('0x45')](_0x2ef8fa[_0x2c58('0x3a')][_0x2c58('0x45')]);_0x37e8ea['where']=qs[_0x2c58('0x3c')](_[_0x2c58('0x47')](_0x2ef8fa[_0x2c58('0x3a')],_0x38af95[_0x2c58('0x3c')]));if(_0x2ef8fa[_0x2c58('0x3a')][_0x2c58('0x4a')]){_0x37e8ea[_0x2c58('0x46')]=_['merge'](_0x37e8ea[_0x2c58('0x46')],{'$or':_['map'](_0x37e8ea['attributes'],function(_0x2464b2){var _0x673ea3={};_0x673ea3[_0x2464b2]={'$like':'%'+_0x2ef8fa[_0x2c58('0x3a')][_0x2c58('0x4a')]+'%'};return _0x673ea3;})});}_0x37e8ea=_[_0x2c58('0x48')]({},_0x37e8ea,_0x2ef8fa[_0x2c58('0x4b')]);var _0x2ff070={'where':_0x37e8ea[_0x2c58('0x46')]};return db['VoiceQueueReport'][_0x2c58('0x29')](_0x2ff070)[_0x2c58('0x2f')](function(_0x50ec3e){_0x461c21[_0x2c58('0x29')]=_0x50ec3e;if(_0x2ef8fa['query'][_0x2c58('0x4d')]){_0x37e8ea[_0x2c58('0x50')]=[{'all':!![]}];}return db[_0x2c58('0x4c')][_0x2c58('0x4e')](_0x37e8ea);})[_0x2c58('0x2f')](function(_0x526f04){_0x461c21['rows']=_0x526f04;return _0x461c21;})[_0x2c58('0x2f')](respondWithFilteredResult(_0x1fa8d6,_0x37e8ea,_0x2c58('0x56')))[_0x2c58('0x52')](handleError(_0x1fa8d6,null,_0x2c58('0x56')));};