6d11d3dab95df2d1987ae158a854aced5d284dd6
[motion2.git] / server / api / analyticFieldReport / analyticFieldReport.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 _0xfc99=['lodash','squel','crypto','jsforce','desk.js','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','undefined','limit','count','offset','Content-Range','save','update','then','destroy','name','send','map','AnalyticFieldReport','rawAttributes','fieldName','key','model','query','filters','intersection','fields','attributes','length','hasOwnProperty','nolimit','sort','pick','filter','where','merge','type','VIRTUAL','options','includeAll','include','rows','catch','show','keys','find','create','bulkCreate','body','params','ids','addFields','findOne','sequelize','transaction','CustomReportId','findAll','rimraf','zip-dir','fast-json-patch','moment','bluebird','mustache','util','path','sox','ejs','fs-extra'];(function(_0x11da29,_0x5402c1){var _0x434192=function(_0x4c2665){while(--_0x4c2665){_0x11da29['push'](_0x11da29['shift']());}};_0x434192(++_0x5402c1);}(_0xfc99,0x139));var _0x9fc9=function(_0x30d6a5,_0x546523){_0x30d6a5=_0x30d6a5-0x0;var _0x3cd234=_0xfc99[_0x30d6a5];return _0x3cd234;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x9fc9('0x0'));var zipdir=require(_0x9fc9('0x1'));var jsonpatch=require(_0x9fc9('0x2'));var rp=require('request-promise');var moment=require(_0x9fc9('0x3'));var BPromise=require(_0x9fc9('0x4'));var Mustache=require(_0x9fc9('0x5'));var util=require(_0x9fc9('0x6'));var path=require(_0x9fc9('0x7'));var sox=require(_0x9fc9('0x8'));var csv=require('to-csv');var ejs=require(_0x9fc9('0x9'));var fs=require('fs');var fs_extra=require(_0x9fc9('0xa'));var _=require(_0x9fc9('0xb'));var squel=require(_0x9fc9('0xc'));var crypto=require(_0x9fc9('0xd'));var jsforce=require(_0x9fc9('0xe'));var deskjs=require(_0x9fc9('0xf'));var toCsv=require('to-csv');var querystring=require(_0x9fc9('0x10'));var Papa=require('papaparse');var Redis=require(_0x9fc9('0x11'));var authService=require(_0x9fc9('0x12'));var qs=require(_0x9fc9('0x13'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require('../../config/license/hardware');var logger=require(_0x9fc9('0x14'))(_0x9fc9('0x15'));var utils=require(_0x9fc9('0x16'));var config=require(_0x9fc9('0x17'));var licenseUtil=require(_0x9fc9('0x18'));var db=require(_0x9fc9('0x19'))['db'];function respondWithStatusCode(_0x5d0c2d,_0x17438f){_0x17438f=_0x17438f||0xcc;return function(_0x31bd6d){if(_0x31bd6d){return _0x5d0c2d[_0x9fc9('0x1a')](_0x17438f);}return _0x5d0c2d[_0x9fc9('0x1b')](_0x17438f)[_0x9fc9('0x1c')]();};}function respondWithResult(_0x17b4ef,_0x31cf8e){_0x31cf8e=_0x31cf8e||0xc8;return function(_0x12693e){if(_0x12693e){return _0x17b4ef[_0x9fc9('0x1b')](_0x31cf8e)[_0x9fc9('0x1d')](_0x12693e);}};}function respondWithFilteredResult(_0x46255e,_0x3e4ad9){return function(_0xd245af){if(_0xd245af){var _0x3bac71=typeof _0x3e4ad9['offset']===_0x9fc9('0x1e')&&typeof _0x3e4ad9[_0x9fc9('0x1f')]==='undefined';var _0x405378=_0xd245af[_0x9fc9('0x20')];var _0x4e64b0=_0x3bac71?0x0:_0x3e4ad9['offset'];var _0x24f6ef=_0x3bac71?_0xd245af[_0x9fc9('0x20')]:_0x3e4ad9[_0x9fc9('0x21')]+_0x3e4ad9[_0x9fc9('0x1f')];var _0x57d610;if(_0x24f6ef>=_0x405378){_0x24f6ef=_0x405378;_0x57d610=0xc8;}else{_0x57d610=0xce;}_0x46255e[_0x9fc9('0x1b')](_0x57d610);return _0x46255e['set'](_0x9fc9('0x22'),_0x4e64b0+'-'+_0x24f6ef+'/'+_0x405378)[_0x9fc9('0x1d')](_0xd245af);}return null;};}function patchUpdates(_0xee665c){return function(_0x4a4b67){try{jsonpatch['apply'](_0x4a4b67,_0xee665c,!![]);}catch(_0x3dca58){return BPromise['reject'](_0x3dca58);}return _0x4a4b67[_0x9fc9('0x23')]();};}function saveUpdates(_0x1768dc,_0x927799){return function(_0x193061){if(_0x193061){return _0x193061[_0x9fc9('0x24')](_0x1768dc)[_0x9fc9('0x25')](function(_0x33e529){return _0x33e529;});}return null;};}function removeEntity(_0x15c9a6,_0x459e0c){return function(_0x5386d8){if(_0x5386d8){return _0x5386d8[_0x9fc9('0x26')]()['then'](function(){_0x15c9a6['status'](0xcc)[_0x9fc9('0x1c')]();});}};}function handleEntityNotFound(_0xa2de9,_0x1b0e2b){return function(_0x17f015){if(!_0x17f015){_0xa2de9[_0x9fc9('0x1a')](0x194);}return _0x17f015;};}function handleError(_0x204317,_0x254165){_0x254165=_0x254165||0x1f4;return function(_0xd432a6){logger['error'](_0xd432a6['stack']);if(_0xd432a6[_0x9fc9('0x27')]){delete _0xd432a6[_0x9fc9('0x27')];}_0x204317['status'](_0x254165)[_0x9fc9('0x28')](_0xd432a6);};}exports['index']=function(_0xeca997,_0x1fb709){var _0x145773={},_0x5c9567={},_0x5e5083={'count':0x0,'rows':[]};var _0x60dc6=_[_0x9fc9('0x29')](db[_0x9fc9('0x2a')][_0x9fc9('0x2b')],function(_0xcbc709){return{'name':_0xcbc709[_0x9fc9('0x2c')],'type':_0xcbc709['type'][_0x9fc9('0x2d')]};});_0x5c9567[_0x9fc9('0x2e')]=_[_0x9fc9('0x29')](_0x60dc6,_0x9fc9('0x27'));_0x5c9567[_0x9fc9('0x2f')]=_['keys'](_0xeca997[_0x9fc9('0x2f')]);_0x5c9567[_0x9fc9('0x30')]=_[_0x9fc9('0x31')](_0x5c9567[_0x9fc9('0x2e')],_0x5c9567['query']);_0x145773['attributes']=_['intersection'](_0x5c9567[_0x9fc9('0x2e')],qs[_0x9fc9('0x32')](_0xeca997[_0x9fc9('0x2f')][_0x9fc9('0x32')]));_0x145773[_0x9fc9('0x33')]=_0x145773[_0x9fc9('0x33')][_0x9fc9('0x34')]?_0x145773[_0x9fc9('0x33')]:_0x5c9567[_0x9fc9('0x2e')];if(!_0xeca997[_0x9fc9('0x2f')][_0x9fc9('0x35')](_0x9fc9('0x36'))){_0x145773[_0x9fc9('0x1f')]=qs[_0x9fc9('0x1f')](_0xeca997[_0x9fc9('0x2f')][_0x9fc9('0x1f')]);_0x145773[_0x9fc9('0x21')]=qs[_0x9fc9('0x21')](_0xeca997[_0x9fc9('0x2f')][_0x9fc9('0x21')]);}_0x145773['order']=qs['sort'](_0xeca997['query'][_0x9fc9('0x37')]);_0x145773['where']=qs['filters'](_[_0x9fc9('0x38')](_0xeca997[_0x9fc9('0x2f')],_0x5c9567[_0x9fc9('0x30')]),_0x60dc6);if(_0xeca997[_0x9fc9('0x2f')][_0x9fc9('0x39')]){_0x145773[_0x9fc9('0x3a')]=_[_0x9fc9('0x3b')](_0x145773['where'],{'$or':_[_0x9fc9('0x29')](_0x60dc6,function(_0x3ac275){if(_0x3ac275[_0x9fc9('0x3c')]!==_0x9fc9('0x3d')){var _0x14f8a5={};_0x14f8a5[_0x3ac275[_0x9fc9('0x27')]]={'$like':'%'+_0xeca997[_0x9fc9('0x2f')]['filter']+'%'};return _0x14f8a5;}})});}_0x145773=_[_0x9fc9('0x3b')]({},_0x145773,_0xeca997[_0x9fc9('0x3e')]);var _0x2e6dce={'where':_0x145773[_0x9fc9('0x3a')]};return db[_0x9fc9('0x2a')][_0x9fc9('0x20')](_0x2e6dce)[_0x9fc9('0x25')](function(_0x1171b2){_0x5e5083[_0x9fc9('0x20')]=_0x1171b2;if(_0xeca997[_0x9fc9('0x2f')][_0x9fc9('0x3f')]){_0x145773[_0x9fc9('0x40')]=[{'all':!![]}];}return db['AnalyticFieldReport']['findAll'](_0x145773);})['then'](function(_0x4294d9){_0x5e5083[_0x9fc9('0x41')]=_0x4294d9;return _0x5e5083;})['then'](respondWithFilteredResult(_0x1fb709,_0x145773))[_0x9fc9('0x42')](handleError(_0x1fb709,null));};exports[_0x9fc9('0x43')]=function(_0x51720f,_0x22b242){var _0x4404bb={'raw':![],'where':{'id':_0x51720f['params']['id']}},_0xa75615={};_0xa75615['model']=_['keys'](db[_0x9fc9('0x2a')][_0x9fc9('0x2b')]);_0xa75615['query']=_[_0x9fc9('0x44')](_0x51720f[_0x9fc9('0x2f')]);_0xa75615[_0x9fc9('0x30')]=_['intersection'](_0xa75615[_0x9fc9('0x2e')],_0xa75615[_0x9fc9('0x2f')]);_0x4404bb['attributes']=_['intersection'](_0xa75615[_0x9fc9('0x2e')],qs['fields'](_0x51720f[_0x9fc9('0x2f')]['fields']));_0x4404bb[_0x9fc9('0x33')]=_0x4404bb[_0x9fc9('0x33')]['length']?_0x4404bb['attributes']:_0xa75615[_0x9fc9('0x2e')];if(_0x51720f['query']['includeAll']){_0x4404bb[_0x9fc9('0x40')]=[{'all':!![]}];}_0x4404bb=_[_0x9fc9('0x3b')]({},_0x4404bb,_0x51720f[_0x9fc9('0x3e')]);return db[_0x9fc9('0x2a')][_0x9fc9('0x45')](_0x4404bb)[_0x9fc9('0x25')](handleEntityNotFound(_0x22b242,null))[_0x9fc9('0x25')](respondWithResult(_0x22b242,null))[_0x9fc9('0x42')](handleError(_0x22b242,null));};exports[_0x9fc9('0x46')]=function(_0x4a5f29,_0x2b9c84){return db[_0x9fc9('0x2a')][_0x9fc9('0x46')](_0x4a5f29['body'],{})[_0x9fc9('0x25')](respondWithResult(_0x2b9c84,0xc9))[_0x9fc9('0x42')](handleError(_0x2b9c84,null));};exports[_0x9fc9('0x47')]=function(_0xc4256c,_0x4365a2){return db[_0x9fc9('0x2a')]['bulkCreate'](_0xc4256c[_0x9fc9('0x48')],{'raw':![],'individualHooks':!![]})[_0x9fc9('0x25')](respondWithResult(_0x4365a2,0xc9))[_0x9fc9('0x42')](handleError(_0x4365a2,null));};exports['update']=function(_0x5bb800,_0x298347){if(_0x5bb800[_0x9fc9('0x48')]['id']){delete _0x5bb800[_0x9fc9('0x48')]['id'];}return db[_0x9fc9('0x2a')][_0x9fc9('0x45')]({'where':{'id':_0x5bb800[_0x9fc9('0x49')]['id']}})[_0x9fc9('0x25')](handleEntityNotFound(_0x298347,null))[_0x9fc9('0x25')](saveUpdates(_0x5bb800[_0x9fc9('0x48')],null))[_0x9fc9('0x25')](respondWithResult(_0x298347,null))[_0x9fc9('0x42')](handleError(_0x298347,null));};exports['destroy']=function(_0x23b400,_0x3be468){return db['AnalyticFieldReport'][_0x9fc9('0x45')]({'where':{'id':_0x23b400[_0x9fc9('0x49')]['id']}})[_0x9fc9('0x25')](handleEntityNotFound(_0x3be468,null))[_0x9fc9('0x25')](removeEntity(_0x3be468,null))['catch'](handleError(_0x3be468,null));};exports['bulkDestroy']=function(_0xafb44c,_0x255dac){return db[_0x9fc9('0x2a')][_0x9fc9('0x26')]({'where':{'id':_0xafb44c[_0x9fc9('0x2f')][_0x9fc9('0x4a')]||[]},'raw':![],'individualHooks':!![]})[_0x9fc9('0x25')](respondWithResult(_0x255dac,0xcc))[_0x9fc9('0x42')](handleError(_0x255dac,null));};exports[_0x9fc9('0x4b')]=function(_0x2d91b8,_0x2be401,_0xb1c2d9){return db['AnalyticCustomReport'][_0x9fc9('0x4c')]({'where':{'id':_0x2d91b8['params']['id']}})[_0x9fc9('0x25')](handleEntityNotFound(_0x2be401,null))['then'](function(_0x371168){if(_0x371168){return db[_0x9fc9('0x4d')][_0x9fc9('0x4e')](function(_0x506b83){return db[_0x9fc9('0x2a')][_0x9fc9('0x26')]({'where':{'CustomReportId':_0x2d91b8['params']['id']},'transaction':_0x506b83})['then'](function(_0x3846c1){var _0x319378=_[_0x9fc9('0x29')](_0x2d91b8['body'],function(_0x28df42){delete _0x28df42['id'];_0x28df42[_0x9fc9('0x4f')]=_0x2d91b8[_0x9fc9('0x49')]['id'];return _0x28df42;});return db[_0x9fc9('0x2a')][_0x9fc9('0x47')](_0x319378,{'transaction':_0x506b83});});})[_0x9fc9('0x25')](function(){return db[_0x9fc9('0x2a')][_0x9fc9('0x50')]({'where':{'CustomReportId':_0x2d91b8['params']['id']}});});}})[_0x9fc9('0x25')](respondWithResult(_0x2be401,null))[_0x9fc9('0x42')](handleError(_0x2be401,null));};