ae3a545c2a41a087a73c922e9664c2c51673ca7b
[motion2.git] / server / api / analyticTreeReport / analyticTreeReport.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 _0xb1b4=['jsforce','desk.js','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','status','json','offset','limit','set','Content-Range','apply','reject','update','then','destroy','end','sendStatus','error','stack','name','send','index','map','AnalyticTreeReport','rawAttributes','fieldName','key','model','keys','filters','query','attributes','intersection','fields','length','hasOwnProperty','nolimit','order','pick','filter','where','type','VIRTUAL','merge','options','count','includeAll','include','rows','show','params','find','catch','create','body','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','ejs','lodash','crypto'];(function(_0x5ddb1c,_0x5ea4df){var _0x354adc=function(_0x2dfb1f){while(--_0x2dfb1f){_0x5ddb1c['push'](_0x5ddb1c['shift']());}};_0x354adc(++_0x5ea4df);}(_0xb1b4,0xde));var _0x4b1b=function(_0x49d19d,_0x245cf5){_0x49d19d=_0x49d19d-0x0;var _0x4ebef1=_0xb1b4[_0x49d19d];return _0x4ebef1;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0x4b1b('0x0'));var rimraf=require(_0x4b1b('0x1'));var zipdir=require(_0x4b1b('0x2'));var jsonpatch=require(_0x4b1b('0x3'));var rp=require(_0x4b1b('0x4'));var moment=require(_0x4b1b('0x5'));var BPromise=require(_0x4b1b('0x6'));var Mustache=require(_0x4b1b('0x7'));var util=require(_0x4b1b('0x8'));var path=require(_0x4b1b('0x9'));var sox=require(_0x4b1b('0xa'));var csv=require(_0x4b1b('0xb'));var ejs=require(_0x4b1b('0xc'));var fs=require('fs');var _=require(_0x4b1b('0xd'));var squel=require('squel');var crypto=require(_0x4b1b('0xe'));var jsforce=require(_0x4b1b('0xf'));var deskjs=require(_0x4b1b('0x10'));var toCsv=require('to-csv');var querystring=require('querystring');var Papa=require(_0x4b1b('0x11'));var Redis=require(_0x4b1b('0x12'));var authService=require(_0x4b1b('0x13'));var qs=require(_0x4b1b('0x14'));var as=require(_0x4b1b('0x15'));var hardwareService=require(_0x4b1b('0x16'));var logger=require(_0x4b1b('0x17'))(_0x4b1b('0x18'));var utils=require(_0x4b1b('0x19'));var config=require(_0x4b1b('0x1a'));var licenseUtil=require('../../config/license/util');var db=require(_0x4b1b('0x1b'))['db'];function respondWithStatusCode(_0x24b85e,_0x271719){_0x271719=_0x271719||0xcc;return function(_0x13930f){if(_0x13930f){return _0x24b85e['sendStatus'](_0x271719);}return _0x24b85e['status'](_0x271719)['end']();};}function respondWithResult(_0x24cf4a,_0x345935){_0x345935=_0x345935||0xc8;return function(_0x24acb6){if(_0x24acb6){return _0x24cf4a[_0x4b1b('0x1c')](_0x345935)[_0x4b1b('0x1d')](_0x24acb6);}};}function respondWithFilteredResult(_0xa1db4f,_0x13b359){return function(_0x3ae2c8){if(_0x3ae2c8){var _0x4e90bd=_0x3ae2c8['count'],_0x21f7d0=_0x13b359[_0x4b1b('0x1e')],_0x20648d=_0x13b359[_0x4b1b('0x1e')]+_0x13b359[_0x4b1b('0x1f')],_0x1e5bd4;if(_0x20648d>=_0x4e90bd){_0x20648d=_0x4e90bd;_0x1e5bd4=0xc8;}else{_0x1e5bd4=0xce;}_0xa1db4f[_0x4b1b('0x1c')](_0x1e5bd4);return _0xa1db4f[_0x4b1b('0x20')](_0x4b1b('0x21'),_0x21f7d0+'-'+_0x20648d+'/'+_0x4e90bd)[_0x4b1b('0x1d')](_0x3ae2c8);}return null;};}function patchUpdates(_0x5ee2b7){return function(_0x40d650){try{jsonpatch[_0x4b1b('0x22')](_0x40d650,_0x5ee2b7,!![]);}catch(_0x5923cf){return BPromise[_0x4b1b('0x23')](_0x5923cf);}return _0x40d650['save']();};}function saveUpdates(_0x2d91c5,_0x341b33){return function(_0x3d9fca){if(_0x3d9fca){return _0x3d9fca[_0x4b1b('0x24')](_0x2d91c5)[_0x4b1b('0x25')](function(_0x7d3d96){return _0x7d3d96;});}return null;};}function removeEntity(_0x4e43ba,_0x4e7f77){return function(_0x30c0df){if(_0x30c0df){return _0x30c0df[_0x4b1b('0x26')]()[_0x4b1b('0x25')](function(){_0x4e43ba['status'](0xcc)[_0x4b1b('0x27')]();});}};}function handleEntityNotFound(_0x2b18af,_0x23c538){return function(_0x3548ef){if(!_0x3548ef){_0x2b18af[_0x4b1b('0x28')](0x194);}return _0x3548ef;};}function handleError(_0xa4679d,_0x154300){_0x154300=_0x154300||0x1f4;return function(_0x981047){logger[_0x4b1b('0x29')](_0x981047[_0x4b1b('0x2a')]);if(_0x981047['name']){delete _0x981047[_0x4b1b('0x2b')];}_0xa4679d[_0x4b1b('0x1c')](_0x154300)[_0x4b1b('0x2c')](_0x981047);};}exports[_0x4b1b('0x2d')]=function(_0x599a60,_0x1a701e){var _0x479443={},_0x3cd954={},_0x77f585={'count':0x0,'rows':[]};var _0x55cae1=_[_0x4b1b('0x2e')](db[_0x4b1b('0x2f')][_0x4b1b('0x30')],function(_0x4c49d4){return{'name':_0x4c49d4[_0x4b1b('0x31')],'type':_0x4c49d4['type'][_0x4b1b('0x32')]};});_0x3cd954[_0x4b1b('0x33')]=_[_0x4b1b('0x2e')](_0x55cae1,_0x4b1b('0x2b'));_0x3cd954['query']=_[_0x4b1b('0x34')](_0x599a60['query']);_0x3cd954[_0x4b1b('0x35')]=_['intersection'](_0x3cd954['model'],_0x3cd954[_0x4b1b('0x36')]);_0x479443[_0x4b1b('0x37')]=_[_0x4b1b('0x38')](_0x3cd954[_0x4b1b('0x33')],qs[_0x4b1b('0x39')](_0x599a60[_0x4b1b('0x36')]['fields']));_0x479443[_0x4b1b('0x37')]=_0x479443[_0x4b1b('0x37')][_0x4b1b('0x3a')]?_0x479443['attributes']:_0x3cd954[_0x4b1b('0x33')];if(!_0x599a60[_0x4b1b('0x36')][_0x4b1b('0x3b')](_0x4b1b('0x3c'))){_0x479443[_0x4b1b('0x1f')]=qs[_0x4b1b('0x1f')](_0x599a60[_0x4b1b('0x36')][_0x4b1b('0x1f')]);_0x479443[_0x4b1b('0x1e')]=qs[_0x4b1b('0x1e')](_0x599a60[_0x4b1b('0x36')][_0x4b1b('0x1e')]);}_0x479443[_0x4b1b('0x3d')]=qs['sort'](_0x599a60[_0x4b1b('0x36')]['sort']);_0x479443['where']=qs[_0x4b1b('0x35')](_[_0x4b1b('0x3e')](_0x599a60[_0x4b1b('0x36')],_0x3cd954[_0x4b1b('0x35')]),_0x55cae1);if(_0x599a60['query'][_0x4b1b('0x3f')]){_0x479443['where']=_['merge'](_0x479443[_0x4b1b('0x40')],{'$or':_[_0x4b1b('0x2e')](_0x55cae1,function(_0x2d74df){if(_0x2d74df[_0x4b1b('0x41')]!==_0x4b1b('0x42')){var _0x35f53c={};_0x35f53c[_0x2d74df[_0x4b1b('0x2b')]]={'$like':'%'+_0x599a60[_0x4b1b('0x36')][_0x4b1b('0x3f')]+'%'};return _0x35f53c;}})});}_0x479443=_[_0x4b1b('0x43')]({},_0x479443,_0x599a60[_0x4b1b('0x44')]);var _0x43e7e1={'where':_0x479443[_0x4b1b('0x40')]};return db['AnalyticTreeReport'][_0x4b1b('0x45')](_0x43e7e1)['then'](function(_0x3faa56){_0x77f585[_0x4b1b('0x45')]=_0x3faa56;if(_0x599a60['query'][_0x4b1b('0x46')]){_0x479443[_0x4b1b('0x47')]=[{'all':!![]}];}return db[_0x4b1b('0x2f')]['findAll'](_0x479443);})[_0x4b1b('0x25')](function(_0x3a3406){_0x77f585[_0x4b1b('0x48')]=_0x3a3406;return _0x77f585;})[_0x4b1b('0x25')](respondWithFilteredResult(_0x1a701e,_0x479443))['catch'](handleError(_0x1a701e,null));};exports[_0x4b1b('0x49')]=function(_0x59c8bb,_0xda889e){var _0x4dacfe={'raw':!![],'where':{'id':_0x59c8bb[_0x4b1b('0x4a')]['id']}},_0x4fbc0f={};_0x4fbc0f[_0x4b1b('0x33')]=_[_0x4b1b('0x34')](db['AnalyticTreeReport'][_0x4b1b('0x30')]);_0x4fbc0f[_0x4b1b('0x36')]=_[_0x4b1b('0x34')](_0x59c8bb['query']);_0x4fbc0f[_0x4b1b('0x35')]=_[_0x4b1b('0x38')](_0x4fbc0f['model'],_0x4fbc0f[_0x4b1b('0x36')]);_0x4dacfe[_0x4b1b('0x37')]=_['intersection'](_0x4fbc0f[_0x4b1b('0x33')],qs[_0x4b1b('0x39')](_0x59c8bb[_0x4b1b('0x36')][_0x4b1b('0x39')]));_0x4dacfe[_0x4b1b('0x37')]=_0x4dacfe[_0x4b1b('0x37')]['length']?_0x4dacfe[_0x4b1b('0x37')]:_0x4fbc0f[_0x4b1b('0x33')];if(_0x59c8bb[_0x4b1b('0x36')][_0x4b1b('0x46')]){_0x4dacfe[_0x4b1b('0x47')]=[{'all':!![]}];}_0x4dacfe=_[_0x4b1b('0x43')]({},_0x4dacfe,_0x59c8bb['options']);return db[_0x4b1b('0x2f')][_0x4b1b('0x4b')](_0x4dacfe)[_0x4b1b('0x25')](handleEntityNotFound(_0xda889e,null))[_0x4b1b('0x25')](respondWithResult(_0xda889e,null))[_0x4b1b('0x4c')](handleError(_0xda889e,null));};exports[_0x4b1b('0x4d')]=function(_0x56aac7,_0x30e60e){return db[_0x4b1b('0x2f')][_0x4b1b('0x4d')](_0x56aac7['body'],{})[_0x4b1b('0x25')](respondWithResult(_0x30e60e,0xc9))[_0x4b1b('0x4c')](handleError(_0x30e60e,null));};exports[_0x4b1b('0x24')]=function(_0x402861,_0x4cc6bd){if(_0x402861[_0x4b1b('0x4e')]['id']){delete _0x402861[_0x4b1b('0x4e')]['id'];}return db[_0x4b1b('0x2f')][_0x4b1b('0x4b')]({'where':{'id':_0x402861['params']['id']}})['then'](handleEntityNotFound(_0x4cc6bd,null))[_0x4b1b('0x25')](saveUpdates(_0x402861[_0x4b1b('0x4e')],null))[_0x4b1b('0x25')](respondWithResult(_0x4cc6bd,null))[_0x4b1b('0x4c')](handleError(_0x4cc6bd,null));};exports[_0x4b1b('0x26')]=function(_0x202957,_0x5667a6){return db[_0x4b1b('0x2f')]['find']({'where':{'id':_0x202957['params']['id']}})[_0x4b1b('0x25')](handleEntityNotFound(_0x5667a6,null))[_0x4b1b('0x25')](removeEntity(_0x5667a6,null))[_0x4b1b('0x4c')](handleError(_0x5667a6,null));};