Built motion from commit (unavailable).|2.5.24
[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 _0x77f2=['querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','count','offset','limit','set','save','update','then','get','UserProfileResource','destroy','name','send','index','map','AnalyticExtractedReport','fieldName','type','key','model','query','keys','filters','attributes','intersection','fields','length','nolimit','order','sort','where','pick','filter','merge','VIRTUAL','options','includeAll','include','findAll','catch','show','params','find','create','user','ExtractedReports','UserProfileSection','userProfileId','autoAssociation','error','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','body','output','existsSync','join','root','server/files/reports','savename','Sequelize','ValidationError','Report\x20not\x20found\x20or\x20empty','exists','download','format','%s.%s','basename','toLowerCase','html-pdf','rimraf','fast-json-patch','request-promise','moment','bluebird','mustache','sox','to-csv','ejs','lodash','squel','crypto','jsforce','desk.js'];(function(_0x580576,_0x2f107d){var _0x3f55a0=function(_0x2e180b){while(--_0x2e180b){_0x580576['push'](_0x580576['shift']());}};_0x3f55a0(++_0x2f107d);}(_0x77f2,0x10e));var _0x277f=function(_0x26e424,_0xfcf210){_0x26e424=_0x26e424-0x0;var _0x2c81d6=_0x77f2[_0x26e424];return _0x2c81d6;};'use strict';var pdf=require(_0x277f('0x0'));var emlformat=require('eml-format');var rimraf=require(_0x277f('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0x277f('0x2'));var rp=require(_0x277f('0x3'));var moment=require(_0x277f('0x4'));var BPromise=require(_0x277f('0x5'));var Mustache=require(_0x277f('0x6'));var util=require('util');var path=require('path');var sox=require(_0x277f('0x7'));var csv=require(_0x277f('0x8'));var ejs=require(_0x277f('0x9'));var fs=require('fs');var _=require(_0x277f('0xa'));var squel=require(_0x277f('0xb'));var crypto=require(_0x277f('0xc'));var jsforce=require(_0x277f('0xd'));var deskjs=require(_0x277f('0xe'));var toCsv=require(_0x277f('0x8'));var querystring=require(_0x277f('0xf'));var Papa=require(_0x277f('0x10'));var Redis=require('ioredis');var authService=require(_0x277f('0x11'));var qs=require(_0x277f('0x12'));var as=require(_0x277f('0x13'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x277f('0x14'))(_0x277f('0x15'));var utils=require('../../config/utils');var config=require(_0x277f('0x16'));var licenseUtil=require(_0x277f('0x17'));var db=require(_0x277f('0x18'))['db'];function respondWithStatusCode(_0x12169b,_0x5607cb){_0x5607cb=_0x5607cb||0xcc;return function(_0x26eae9){if(_0x26eae9){return _0x12169b[_0x277f('0x19')](_0x5607cb);}return _0x12169b[_0x277f('0x1a')](_0x5607cb)[_0x277f('0x1b')]();};}function respondWithResult(_0x5e8fd6,_0x19cf0a){_0x19cf0a=_0x19cf0a||0xc8;return function(_0x4ee219){if(_0x4ee219){return _0x5e8fd6[_0x277f('0x1a')](_0x19cf0a)[_0x277f('0x1c')](_0x4ee219);}};}function respondWithFilteredResult(_0x37732f,_0x244973){return function(_0x8920b5){if(_0x8920b5){var _0x5d95a5=_0x8920b5[_0x277f('0x1d')],_0x2db313=_0x244973[_0x277f('0x1e')],_0x1cc261=_0x244973[_0x277f('0x1e')]+_0x244973[_0x277f('0x1f')],_0x4288fc;if(_0x1cc261>=_0x5d95a5){_0x1cc261=_0x5d95a5;_0x4288fc=0xc8;}else{_0x4288fc=0xce;}_0x37732f[_0x277f('0x1a')](_0x4288fc);return _0x37732f[_0x277f('0x20')]('Content-Range',_0x2db313+'-'+_0x1cc261+'/'+_0x5d95a5)[_0x277f('0x1c')](_0x8920b5);}return null;};}function patchUpdates(_0x5579d3){return function(_0x373121){try{jsonpatch['apply'](_0x373121,_0x5579d3,!![]);}catch(_0x24115a){return BPromise['reject'](_0x24115a);}return _0x373121[_0x277f('0x21')]();};}function saveUpdates(_0x1a79da,_0xe9c1fb){return function(_0xc49fc3){if(_0xc49fc3){return _0xc49fc3[_0x277f('0x22')](_0x1a79da)[_0x277f('0x23')](function(_0x33b763){return _0x33b763;});}return null;};}function removeEntity(_0x28a1c1,_0x3e2c28){return function(_0x13e3c7){if(_0x13e3c7){return _0x13e3c7['destroy']()['then'](function(){var _0x2c741c=_0x13e3c7[_0x277f('0x24')]({'plain':!![]});var _0x22ef57='ExtractedReports';return db[_0x277f('0x25')][_0x277f('0x26')]({'where':{'type':_0x22ef57,'resourceId':_0x2c741c['id']}})[_0x277f('0x23')](function(){return _0x13e3c7;});})[_0x277f('0x23')](function(){_0x28a1c1[_0x277f('0x1a')](0xcc)[_0x277f('0x1b')]();});}};}function handleEntityNotFound(_0x176332,_0x34c840){return function(_0x28e720){if(!_0x28e720){_0x176332[_0x277f('0x19')](0x194);}return _0x28e720;};}function handleError(_0x2710e7,_0x5e613a){_0x5e613a=_0x5e613a||0x1f4;return function(_0x33d510){logger['error'](_0x33d510['stack']);if(_0x33d510['name']){delete _0x33d510[_0x277f('0x27')];}_0x2710e7[_0x277f('0x1a')](_0x5e613a)[_0x277f('0x28')](_0x33d510);};}exports[_0x277f('0x29')]=function(_0x2256ae,_0x29fc8c){var _0x358176={},_0x3ac6fc={},_0x4da319={'count':0x0,'rows':[]};var _0x58482d=_[_0x277f('0x2a')](db[_0x277f('0x2b')]['rawAttributes'],function(_0xca55a2){return{'name':_0xca55a2[_0x277f('0x2c')],'type':_0xca55a2[_0x277f('0x2d')][_0x277f('0x2e')]};});_0x3ac6fc[_0x277f('0x2f')]=_[_0x277f('0x2a')](_0x58482d,_0x277f('0x27'));_0x3ac6fc[_0x277f('0x30')]=_[_0x277f('0x31')](_0x2256ae[_0x277f('0x30')]);_0x3ac6fc[_0x277f('0x32')]=_['intersection'](_0x3ac6fc[_0x277f('0x2f')],_0x3ac6fc[_0x277f('0x30')]);_0x358176[_0x277f('0x33')]=_[_0x277f('0x34')](_0x3ac6fc['model'],qs[_0x277f('0x35')](_0x2256ae[_0x277f('0x30')][_0x277f('0x35')]));_0x358176[_0x277f('0x33')]=_0x358176[_0x277f('0x33')][_0x277f('0x36')]?_0x358176[_0x277f('0x33')]:_0x3ac6fc[_0x277f('0x2f')];if(!_0x2256ae[_0x277f('0x30')]['hasOwnProperty'](_0x277f('0x37'))){_0x358176[_0x277f('0x1f')]=qs[_0x277f('0x1f')](_0x2256ae['query'][_0x277f('0x1f')]);_0x358176[_0x277f('0x1e')]=qs['offset'](_0x2256ae['query'][_0x277f('0x1e')]);}_0x358176[_0x277f('0x38')]=qs[_0x277f('0x39')](_0x2256ae[_0x277f('0x30')][_0x277f('0x39')]);_0x358176[_0x277f('0x3a')]=qs[_0x277f('0x32')](_[_0x277f('0x3b')](_0x2256ae['query'],_0x3ac6fc['filters']),_0x58482d);if(_0x2256ae[_0x277f('0x30')][_0x277f('0x3c')]){_0x358176[_0x277f('0x3a')]=_[_0x277f('0x3d')](_0x358176[_0x277f('0x3a')],{'$or':_[_0x277f('0x2a')](_0x58482d,function(_0x2b31b1){if(_0x2b31b1['type']!==_0x277f('0x3e')){var _0x215bdb={};_0x215bdb[_0x2b31b1['name']]={'$like':'%'+_0x2256ae[_0x277f('0x30')][_0x277f('0x3c')]+'%'};return _0x215bdb;}})});}_0x358176=_[_0x277f('0x3d')]({},_0x358176,_0x2256ae[_0x277f('0x3f')]);var _0x5d66b2={'where':_0x358176[_0x277f('0x3a')]};return db[_0x277f('0x2b')][_0x277f('0x1d')](_0x5d66b2)[_0x277f('0x23')](function(_0x27f000){_0x4da319[_0x277f('0x1d')]=_0x27f000;if(_0x2256ae['query'][_0x277f('0x40')]){_0x358176[_0x277f('0x41')]=[{'all':!![]}];}return db['AnalyticExtractedReport'][_0x277f('0x42')](_0x358176);})[_0x277f('0x23')](function(_0x124924){_0x4da319['rows']=_0x124924;return _0x4da319;})[_0x277f('0x23')](respondWithFilteredResult(_0x29fc8c,_0x358176))[_0x277f('0x43')](handleError(_0x29fc8c,null));};exports[_0x277f('0x44')]=function(_0xe60446,_0x356a7a){var _0x1a5c87={'raw':!![],'where':{'id':_0xe60446[_0x277f('0x45')]['id']}},_0x578323={};_0x578323['model']=_['keys'](db['AnalyticExtractedReport']['rawAttributes']);_0x578323[_0x277f('0x30')]=_[_0x277f('0x31')](_0xe60446[_0x277f('0x30')]);_0x578323[_0x277f('0x32')]=_['intersection'](_0x578323[_0x277f('0x2f')],_0x578323['query']);_0x1a5c87['attributes']=_[_0x277f('0x34')](_0x578323[_0x277f('0x2f')],qs[_0x277f('0x35')](_0xe60446[_0x277f('0x30')][_0x277f('0x35')]));_0x1a5c87[_0x277f('0x33')]=_0x1a5c87[_0x277f('0x33')][_0x277f('0x36')]?_0x1a5c87['attributes']:_0x578323[_0x277f('0x2f')];if(_0xe60446['query'][_0x277f('0x40')]){_0x1a5c87['include']=[{'all':!![]}];}_0x1a5c87=_['merge']({},_0x1a5c87,_0xe60446[_0x277f('0x3f')]);return db[_0x277f('0x2b')][_0x277f('0x46')](_0x1a5c87)[_0x277f('0x23')](handleEntityNotFound(_0x356a7a,null))[_0x277f('0x23')](respondWithResult(_0x356a7a,null))['catch'](handleError(_0x356a7a,null));};exports[_0x277f('0x47')]=function(_0x1da2f8,_0x2d805d){return db[_0x277f('0x2b')][_0x277f('0x47')](_0x1da2f8['body'],{})['then'](function(_0x37b1b7){var _0x218fae=_0x1da2f8[_0x277f('0x48')][_0x277f('0x24')]({'plain':!![]});if(!_0x218fae)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x218fae['role']===_0x277f('0x48')){var _0x4c7722=_0x37b1b7[_0x277f('0x24')]({'plain':!![]});var _0x4dffc5=_0x277f('0x49');return db[_0x277f('0x4a')][_0x277f('0x46')]({'where':{'name':_0x4dffc5,'userProfileId':_0x218fae[_0x277f('0x4b')]},'raw':!![]})[_0x277f('0x23')](function(_0x1b79dd){if(_0x1b79dd&&_0x1b79dd[_0x277f('0x4c')]===0x0){return db[_0x277f('0x25')][_0x277f('0x47')]({'name':_0x4c7722[_0x277f('0x27')],'resourceId':_0x4c7722['id'],'type':_0x1b79dd[_0x277f('0x27')],'sectionId':_0x1b79dd['id']},{})[_0x277f('0x23')](function(){return _0x37b1b7;});}else{return _0x37b1b7;}})[_0x277f('0x43')](function(_0xd0d08d){logger[_0x277f('0x4d')](_0x277f('0x4e'),_0xd0d08d);throw _0xd0d08d;});}return _0x37b1b7;})['then'](respondWithResult(_0x2d805d,0xc9))['catch'](handleError(_0x2d805d,null));};exports[_0x277f('0x22')]=function(_0x10cb4a,_0x12aeff){if(_0x10cb4a[_0x277f('0x4f')]['id']){delete _0x10cb4a['body']['id'];}return db['AnalyticExtractedReport']['find']({'where':{'id':_0x10cb4a[_0x277f('0x45')]['id']}})[_0x277f('0x23')](handleEntityNotFound(_0x12aeff,null))[_0x277f('0x23')](saveUpdates(_0x10cb4a['body'],null))[_0x277f('0x23')](respondWithResult(_0x12aeff,null))[_0x277f('0x43')](handleError(_0x12aeff,null));};exports['destroy']=function(_0x29143d,_0x5382e6){return db[_0x277f('0x2b')][_0x277f('0x46')]({'where':{'id':_0x29143d['params']['id']}})[_0x277f('0x23')](handleEntityNotFound(_0x5382e6,null))[_0x277f('0x23')](removeEntity(_0x5382e6,null))[_0x277f('0x43')](handleError(_0x5382e6,null));};exports['download']=function(_0x1b45d9,_0x46abd6,_0x212df6){return db['AnalyticExtractedReport'][_0x277f('0x46')]({'where':{'id':_0x1b45d9[_0x277f('0x45')]['id']},'attributes':[_0x277f('0x27'),'basename','savename',_0x277f('0x50')],'raw':!![]})[_0x277f('0x23')](handleEntityNotFound(_0x46abd6,null))['then'](function(_0x29ed0b){if(_0x29ed0b){if(!fs[_0x277f('0x51')](path[_0x277f('0x52')](config[_0x277f('0x53')],_0x277f('0x54'),_0x29ed0b[_0x277f('0x55')]))){throw new db[(_0x277f('0x56'))][(_0x277f('0x57'))](_0x277f('0x58'));}if(_0x1b45d9[_0x277f('0x30')][_0x277f('0x59')]){return _0x46abd6[_0x277f('0x19')](0xc8);}return _0x46abd6[_0x277f('0x5a')](path[_0x277f('0x52')](config[_0x277f('0x53')],_0x277f('0x54'),_0x29ed0b[_0x277f('0x55')]),util[_0x277f('0x5b')](_0x277f('0x5c'),_0x29ed0b[_0x277f('0x5d')]||_0x29ed0b[_0x277f('0x27')],_0x29ed0b[_0x277f('0x50')][_0x277f('0x5e')]()));}})[_0x277f('0x43')](handleError(_0x46abd6,null));};