Built motion from commit (unavailable).|2.5.9
[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 _0x3afa=['Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','update','basename','savename','output','existsSync','join','root','server/files/reports','Sequelize','ValidationError','download','format','toLowerCase','html-pdf','eml-format','zip-dir','fast-json-patch','bluebird','mustache','util','path','to-csv','ejs','squel','crypto','jsforce','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','../../config/environment','../../config/license/util','sendStatus','status','end','json','count','offset','limit','set','Content-Range','apply','reject','then','destroy','get','UserProfileResource','error','stack','name','index','map','AnalyticExtractedReport','rawAttributes','key','model','query','keys','filters','intersection','attributes','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','type','VIRTUAL','options','includeAll','include','catch','show','params','fields','find','create','body','user','role','ExtractedReports'];(function(_0x250ce7,_0x502ad3){var _0x416428=function(_0x46564d){while(--_0x46564d){_0x250ce7['push'](_0x250ce7['shift']());}};_0x416428(++_0x502ad3);}(_0x3afa,0x69));var _0xa3af=function(_0x1ac6ec,_0x1f81fc){_0x1ac6ec=_0x1ac6ec-0x0;var _0x48a489=_0x3afa[_0x1ac6ec];return _0x48a489;};'use strict';var pdf=require(_0xa3af('0x0'));var emlformat=require(_0xa3af('0x1'));var rimraf=require('rimraf');var zipdir=require(_0xa3af('0x2'));var jsonpatch=require(_0xa3af('0x3'));var rp=require('request-promise');var moment=require('moment');var BPromise=require(_0xa3af('0x4'));var Mustache=require(_0xa3af('0x5'));var util=require(_0xa3af('0x6'));var path=require(_0xa3af('0x7'));var sox=require('sox');var csv=require(_0xa3af('0x8'));var ejs=require(_0xa3af('0x9'));var fs=require('fs');var _=require('lodash');var squel=require(_0xa3af('0xa'));var crypto=require(_0xa3af('0xb'));var jsforce=require(_0xa3af('0xc'));var deskjs=require('desk.js');var toCsv=require(_0xa3af('0x8'));var querystring=require(_0xa3af('0xd'));var Papa=require(_0xa3af('0xe'));var Redis=require(_0xa3af('0xf'));var authService=require(_0xa3af('0x10'));var qs=require(_0xa3af('0x11'));var as=require(_0xa3af('0x12'));var hardwareService=require(_0xa3af('0x13'));var logger=require('../../config/logger')(_0xa3af('0x14'));var utils=require(_0xa3af('0x15'));var config=require(_0xa3af('0x16'));var licenseUtil=require(_0xa3af('0x17'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x32be19,_0x146568){_0x146568=_0x146568||0xcc;return function(_0x7bf4ea){if(_0x7bf4ea){return _0x32be19[_0xa3af('0x18')](_0x146568);}return _0x32be19[_0xa3af('0x19')](_0x146568)[_0xa3af('0x1a')]();};}function respondWithResult(_0x2c3939,_0x4ac046){_0x4ac046=_0x4ac046||0xc8;return function(_0x465e70){if(_0x465e70){return _0x2c3939['status'](_0x4ac046)[_0xa3af('0x1b')](_0x465e70);}};}function respondWithFilteredResult(_0x7444c9,_0x408e6d){return function(_0x5d18c4){if(_0x5d18c4){var _0x3d7768=_0x5d18c4[_0xa3af('0x1c')],_0x8eb1b6=_0x408e6d[_0xa3af('0x1d')],_0x4046cc=_0x408e6d[_0xa3af('0x1d')]+_0x408e6d[_0xa3af('0x1e')],_0x888e62;if(_0x4046cc>=_0x3d7768){_0x4046cc=_0x3d7768;_0x888e62=0xc8;}else{_0x888e62=0xce;}_0x7444c9['status'](_0x888e62);return _0x7444c9[_0xa3af('0x1f')](_0xa3af('0x20'),_0x8eb1b6+'-'+_0x4046cc+'/'+_0x3d7768)[_0xa3af('0x1b')](_0x5d18c4);}return null;};}function patchUpdates(_0x17abf9){return function(_0x2fa089){try{jsonpatch[_0xa3af('0x21')](_0x2fa089,_0x17abf9,!![]);}catch(_0x7d7115){return BPromise[_0xa3af('0x22')](_0x7d7115);}return _0x2fa089['save']();};}function saveUpdates(_0x2fca66,_0x39399e){return function(_0x35bd87){if(_0x35bd87){return _0x35bd87['update'](_0x2fca66)[_0xa3af('0x23')](function(_0x4ae494){return _0x4ae494;});}return null;};}function removeEntity(_0x542894,_0x3a8e7e){return function(_0x5d1e92){if(_0x5d1e92){return _0x5d1e92[_0xa3af('0x24')]()[_0xa3af('0x23')](function(){var _0x35e53b=_0x5d1e92[_0xa3af('0x25')]({'plain':!![]});var _0x227714='ExtractedReports';return db[_0xa3af('0x26')][_0xa3af('0x24')]({'where':{'type':_0x227714,'resourceId':_0x35e53b['id']}})['then'](function(){return _0x5d1e92;});})[_0xa3af('0x23')](function(){_0x542894[_0xa3af('0x19')](0xcc)[_0xa3af('0x1a')]();});}};}function handleEntityNotFound(_0x3887e3,_0x20abf7){return function(_0x207024){if(!_0x207024){_0x3887e3[_0xa3af('0x18')](0x194);}return _0x207024;};}function handleError(_0xb569ae,_0x95f157){_0x95f157=_0x95f157||0x1f4;return function(_0x387673){logger[_0xa3af('0x27')](_0x387673[_0xa3af('0x28')]);if(_0x387673[_0xa3af('0x29')]){delete _0x387673[_0xa3af('0x29')];}_0xb569ae[_0xa3af('0x19')](_0x95f157)['send'](_0x387673);};}exports[_0xa3af('0x2a')]=function(_0x3bf9bd,_0x448b58){var _0x491771={},_0x4c15eb={},_0x44828b={'count':0x0,'rows':[]};var _0x1f3406=_[_0xa3af('0x2b')](db[_0xa3af('0x2c')][_0xa3af('0x2d')],function(_0x35cd2a){return{'name':_0x35cd2a['fieldName'],'type':_0x35cd2a['type'][_0xa3af('0x2e')]};});_0x4c15eb[_0xa3af('0x2f')]=_[_0xa3af('0x2b')](_0x1f3406,_0xa3af('0x29'));_0x4c15eb[_0xa3af('0x30')]=_[_0xa3af('0x31')](_0x3bf9bd[_0xa3af('0x30')]);_0x4c15eb[_0xa3af('0x32')]=_[_0xa3af('0x33')](_0x4c15eb[_0xa3af('0x2f')],_0x4c15eb[_0xa3af('0x30')]);_0x491771[_0xa3af('0x34')]=_[_0xa3af('0x33')](_0x4c15eb[_0xa3af('0x2f')],qs['fields'](_0x3bf9bd['query']['fields']));_0x491771['attributes']=_0x491771['attributes'][_0xa3af('0x35')]?_0x491771[_0xa3af('0x34')]:_0x4c15eb[_0xa3af('0x2f')];if(!_0x3bf9bd[_0xa3af('0x30')][_0xa3af('0x36')](_0xa3af('0x37'))){_0x491771[_0xa3af('0x1e')]=qs[_0xa3af('0x1e')](_0x3bf9bd[_0xa3af('0x30')]['limit']);_0x491771[_0xa3af('0x1d')]=qs[_0xa3af('0x1d')](_0x3bf9bd[_0xa3af('0x30')]['offset']);}_0x491771[_0xa3af('0x38')]=qs[_0xa3af('0x39')](_0x3bf9bd[_0xa3af('0x30')][_0xa3af('0x39')]);_0x491771[_0xa3af('0x3a')]=qs[_0xa3af('0x32')](_[_0xa3af('0x3b')](_0x3bf9bd[_0xa3af('0x30')],_0x4c15eb['filters']),_0x1f3406);if(_0x3bf9bd['query'][_0xa3af('0x3c')]){_0x491771['where']=_[_0xa3af('0x3d')](_0x491771['where'],{'$or':_[_0xa3af('0x2b')](_0x1f3406,function(_0x75d436){if(_0x75d436[_0xa3af('0x3e')]!==_0xa3af('0x3f')){var _0xe5c2a6={};_0xe5c2a6[_0x75d436['name']]={'$like':'%'+_0x3bf9bd[_0xa3af('0x30')]['filter']+'%'};return _0xe5c2a6;}})});}_0x491771=_[_0xa3af('0x3d')]({},_0x491771,_0x3bf9bd[_0xa3af('0x40')]);var _0x523308={'where':_0x491771['where']};return db[_0xa3af('0x2c')]['count'](_0x523308)[_0xa3af('0x23')](function(_0x2e34e2){_0x44828b[_0xa3af('0x1c')]=_0x2e34e2;if(_0x3bf9bd[_0xa3af('0x30')][_0xa3af('0x41')]){_0x491771[_0xa3af('0x42')]=[{'all':!![]}];}return db['AnalyticExtractedReport']['findAll'](_0x491771);})[_0xa3af('0x23')](function(_0x4dbc57){_0x44828b['rows']=_0x4dbc57;return _0x44828b;})[_0xa3af('0x23')](respondWithFilteredResult(_0x448b58,_0x491771))[_0xa3af('0x43')](handleError(_0x448b58,null));};exports[_0xa3af('0x44')]=function(_0x1bf2ae,_0x585062){var _0x2bd16e={'raw':!![],'where':{'id':_0x1bf2ae[_0xa3af('0x45')]['id']}},_0x1e5c10={};_0x1e5c10[_0xa3af('0x2f')]=_[_0xa3af('0x31')](db[_0xa3af('0x2c')][_0xa3af('0x2d')]);_0x1e5c10[_0xa3af('0x30')]=_[_0xa3af('0x31')](_0x1bf2ae['query']);_0x1e5c10[_0xa3af('0x32')]=_[_0xa3af('0x33')](_0x1e5c10[_0xa3af('0x2f')],_0x1e5c10[_0xa3af('0x30')]);_0x2bd16e[_0xa3af('0x34')]=_[_0xa3af('0x33')](_0x1e5c10[_0xa3af('0x2f')],qs[_0xa3af('0x46')](_0x1bf2ae[_0xa3af('0x30')]['fields']));_0x2bd16e['attributes']=_0x2bd16e[_0xa3af('0x34')][_0xa3af('0x35')]?_0x2bd16e[_0xa3af('0x34')]:_0x1e5c10[_0xa3af('0x2f')];if(_0x1bf2ae['query'][_0xa3af('0x41')]){_0x2bd16e['include']=[{'all':!![]}];}_0x2bd16e=_[_0xa3af('0x3d')]({},_0x2bd16e,_0x1bf2ae[_0xa3af('0x40')]);return db[_0xa3af('0x2c')][_0xa3af('0x47')](_0x2bd16e)['then'](handleEntityNotFound(_0x585062,null))[_0xa3af('0x23')](respondWithResult(_0x585062,null))[_0xa3af('0x43')](handleError(_0x585062,null));};exports['create']=function(_0x5595c6,_0x5f455a){return db[_0xa3af('0x2c')][_0xa3af('0x48')](_0x5595c6[_0xa3af('0x49')],{})['then'](function(_0x4bd866){var _0x5c2e2c=_0x5595c6[_0xa3af('0x4a')][_0xa3af('0x25')]({'plain':!![]});if(!_0x5c2e2c)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x5c2e2c[_0xa3af('0x4b')]==='user'){var _0x27546f=_0x4bd866['get']({'plain':!![]});var _0xa9d53f=_0xa3af('0x4c');return db['UserProfileSection'][_0xa3af('0x47')]({'where':{'name':_0xa9d53f,'userProfileId':_0x5c2e2c['userProfileId']},'raw':!![]})[_0xa3af('0x23')](function(_0x371beb){if(_0x371beb&&_0x371beb['autoAssociation']===0x0){return db[_0xa3af('0x26')]['create']({'name':_0x27546f['name'],'resourceId':_0x27546f['id'],'type':_0x371beb[_0xa3af('0x29')],'sectionId':_0x371beb['id']},{})[_0xa3af('0x23')](function(){return _0x4bd866;});}else{return _0x4bd866;}})[_0xa3af('0x43')](function(_0x2d33fe){logger[_0xa3af('0x27')](_0xa3af('0x4d'),_0x2d33fe);throw _0x2d33fe;});}return _0x4bd866;})['then'](respondWithResult(_0x5f455a,0xc9))[_0xa3af('0x43')](handleError(_0x5f455a,null));};exports[_0xa3af('0x4e')]=function(_0x10efdf,_0x2edddf){if(_0x10efdf['body']['id']){delete _0x10efdf[_0xa3af('0x49')]['id'];}return db[_0xa3af('0x2c')][_0xa3af('0x47')]({'where':{'id':_0x10efdf[_0xa3af('0x45')]['id']}})[_0xa3af('0x23')](handleEntityNotFound(_0x2edddf,null))[_0xa3af('0x23')](saveUpdates(_0x10efdf['body'],null))[_0xa3af('0x23')](respondWithResult(_0x2edddf,null))[_0xa3af('0x43')](handleError(_0x2edddf,null));};exports['destroy']=function(_0x5dade3,_0x30f87b){return db['AnalyticExtractedReport'][_0xa3af('0x47')]({'where':{'id':_0x5dade3[_0xa3af('0x45')]['id']}})['then'](handleEntityNotFound(_0x30f87b,null))[_0xa3af('0x23')](removeEntity(_0x30f87b,null))[_0xa3af('0x43')](handleError(_0x30f87b,null));};exports['download']=function(_0x16c18a,_0x1e1c78,_0x4ec792){return db[_0xa3af('0x2c')]['find']({'where':{'id':_0x16c18a['params']['id']},'attributes':[_0xa3af('0x29'),_0xa3af('0x4f'),_0xa3af('0x50'),_0xa3af('0x51')],'raw':!![]})[_0xa3af('0x23')](handleEntityNotFound(_0x1e1c78,null))['then'](function(_0x5dec04){if(_0x5dec04){if(!fs[_0xa3af('0x52')](path[_0xa3af('0x53')](config[_0xa3af('0x54')],_0xa3af('0x55'),_0x5dec04[_0xa3af('0x50')]))){throw new db[(_0xa3af('0x56'))][(_0xa3af('0x57'))]('Report\x20not\x20found\x20or\x20empty');}if(_0x16c18a['query']['exists']){return _0x1e1c78[_0xa3af('0x18')](0xc8);}return _0x1e1c78[_0xa3af('0x58')](path['join'](config[_0xa3af('0x54')],'server/files/reports',_0x5dec04[_0xa3af('0x50')]),util[_0xa3af('0x59')]('%s.%s',_0x5dec04[_0xa3af('0x4f')]||_0x5dec04['name'],_0x5dec04[_0xa3af('0x51')][_0xa3af('0x5a')]()));}})['catch'](handleError(_0x1e1c78,null));};