Built motion from commit (unavailable).|2.5.14
[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 _0x18f6=['path','sox','to-csv','ejs','lodash','squel','jsforce','desk.js','querystring','papaparse','../../components/parsers/qs','../../config/logger','api','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','count','offset','limit','Content-Range','apply','reject','save','update','then','destroy','get','ExtractedReports','UserProfileResource','stack','name','send','map','type','model','keys','filters','intersection','query','attributes','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','VIRTUAL','merge','options','AnalyticExtractedReport','includeAll','rows','catch','show','params','fields','include','find','create','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','user','UserProfileSection','userProfileId','autoAssociation','error','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','body','download','basename','output','existsSync','join','server/files/reports','savename','Sequelize','Report\x20not\x20found\x20or\x20empty','root','format','%s.%s','toLowerCase','html-pdf','eml-format','fast-json-patch','request-promise','moment','mustache'];(function(_0xe571a9,_0x3bb4d2){var _0x24eb18=function(_0xc6306c){while(--_0xc6306c){_0xe571a9['push'](_0xe571a9['shift']());}};_0x24eb18(++_0x3bb4d2);}(_0x18f6,0x16e));var _0x618f=function(_0x93398c,_0xb9e33f){_0x93398c=_0x93398c-0x0;var _0xa694e9=_0x18f6[_0x93398c];return _0xa694e9;};'use strict';var pdf=require(_0x618f('0x0'));var emlformat=require(_0x618f('0x1'));var rimraf=require('rimraf');var zipdir=require('zip-dir');var jsonpatch=require(_0x618f('0x2'));var rp=require(_0x618f('0x3'));var moment=require(_0x618f('0x4'));var BPromise=require('bluebird');var Mustache=require(_0x618f('0x5'));var util=require('util');var path=require(_0x618f('0x6'));var sox=require(_0x618f('0x7'));var csv=require(_0x618f('0x8'));var ejs=require(_0x618f('0x9'));var fs=require('fs');var _=require(_0x618f('0xa'));var squel=require(_0x618f('0xb'));var crypto=require('crypto');var jsforce=require(_0x618f('0xc'));var deskjs=require(_0x618f('0xd'));var toCsv=require(_0x618f('0x8'));var querystring=require(_0x618f('0xe'));var Papa=require(_0x618f('0xf'));var Redis=require('ioredis');var authService=require('../../components/auth/service');var qs=require(_0x618f('0x10'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require('../../config/license/hardware');var logger=require(_0x618f('0x11'))(_0x618f('0x12'));var utils=require('../../config/utils');var config=require(_0x618f('0x13'));var licenseUtil=require(_0x618f('0x14'));var db=require(_0x618f('0x15'))['db'];function respondWithStatusCode(_0x4da324,_0x22f790){_0x22f790=_0x22f790||0xcc;return function(_0x5a5f02){if(_0x5a5f02){return _0x4da324[_0x618f('0x16')](_0x22f790);}return _0x4da324[_0x618f('0x17')](_0x22f790)[_0x618f('0x18')]();};}function respondWithResult(_0x97055e,_0x36ab49){_0x36ab49=_0x36ab49||0xc8;return function(_0x2622ea){if(_0x2622ea){return _0x97055e[_0x618f('0x17')](_0x36ab49)[_0x618f('0x19')](_0x2622ea);}};}function respondWithFilteredResult(_0x73b49,_0x12751c){return function(_0x4e3e8b){if(_0x4e3e8b){var _0x1dc341=_0x4e3e8b[_0x618f('0x1a')],_0x2c11ef=_0x12751c[_0x618f('0x1b')],_0x57d002=_0x12751c[_0x618f('0x1b')]+_0x12751c[_0x618f('0x1c')],_0x6b699c;if(_0x57d002>=_0x1dc341){_0x57d002=_0x1dc341;_0x6b699c=0xc8;}else{_0x6b699c=0xce;}_0x73b49['status'](_0x6b699c);return _0x73b49['set'](_0x618f('0x1d'),_0x2c11ef+'-'+_0x57d002+'/'+_0x1dc341)['json'](_0x4e3e8b);}return null;};}function patchUpdates(_0x4dcc65){return function(_0x2647f2){try{jsonpatch[_0x618f('0x1e')](_0x2647f2,_0x4dcc65,!![]);}catch(_0x469223){return BPromise[_0x618f('0x1f')](_0x469223);}return _0x2647f2[_0x618f('0x20')]();};}function saveUpdates(_0x284747,_0x4c4420){return function(_0x37ed6b){if(_0x37ed6b){return _0x37ed6b[_0x618f('0x21')](_0x284747)[_0x618f('0x22')](function(_0x2cbf72){return _0x2cbf72;});}return null;};}function removeEntity(_0x55877f,_0x12f7f7){return function(_0x2f6958){if(_0x2f6958){return _0x2f6958[_0x618f('0x23')]()[_0x618f('0x22')](function(){var _0x2939ac=_0x2f6958[_0x618f('0x24')]({'plain':!![]});var _0x5674e1=_0x618f('0x25');return db[_0x618f('0x26')][_0x618f('0x23')]({'where':{'type':_0x5674e1,'resourceId':_0x2939ac['id']}})[_0x618f('0x22')](function(){return _0x2f6958;});})[_0x618f('0x22')](function(){_0x55877f[_0x618f('0x17')](0xcc)['end']();});}};}function handleEntityNotFound(_0x1e432f,_0x59187d){return function(_0x239086){if(!_0x239086){_0x1e432f[_0x618f('0x16')](0x194);}return _0x239086;};}function handleError(_0x54494c,_0x413c09){_0x413c09=_0x413c09||0x1f4;return function(_0x1723ad){logger['error'](_0x1723ad[_0x618f('0x27')]);if(_0x1723ad[_0x618f('0x28')]){delete _0x1723ad['name'];}_0x54494c[_0x618f('0x17')](_0x413c09)[_0x618f('0x29')](_0x1723ad);};}exports['index']=function(_0x225acc,_0xaf0429){var _0x507ec6={},_0x562f73={},_0x566c06={'count':0x0,'rows':[]};var _0x181797=_[_0x618f('0x2a')](db['AnalyticExtractedReport']['rawAttributes'],function(_0x4f7a3b){return{'name':_0x4f7a3b['fieldName'],'type':_0x4f7a3b[_0x618f('0x2b')]['key']};});_0x562f73[_0x618f('0x2c')]=_[_0x618f('0x2a')](_0x181797,'name');_0x562f73['query']=_[_0x618f('0x2d')](_0x225acc['query']);_0x562f73[_0x618f('0x2e')]=_[_0x618f('0x2f')](_0x562f73[_0x618f('0x2c')],_0x562f73[_0x618f('0x30')]);_0x507ec6[_0x618f('0x31')]=_[_0x618f('0x2f')](_0x562f73[_0x618f('0x2c')],qs['fields'](_0x225acc[_0x618f('0x30')]['fields']));_0x507ec6[_0x618f('0x31')]=_0x507ec6[_0x618f('0x31')][_0x618f('0x32')]?_0x507ec6['attributes']:_0x562f73['model'];if(!_0x225acc['query'][_0x618f('0x33')](_0x618f('0x34'))){_0x507ec6[_0x618f('0x1c')]=qs[_0x618f('0x1c')](_0x225acc[_0x618f('0x30')][_0x618f('0x1c')]);_0x507ec6[_0x618f('0x1b')]=qs['offset'](_0x225acc['query'][_0x618f('0x1b')]);}_0x507ec6[_0x618f('0x35')]=qs[_0x618f('0x36')](_0x225acc[_0x618f('0x30')][_0x618f('0x36')]);_0x507ec6[_0x618f('0x37')]=qs[_0x618f('0x2e')](_[_0x618f('0x38')](_0x225acc[_0x618f('0x30')],_0x562f73[_0x618f('0x2e')]),_0x181797);if(_0x225acc['query'][_0x618f('0x39')]){_0x507ec6[_0x618f('0x37')]=_['merge'](_0x507ec6['where'],{'$or':_[_0x618f('0x2a')](_0x181797,function(_0x5288e4){if(_0x5288e4[_0x618f('0x2b')]!==_0x618f('0x3a')){var _0x58034d={};_0x58034d[_0x5288e4[_0x618f('0x28')]]={'$like':'%'+_0x225acc[_0x618f('0x30')][_0x618f('0x39')]+'%'};return _0x58034d;}})});}_0x507ec6=_[_0x618f('0x3b')]({},_0x507ec6,_0x225acc[_0x618f('0x3c')]);var _0x3aed95={'where':_0x507ec6['where']};return db[_0x618f('0x3d')][_0x618f('0x1a')](_0x3aed95)[_0x618f('0x22')](function(_0x2606ae){_0x566c06[_0x618f('0x1a')]=_0x2606ae;if(_0x225acc[_0x618f('0x30')][_0x618f('0x3e')]){_0x507ec6['include']=[{'all':!![]}];}return db[_0x618f('0x3d')]['findAll'](_0x507ec6);})[_0x618f('0x22')](function(_0x5ed4a6){_0x566c06[_0x618f('0x3f')]=_0x5ed4a6;return _0x566c06;})[_0x618f('0x22')](respondWithFilteredResult(_0xaf0429,_0x507ec6))[_0x618f('0x40')](handleError(_0xaf0429,null));};exports[_0x618f('0x41')]=function(_0x41d8c5,_0xc8320f){var _0xc91c94={'raw':!![],'where':{'id':_0x41d8c5[_0x618f('0x42')]['id']}},_0x59d325={};_0x59d325[_0x618f('0x2c')]=_[_0x618f('0x2d')](db[_0x618f('0x3d')]['rawAttributes']);_0x59d325[_0x618f('0x30')]=_[_0x618f('0x2d')](_0x41d8c5['query']);_0x59d325[_0x618f('0x2e')]=_[_0x618f('0x2f')](_0x59d325[_0x618f('0x2c')],_0x59d325[_0x618f('0x30')]);_0xc91c94[_0x618f('0x31')]=_['intersection'](_0x59d325[_0x618f('0x2c')],qs[_0x618f('0x43')](_0x41d8c5['query'][_0x618f('0x43')]));_0xc91c94[_0x618f('0x31')]=_0xc91c94['attributes'][_0x618f('0x32')]?_0xc91c94[_0x618f('0x31')]:_0x59d325['model'];if(_0x41d8c5[_0x618f('0x30')][_0x618f('0x3e')]){_0xc91c94[_0x618f('0x44')]=[{'all':!![]}];}_0xc91c94=_[_0x618f('0x3b')]({},_0xc91c94,_0x41d8c5['options']);return db[_0x618f('0x3d')][_0x618f('0x45')](_0xc91c94)[_0x618f('0x22')](handleEntityNotFound(_0xc8320f,null))['then'](respondWithResult(_0xc8320f,null))[_0x618f('0x40')](handleError(_0xc8320f,null));};exports[_0x618f('0x46')]=function(_0x39dc74,_0x20abc3){return db[_0x618f('0x3d')]['create'](_0x39dc74['body'],{})[_0x618f('0x22')](function(_0x546597){var _0x13d39a=_0x39dc74['user'][_0x618f('0x24')]({'plain':!![]});if(!_0x13d39a)throw new Error(_0x618f('0x47'));if(_0x13d39a[_0x618f('0x48')]===_0x618f('0x49')){var _0x1523b8=_0x546597[_0x618f('0x24')]({'plain':!![]});var _0x1663ea=_0x618f('0x25');return db[_0x618f('0x4a')]['find']({'where':{'name':_0x1663ea,'userProfileId':_0x13d39a[_0x618f('0x4b')]},'raw':!![]})[_0x618f('0x22')](function(_0x203c9c){if(_0x203c9c&&_0x203c9c[_0x618f('0x4c')]===0x0){return db['UserProfileResource'][_0x618f('0x46')]({'name':_0x1523b8[_0x618f('0x28')],'resourceId':_0x1523b8['id'],'type':_0x203c9c[_0x618f('0x28')],'sectionId':_0x203c9c['id']},{})[_0x618f('0x22')](function(){return _0x546597;});}else{return _0x546597;}})[_0x618f('0x40')](function(_0x5b4f09){logger[_0x618f('0x4d')](_0x618f('0x4e'),_0x5b4f09);throw _0x5b4f09;});}return _0x546597;})['then'](respondWithResult(_0x20abc3,0xc9))[_0x618f('0x40')](handleError(_0x20abc3,null));};exports[_0x618f('0x21')]=function(_0x5b4d5d,_0x4c817a){if(_0x5b4d5d[_0x618f('0x4f')]['id']){delete _0x5b4d5d[_0x618f('0x4f')]['id'];}return db[_0x618f('0x3d')][_0x618f('0x45')]({'where':{'id':_0x5b4d5d[_0x618f('0x42')]['id']}})[_0x618f('0x22')](handleEntityNotFound(_0x4c817a,null))['then'](saveUpdates(_0x5b4d5d[_0x618f('0x4f')],null))[_0x618f('0x22')](respondWithResult(_0x4c817a,null))[_0x618f('0x40')](handleError(_0x4c817a,null));};exports[_0x618f('0x23')]=function(_0x300add,_0x2b2c71){return db[_0x618f('0x3d')][_0x618f('0x45')]({'where':{'id':_0x300add['params']['id']}})[_0x618f('0x22')](handleEntityNotFound(_0x2b2c71,null))['then'](removeEntity(_0x2b2c71,null))[_0x618f('0x40')](handleError(_0x2b2c71,null));};exports[_0x618f('0x50')]=function(_0x1317ac,_0x41f0cb,_0x59fbfc){return db[_0x618f('0x3d')][_0x618f('0x45')]({'where':{'id':_0x1317ac[_0x618f('0x42')]['id']},'attributes':[_0x618f('0x28'),_0x618f('0x51'),'savename',_0x618f('0x52')],'raw':!![]})[_0x618f('0x22')](handleEntityNotFound(_0x41f0cb,null))[_0x618f('0x22')](function(_0x2ddf21){if(_0x2ddf21){if(!fs[_0x618f('0x53')](path[_0x618f('0x54')](config['root'],_0x618f('0x55'),_0x2ddf21[_0x618f('0x56')]))){throw new db[(_0x618f('0x57'))]['ValidationError'](_0x618f('0x58'));}if(_0x1317ac[_0x618f('0x30')]['exists']){return _0x41f0cb[_0x618f('0x16')](0xc8);}return _0x41f0cb[_0x618f('0x50')](path['join'](config[_0x618f('0x59')],_0x618f('0x55'),_0x2ddf21['savename']),util[_0x618f('0x5a')](_0x618f('0x5b'),_0x2ddf21[_0x618f('0x51')]||_0x2ddf21[_0x618f('0x28')],_0x2ddf21[_0x618f('0x52')][_0x618f('0x5c')]()));}})[_0x618f('0x40')](handleError(_0x41f0cb,null));};