Built motion from commit a61a4a20.|2.5.46
[motion2.git] / server / api / analyticExtractedReport / analyticExtractedReport.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 _0x450f=['AnalyticExtractedReport','includeAll','findAll','rows','catch','show','keys','length','include','find','create','body','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','params','download','basename','savename','output','join','root','Sequelize','ValidationError','Report\x20not\x20found\x20or\x20empty','exists','server/files/reports','format','%s.%s','toLowerCase','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','fs-extra','squel','crypto','desk.js','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','offset','undefined','limit','count','set','Content-Range','json','apply','reject','update','destroy','then','get','ExtractedReports','UserProfileResource','end','error','name','send','index','map','rawAttributes','fieldName','type','key','model','query','filters','intersection','attributes','fields','hasOwnProperty','nolimit','sort','where','pick','filter','merge','VIRTUAL','options'];(function(_0x2ec2c6,_0x4087a2){var _0x52d5a3=function(_0x2341a6){while(--_0x2341a6){_0x2ec2c6['push'](_0x2ec2c6['shift']());}};_0x52d5a3(++_0x4087a2);}(_0x450f,0x1b1));var _0xf450=function(_0x48b329,_0xa9c97f){_0x48b329=_0x48b329-0x0;var _0x2ac307=_0x450f[_0x48b329];return _0x2ac307;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0xf450('0x0'));var zipdir=require(_0xf450('0x1'));var jsonpatch=require(_0xf450('0x2'));var rp=require(_0xf450('0x3'));var moment=require(_0xf450('0x4'));var BPromise=require(_0xf450('0x5'));var Mustache=require(_0xf450('0x6'));var util=require(_0xf450('0x7'));var path=require(_0xf450('0x8'));var sox=require(_0xf450('0x9'));var csv=require(_0xf450('0xa'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0xf450('0xb'));var _=require('lodash');var squel=require(_0xf450('0xc'));var crypto=require(_0xf450('0xd'));var jsforce=require('jsforce');var deskjs=require(_0xf450('0xe'));var toCsv=require(_0xf450('0xa'));var querystring=require('querystring');var Papa=require(_0xf450('0xf'));var Redis=require(_0xf450('0x10'));var authService=require(_0xf450('0x11'));var qs=require('../../components/parsers/qs');var as=require(_0xf450('0x12'));var hardwareService=require('../../config/license/hardware');var logger=require(_0xf450('0x13'))(_0xf450('0x14'));var utils=require(_0xf450('0x15'));var config=require(_0xf450('0x16'));var licenseUtil=require(_0xf450('0x17'));var db=require(_0xf450('0x18'))['db'];function respondWithStatusCode(_0x1fd279,_0x4a26a8){_0x4a26a8=_0x4a26a8||0xcc;return function(_0x5cfc22){if(_0x5cfc22){return _0x1fd279[_0xf450('0x19')](_0x4a26a8);}return _0x1fd279[_0xf450('0x1a')](_0x4a26a8)['end']();};}function respondWithResult(_0x5740d1,_0x5e981a){_0x5e981a=_0x5e981a||0xc8;return function(_0x41173c){if(_0x41173c){return _0x5740d1[_0xf450('0x1a')](_0x5e981a)['json'](_0x41173c);}};}function respondWithFilteredResult(_0x53fa4c,_0x5cd454){return function(_0x38ec4b){if(_0x38ec4b){var _0x53adc4=typeof _0x5cd454[_0xf450('0x1b')]===_0xf450('0x1c')&&typeof _0x5cd454[_0xf450('0x1d')]===_0xf450('0x1c');var _0x1528cb=_0x38ec4b[_0xf450('0x1e')];var _0x4a1109=_0x53adc4?0x0:_0x5cd454['offset'];var _0x15198=_0x53adc4?_0x38ec4b[_0xf450('0x1e')]:_0x5cd454['offset']+_0x5cd454[_0xf450('0x1d')];var _0x1eb68b;if(_0x15198>=_0x1528cb){_0x15198=_0x1528cb;_0x1eb68b=0xc8;}else{_0x1eb68b=0xce;}_0x53fa4c[_0xf450('0x1a')](_0x1eb68b);return _0x53fa4c[_0xf450('0x1f')](_0xf450('0x20'),_0x4a1109+'-'+_0x15198+'/'+_0x1528cb)[_0xf450('0x21')](_0x38ec4b);}return null;};}function patchUpdates(_0x27407c){return function(_0x33a716){try{jsonpatch[_0xf450('0x22')](_0x33a716,_0x27407c,!![]);}catch(_0xbf2c3c){return BPromise[_0xf450('0x23')](_0xbf2c3c);}return _0x33a716['save']();};}function saveUpdates(_0x5245bf,_0x12c386){return function(_0x1e058f){if(_0x1e058f){return _0x1e058f[_0xf450('0x24')](_0x5245bf)['then'](function(_0x322ce5){return _0x322ce5;});}return null;};}function removeEntity(_0x4e547f,_0x5323f9){return function(_0x1af8eb){if(_0x1af8eb){return _0x1af8eb[_0xf450('0x25')]()[_0xf450('0x26')](function(){var _0x1c9b3b=_0x1af8eb[_0xf450('0x27')]({'plain':!![]});var _0x43387f=_0xf450('0x28');return db[_0xf450('0x29')][_0xf450('0x25')]({'where':{'type':_0x43387f,'resourceId':_0x1c9b3b['id']}})[_0xf450('0x26')](function(){return _0x1af8eb;});})['then'](function(){_0x4e547f[_0xf450('0x1a')](0xcc)[_0xf450('0x2a')]();});}};}function handleEntityNotFound(_0x53b37b,_0x55b5dd){return function(_0x531ab6){if(!_0x531ab6){_0x53b37b[_0xf450('0x19')](0x194);}return _0x531ab6;};}function handleError(_0xf7b51,_0x55c456){_0x55c456=_0x55c456||0x1f4;return function(_0x1600ed){logger[_0xf450('0x2b')](_0x1600ed['stack']);if(_0x1600ed[_0xf450('0x2c')]){delete _0x1600ed[_0xf450('0x2c')];}_0xf7b51[_0xf450('0x1a')](_0x55c456)[_0xf450('0x2d')](_0x1600ed);};}exports[_0xf450('0x2e')]=function(_0x84978e,_0x5b2131){var _0x358ab8={},_0x2c37c8={},_0x6b1fd5={'count':0x0,'rows':[]};var _0x30d24e=_[_0xf450('0x2f')](db['AnalyticExtractedReport'][_0xf450('0x30')],function(_0x535164){return{'name':_0x535164[_0xf450('0x31')],'type':_0x535164[_0xf450('0x32')][_0xf450('0x33')]};});_0x2c37c8[_0xf450('0x34')]=_[_0xf450('0x2f')](_0x30d24e,_0xf450('0x2c'));_0x2c37c8[_0xf450('0x35')]=_['keys'](_0x84978e[_0xf450('0x35')]);_0x2c37c8[_0xf450('0x36')]=_[_0xf450('0x37')](_0x2c37c8[_0xf450('0x34')],_0x2c37c8[_0xf450('0x35')]);_0x358ab8[_0xf450('0x38')]=_[_0xf450('0x37')](_0x2c37c8[_0xf450('0x34')],qs[_0xf450('0x39')](_0x84978e[_0xf450('0x35')][_0xf450('0x39')]));_0x358ab8[_0xf450('0x38')]=_0x358ab8['attributes']['length']?_0x358ab8[_0xf450('0x38')]:_0x2c37c8['model'];if(!_0x84978e[_0xf450('0x35')][_0xf450('0x3a')](_0xf450('0x3b'))){_0x358ab8[_0xf450('0x1d')]=qs[_0xf450('0x1d')](_0x84978e[_0xf450('0x35')]['limit']);_0x358ab8[_0xf450('0x1b')]=qs[_0xf450('0x1b')](_0x84978e[_0xf450('0x35')]['offset']);}_0x358ab8['order']=qs[_0xf450('0x3c')](_0x84978e[_0xf450('0x35')][_0xf450('0x3c')]);_0x358ab8[_0xf450('0x3d')]=qs[_0xf450('0x36')](_[_0xf450('0x3e')](_0x84978e[_0xf450('0x35')],_0x2c37c8[_0xf450('0x36')]),_0x30d24e);if(_0x84978e['query'][_0xf450('0x3f')]){_0x358ab8[_0xf450('0x3d')]=_[_0xf450('0x40')](_0x358ab8[_0xf450('0x3d')],{'$or':_[_0xf450('0x2f')](_0x30d24e,function(_0xfd0887){if(_0xfd0887[_0xf450('0x32')]!==_0xf450('0x41')){var _0x579caa={};_0x579caa[_0xfd0887['name']]={'$like':'%'+_0x84978e[_0xf450('0x35')]['filter']+'%'};return _0x579caa;}})});}_0x358ab8=_['merge']({},_0x358ab8,_0x84978e[_0xf450('0x42')]);var _0x39a5be={'where':_0x358ab8['where']};return db[_0xf450('0x43')][_0xf450('0x1e')](_0x39a5be)[_0xf450('0x26')](function(_0xb78186){_0x6b1fd5['count']=_0xb78186;if(_0x84978e[_0xf450('0x35')][_0xf450('0x44')]){_0x358ab8['include']=[{'all':!![]}];}return db[_0xf450('0x43')][_0xf450('0x45')](_0x358ab8);})['then'](function(_0x288bb5){_0x6b1fd5[_0xf450('0x46')]=_0x288bb5;return _0x6b1fd5;})[_0xf450('0x26')](respondWithFilteredResult(_0x5b2131,_0x358ab8))[_0xf450('0x47')](handleError(_0x5b2131,null));};exports[_0xf450('0x48')]=function(_0x47d6b8,_0x4f8cf4){var _0x150f7b={'raw':!![],'where':{'id':_0x47d6b8['params']['id']}},_0x396732={};_0x396732[_0xf450('0x34')]=_[_0xf450('0x49')](db[_0xf450('0x43')]['rawAttributes']);_0x396732[_0xf450('0x35')]=_[_0xf450('0x49')](_0x47d6b8[_0xf450('0x35')]);_0x396732[_0xf450('0x36')]=_[_0xf450('0x37')](_0x396732[_0xf450('0x34')],_0x396732[_0xf450('0x35')]);_0x150f7b[_0xf450('0x38')]=_[_0xf450('0x37')](_0x396732[_0xf450('0x34')],qs[_0xf450('0x39')](_0x47d6b8['query']['fields']));_0x150f7b[_0xf450('0x38')]=_0x150f7b[_0xf450('0x38')][_0xf450('0x4a')]?_0x150f7b[_0xf450('0x38')]:_0x396732[_0xf450('0x34')];if(_0x47d6b8['query'][_0xf450('0x44')]){_0x150f7b[_0xf450('0x4b')]=[{'all':!![]}];}_0x150f7b=_[_0xf450('0x40')]({},_0x150f7b,_0x47d6b8['options']);return db[_0xf450('0x43')][_0xf450('0x4c')](_0x150f7b)[_0xf450('0x26')](handleEntityNotFound(_0x4f8cf4,null))[_0xf450('0x26')](respondWithResult(_0x4f8cf4,null))[_0xf450('0x47')](handleError(_0x4f8cf4,null));};exports[_0xf450('0x4d')]=function(_0x1a8ef5,_0x51a570){return db[_0xf450('0x43')][_0xf450('0x4d')](_0x1a8ef5[_0xf450('0x4e')],{})[_0xf450('0x26')](function(_0x576123){var _0xb4b11=_0x1a8ef5['user'][_0xf450('0x27')]({'plain':!![]});if(!_0xb4b11)throw new Error(_0xf450('0x4f'));if(_0xb4b11[_0xf450('0x50')]==='user'){var _0x3fc1e1=_0x576123[_0xf450('0x27')]({'plain':!![]});var _0x45c95c=_0xf450('0x28');return db[_0xf450('0x51')][_0xf450('0x4c')]({'where':{'name':_0x45c95c,'userProfileId':_0xb4b11[_0xf450('0x52')]},'raw':!![]})[_0xf450('0x26')](function(_0x315751){if(_0x315751&&_0x315751[_0xf450('0x53')]===0x0){return db[_0xf450('0x29')][_0xf450('0x4d')]({'name':_0x3fc1e1[_0xf450('0x2c')],'resourceId':_0x3fc1e1['id'],'type':_0x315751['name'],'sectionId':_0x315751['id']},{})[_0xf450('0x26')](function(){return _0x576123;});}else{return _0x576123;}})[_0xf450('0x47')](function(_0x4c9055){logger[_0xf450('0x2b')](_0xf450('0x54'),_0x4c9055);throw _0x4c9055;});}return _0x576123;})[_0xf450('0x26')](respondWithResult(_0x51a570,0xc9))[_0xf450('0x47')](handleError(_0x51a570,null));};exports['update']=function(_0x2f2281,_0x4fcdba){if(_0x2f2281[_0xf450('0x4e')]['id']){delete _0x2f2281[_0xf450('0x4e')]['id'];}return db[_0xf450('0x43')][_0xf450('0x4c')]({'where':{'id':_0x2f2281['params']['id']}})[_0xf450('0x26')](handleEntityNotFound(_0x4fcdba,null))[_0xf450('0x26')](saveUpdates(_0x2f2281[_0xf450('0x4e')],null))[_0xf450('0x26')](respondWithResult(_0x4fcdba,null))[_0xf450('0x47')](handleError(_0x4fcdba,null));};exports['destroy']=function(_0x423396,_0x393d99){return db[_0xf450('0x43')]['find']({'where':{'id':_0x423396[_0xf450('0x55')]['id']}})['then'](handleEntityNotFound(_0x393d99,null))['then'](removeEntity(_0x393d99,null))[_0xf450('0x47')](handleError(_0x393d99,null));};exports[_0xf450('0x56')]=function(_0x4ec5ec,_0x17ed40,_0x18d9b7){return db['AnalyticExtractedReport'][_0xf450('0x4c')]({'where':{'id':_0x4ec5ec[_0xf450('0x55')]['id']},'attributes':[_0xf450('0x2c'),_0xf450('0x57'),_0xf450('0x58'),_0xf450('0x59')],'raw':!![]})[_0xf450('0x26')](handleEntityNotFound(_0x17ed40,null))[_0xf450('0x26')](function(_0x553ac1){if(_0x553ac1){if(!fs['existsSync'](path[_0xf450('0x5a')](config[_0xf450('0x5b')],'server/files/reports',_0x553ac1['savename']))){throw new db[(_0xf450('0x5c'))][(_0xf450('0x5d'))](_0xf450('0x5e'));}if(_0x4ec5ec[_0xf450('0x35')][_0xf450('0x5f')]){return _0x17ed40['sendStatus'](0xc8);}return _0x17ed40['download'](path[_0xf450('0x5a')](config['root'],_0xf450('0x60'),_0x553ac1[_0xf450('0x58')]),util[_0xf450('0x61')](_0xf450('0x62'),_0x553ac1['basename']||_0x553ac1[_0xf450('0x2c')],_0x553ac1[_0xf450('0x59')][_0xf450('0x63')]()));}})[_0xf450('0x47')](handleError(_0x17ed40,null));};