Built motion from commit 5ae82ce5.|2.6.7
[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 _0xf411=['type','VIRTUAL','options','includeAll','catch','show','params','keys','include','create','body','find','eml-format','rimraf','fast-json-patch','request-promise','moment','bluebird','mustache','util','to-csv','ejs','fs-extra','lodash','squel','jsforce','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../mysqldb','status','json','offset','undefined','count','set','Content-Range','apply','save','update','then','destroy','end','sendStatus','error','stack','name','send','map','AnalyticTreeReport','rawAttributes','fieldName','key','query','filters','intersection','attributes','model','fields','hasOwnProperty','limit','where','filter','merge'];(function(_0x55d829,_0x43f06c){var _0x52163b=function(_0x493cd8){while(--_0x493cd8){_0x55d829['push'](_0x55d829['shift']());}};_0x52163b(++_0x43f06c);}(_0xf411,0x98));var _0x1f41=function(_0x2ee712,_0x5a2179){_0x2ee712=_0x2ee712-0x0;var _0x2e8783=_0xf411[_0x2ee712];return _0x2e8783;};'use strict';var emlformat=require(_0x1f41('0x0'));var rimraf=require(_0x1f41('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0x1f41('0x2'));var rp=require(_0x1f41('0x3'));var moment=require(_0x1f41('0x4'));var BPromise=require(_0x1f41('0x5'));var Mustache=require(_0x1f41('0x6'));var util=require(_0x1f41('0x7'));var path=require('path');var sox=require('sox');var csv=require(_0x1f41('0x8'));var ejs=require(_0x1f41('0x9'));var fs=require('fs');var fs_extra=require(_0x1f41('0xa'));var _=require(_0x1f41('0xb'));var squel=require(_0x1f41('0xc'));var crypto=require('crypto');var jsforce=require(_0x1f41('0xd'));var deskjs=require('desk.js');var toCsv=require(_0x1f41('0x8'));var querystring=require(_0x1f41('0xe'));var Papa=require(_0x1f41('0xf'));var Redis=require('ioredis');var authService=require(_0x1f41('0x10'));var qs=require(_0x1f41('0x11'));var as=require(_0x1f41('0x12'));var hardwareService=require(_0x1f41('0x13'));var logger=require(_0x1f41('0x14'))(_0x1f41('0x15'));var utils=require(_0x1f41('0x16'));var config=require('../../config/environment');var licenseUtil=require('../../config/license/util');var db=require(_0x1f41('0x17'))['db'];function respondWithStatusCode(_0x148b9a,_0x2ffc46){_0x2ffc46=_0x2ffc46||0xcc;return function(_0x11c3c5){if(_0x11c3c5){return _0x148b9a['sendStatus'](_0x2ffc46);}return _0x148b9a[_0x1f41('0x18')](_0x2ffc46)['end']();};}function respondWithResult(_0x2dac4c,_0x557ff8){_0x557ff8=_0x557ff8||0xc8;return function(_0x8de505){if(_0x8de505){return _0x2dac4c[_0x1f41('0x18')](_0x557ff8)[_0x1f41('0x19')](_0x8de505);}};}function respondWithFilteredResult(_0x507652,_0x541a3c){return function(_0x196acd){if(_0x196acd){var _0x9a7fbc=typeof _0x541a3c[_0x1f41('0x1a')]===_0x1f41('0x1b')&&typeof _0x541a3c['limit']===_0x1f41('0x1b');var _0x768646=_0x196acd[_0x1f41('0x1c')];var _0x3ea6ff=_0x9a7fbc?0x0:_0x541a3c[_0x1f41('0x1a')];var _0x5e8dfc=_0x9a7fbc?_0x196acd[_0x1f41('0x1c')]:_0x541a3c[_0x1f41('0x1a')]+_0x541a3c['limit'];var _0x1d44ef;if(_0x5e8dfc>=_0x768646){_0x5e8dfc=_0x768646;_0x1d44ef=0xc8;}else{_0x1d44ef=0xce;}_0x507652['status'](_0x1d44ef);return _0x507652[_0x1f41('0x1d')](_0x1f41('0x1e'),_0x3ea6ff+'-'+_0x5e8dfc+'/'+_0x768646)[_0x1f41('0x19')](_0x196acd);}return null;};}function patchUpdates(_0x3d8008){return function(_0x26e2fc){try{jsonpatch[_0x1f41('0x1f')](_0x26e2fc,_0x3d8008,!![]);}catch(_0x55f746){return BPromise['reject'](_0x55f746);}return _0x26e2fc[_0x1f41('0x20')]();};}function saveUpdates(_0x2c6624,_0x2abceb){return function(_0x26c159){if(_0x26c159){return _0x26c159[_0x1f41('0x21')](_0x2c6624)[_0x1f41('0x22')](function(_0x2641fa){return _0x2641fa;});}return null;};}function removeEntity(_0x59ea4d,_0x19977f){return function(_0x224fbd){if(_0x224fbd){return _0x224fbd[_0x1f41('0x23')]()[_0x1f41('0x22')](function(){_0x59ea4d[_0x1f41('0x18')](0xcc)[_0x1f41('0x24')]();});}};}function handleEntityNotFound(_0x168197,_0x3bce12){return function(_0x59269b){if(!_0x59269b){_0x168197[_0x1f41('0x25')](0x194);}return _0x59269b;};}function handleError(_0xf9a529,_0x5a5f38){_0x5a5f38=_0x5a5f38||0x1f4;return function(_0x23780){logger[_0x1f41('0x26')](_0x23780[_0x1f41('0x27')]);if(_0x23780[_0x1f41('0x28')]){delete _0x23780['name'];}_0xf9a529[_0x1f41('0x18')](_0x5a5f38)[_0x1f41('0x29')](_0x23780);};}exports['index']=function(_0x415d30,_0x2aab27){var _0x45e687={},_0x1f0c9c={},_0x2710ef={'count':0x0,'rows':[]};var _0x273e66=_[_0x1f41('0x2a')](db[_0x1f41('0x2b')][_0x1f41('0x2c')],function(_0x51a323){return{'name':_0x51a323[_0x1f41('0x2d')],'type':_0x51a323['type'][_0x1f41('0x2e')]};});_0x1f0c9c['model']=_[_0x1f41('0x2a')](_0x273e66,_0x1f41('0x28'));_0x1f0c9c[_0x1f41('0x2f')]=_['keys'](_0x415d30['query']);_0x1f0c9c[_0x1f41('0x30')]=_[_0x1f41('0x31')](_0x1f0c9c['model'],_0x1f0c9c[_0x1f41('0x2f')]);_0x45e687[_0x1f41('0x32')]=_['intersection'](_0x1f0c9c[_0x1f41('0x33')],qs[_0x1f41('0x34')](_0x415d30[_0x1f41('0x2f')][_0x1f41('0x34')]));_0x45e687[_0x1f41('0x32')]=_0x45e687[_0x1f41('0x32')]['length']?_0x45e687[_0x1f41('0x32')]:_0x1f0c9c[_0x1f41('0x33')];if(!_0x415d30[_0x1f41('0x2f')][_0x1f41('0x35')]('nolimit')){_0x45e687[_0x1f41('0x36')]=qs['limit'](_0x415d30[_0x1f41('0x2f')][_0x1f41('0x36')]);_0x45e687[_0x1f41('0x1a')]=qs[_0x1f41('0x1a')](_0x415d30[_0x1f41('0x2f')][_0x1f41('0x1a')]);}_0x45e687['order']=qs['sort'](_0x415d30[_0x1f41('0x2f')]['sort']);_0x45e687[_0x1f41('0x37')]=qs[_0x1f41('0x30')](_['pick'](_0x415d30[_0x1f41('0x2f')],_0x1f0c9c[_0x1f41('0x30')]),_0x273e66);if(_0x415d30[_0x1f41('0x2f')][_0x1f41('0x38')]){_0x45e687[_0x1f41('0x37')]=_[_0x1f41('0x39')](_0x45e687['where'],{'$or':_['map'](_0x273e66,function(_0x1050bc){if(_0x1050bc[_0x1f41('0x3a')]!==_0x1f41('0x3b')){var _0x71aa17={};_0x71aa17[_0x1050bc[_0x1f41('0x28')]]={'$like':'%'+_0x415d30[_0x1f41('0x2f')][_0x1f41('0x38')]+'%'};return _0x71aa17;}})});}_0x45e687=_[_0x1f41('0x39')]({},_0x45e687,_0x415d30[_0x1f41('0x3c')]);var _0x3d91ae={'where':_0x45e687[_0x1f41('0x37')]};return db[_0x1f41('0x2b')][_0x1f41('0x1c')](_0x3d91ae)[_0x1f41('0x22')](function(_0xef90c8){_0x2710ef['count']=_0xef90c8;if(_0x415d30[_0x1f41('0x2f')][_0x1f41('0x3d')]){_0x45e687['include']=[{'all':!![]}];}return db[_0x1f41('0x2b')]['findAll'](_0x45e687);})['then'](function(_0x1a3aba){_0x2710ef['rows']=_0x1a3aba;return _0x2710ef;})['then'](respondWithFilteredResult(_0x2aab27,_0x45e687))[_0x1f41('0x3e')](handleError(_0x2aab27,null));};exports[_0x1f41('0x3f')]=function(_0x5c4081,_0x1bedc6){var _0x3fab24={'raw':!![],'where':{'id':_0x5c4081[_0x1f41('0x40')]['id']}},_0x5f4fb5={};_0x5f4fb5['model']=_[_0x1f41('0x41')](db[_0x1f41('0x2b')][_0x1f41('0x2c')]);_0x5f4fb5[_0x1f41('0x2f')]=_[_0x1f41('0x41')](_0x5c4081[_0x1f41('0x2f')]);_0x5f4fb5[_0x1f41('0x30')]=_['intersection'](_0x5f4fb5['model'],_0x5f4fb5[_0x1f41('0x2f')]);_0x3fab24['attributes']=_[_0x1f41('0x31')](_0x5f4fb5['model'],qs['fields'](_0x5c4081[_0x1f41('0x2f')][_0x1f41('0x34')]));_0x3fab24['attributes']=_0x3fab24[_0x1f41('0x32')]['length']?_0x3fab24['attributes']:_0x5f4fb5[_0x1f41('0x33')];if(_0x5c4081[_0x1f41('0x2f')]['includeAll']){_0x3fab24[_0x1f41('0x42')]=[{'all':!![]}];}_0x3fab24=_[_0x1f41('0x39')]({},_0x3fab24,_0x5c4081[_0x1f41('0x3c')]);return db[_0x1f41('0x2b')]['find'](_0x3fab24)['then'](handleEntityNotFound(_0x1bedc6,null))[_0x1f41('0x22')](respondWithResult(_0x1bedc6,null))[_0x1f41('0x3e')](handleError(_0x1bedc6,null));};exports[_0x1f41('0x43')]=function(_0x4dd502,_0x37848f){return db[_0x1f41('0x2b')]['create'](_0x4dd502[_0x1f41('0x44')],{})['then'](respondWithResult(_0x37848f,0xc9))['catch'](handleError(_0x37848f,null));};exports[_0x1f41('0x21')]=function(_0x972597,_0x4764e6){if(_0x972597['body']['id']){delete _0x972597[_0x1f41('0x44')]['id'];}return db[_0x1f41('0x2b')][_0x1f41('0x45')]({'where':{'id':_0x972597[_0x1f41('0x40')]['id']}})[_0x1f41('0x22')](handleEntityNotFound(_0x4764e6,null))[_0x1f41('0x22')](saveUpdates(_0x972597['body'],null))['then'](respondWithResult(_0x4764e6,null))[_0x1f41('0x3e')](handleError(_0x4764e6,null));};exports['destroy']=function(_0x4d015a,_0x45eacb){return db[_0x1f41('0x2b')][_0x1f41('0x45')]({'where':{'id':_0x4d015a[_0x1f41('0x40')]['id']}})[_0x1f41('0x22')](handleEntityNotFound(_0x45eacb,null))['then'](removeEntity(_0x45eacb,null))['catch'](handleError(_0x45eacb,null));};