c15ba57ae578d0c1c92e9b9faa848b470ca734d9
[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 _0x76fc=['AnalyticTreeReport','rawAttributes','type','key','model','query','keys','filters','attributes','intersection','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','VIRTUAL','count','includeAll','include','rows','catch','show','params','options','create','body','html-pdf','eml-format','zip-dir','moment','bluebird','mustache','util','path','sox','ejs','lodash','crypto','jsforce','desk.js','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','json','offset','limit','apply','reject','save','update','destroy','then','error','stack','name','send','index','map'];(function(_0x5f2db8,_0x29c7d6){var _0x240596=function(_0x74f9fa){while(--_0x74f9fa){_0x5f2db8['push'](_0x5f2db8['shift']());}};_0x240596(++_0x29c7d6);}(_0x76fc,0x18c));var _0xc76f=function(_0x28aff6,_0x390453){_0x28aff6=_0x28aff6-0x0;var _0x1be069=_0x76fc[_0x28aff6];return _0x1be069;};'use strict';var pdf=require(_0xc76f('0x0'));var emlformat=require(_0xc76f('0x1'));var rimraf=require('rimraf');var zipdir=require(_0xc76f('0x2'));var jsonpatch=require('fast-json-patch');var rp=require('request-promise');var moment=require(_0xc76f('0x3'));var BPromise=require(_0xc76f('0x4'));var Mustache=require(_0xc76f('0x5'));var util=require(_0xc76f('0x6'));var path=require(_0xc76f('0x7'));var sox=require(_0xc76f('0x8'));var csv=require('to-csv');var ejs=require(_0xc76f('0x9'));var fs=require('fs');var _=require(_0xc76f('0xa'));var squel=require('squel');var crypto=require(_0xc76f('0xb'));var jsforce=require(_0xc76f('0xc'));var deskjs=require(_0xc76f('0xd'));var toCsv=require('to-csv');var querystring=require(_0xc76f('0xe'));var Papa=require('papaparse');var Redis=require(_0xc76f('0xf'));var authService=require(_0xc76f('0x10'));var qs=require(_0xc76f('0x11'));var as=require(_0xc76f('0x12'));var hardwareService=require('../../config/license/hardware');var logger=require(_0xc76f('0x13'))(_0xc76f('0x14'));var utils=require(_0xc76f('0x15'));var config=require(_0xc76f('0x16'));var licenseUtil=require(_0xc76f('0x17'));var db=require(_0xc76f('0x18'))['db'];function respondWithStatusCode(_0x41f3f0,_0x3d6ec9){_0x3d6ec9=_0x3d6ec9||0xcc;return function(_0x362bfe){if(_0x362bfe){return _0x41f3f0[_0xc76f('0x19')](_0x3d6ec9);}return _0x41f3f0['status'](_0x3d6ec9)['end']();};}function respondWithResult(_0x12a4db,_0x348435){_0x348435=_0x348435||0xc8;return function(_0x1471e0){if(_0x1471e0){return _0x12a4db[_0xc76f('0x1a')](_0x348435)[_0xc76f('0x1b')](_0x1471e0);}};}function respondWithFilteredResult(_0x5de9f2,_0x1f8959){return function(_0x5f1452){if(_0x5f1452){var _0x42214e=_0x5f1452['count'],_0x3d780d=_0x1f8959[_0xc76f('0x1c')],_0x2b3123=_0x1f8959[_0xc76f('0x1c')]+_0x1f8959[_0xc76f('0x1d')],_0x514f88;if(_0x2b3123>=_0x42214e){_0x2b3123=_0x42214e;_0x514f88=0xc8;}else{_0x514f88=0xce;}_0x5de9f2[_0xc76f('0x1a')](_0x514f88);return _0x5de9f2['set']('Content-Range',_0x3d780d+'-'+_0x2b3123+'/'+_0x42214e)[_0xc76f('0x1b')](_0x5f1452);}return null;};}function patchUpdates(_0x4265e2){return function(_0x10bd42){try{jsonpatch[_0xc76f('0x1e')](_0x10bd42,_0x4265e2,!![]);}catch(_0x27b4dd){return BPromise[_0xc76f('0x1f')](_0x27b4dd);}return _0x10bd42[_0xc76f('0x20')]();};}function saveUpdates(_0x567ee8,_0x1f0e69){return function(_0x4ad12a){if(_0x4ad12a){return _0x4ad12a[_0xc76f('0x21')](_0x567ee8)['then'](function(_0x5ca6e6){return _0x5ca6e6;});}return null;};}function removeEntity(_0xc53715,_0x5e9e89){return function(_0x40b9d1){if(_0x40b9d1){return _0x40b9d1[_0xc76f('0x22')]()[_0xc76f('0x23')](function(){_0xc53715[_0xc76f('0x1a')](0xcc)['end']();});}};}function handleEntityNotFound(_0x3d3b63,_0x4ffbe2){return function(_0x51b30e){if(!_0x51b30e){_0x3d3b63[_0xc76f('0x19')](0x194);}return _0x51b30e;};}function handleError(_0x3c8973,_0x4655fc){_0x4655fc=_0x4655fc||0x1f4;return function(_0x28e890){logger[_0xc76f('0x24')](_0x28e890[_0xc76f('0x25')]);if(_0x28e890['name']){delete _0x28e890[_0xc76f('0x26')];}_0x3c8973[_0xc76f('0x1a')](_0x4655fc)[_0xc76f('0x27')](_0x28e890);};}exports[_0xc76f('0x28')]=function(_0x2f903e,_0x1913ca){var _0x46359a={},_0x59ec7b={},_0x2ca109={'count':0x0,'rows':[]};var _0x58de8a=_[_0xc76f('0x29')](db[_0xc76f('0x2a')][_0xc76f('0x2b')],function(_0x342da0){return{'name':_0x342da0['fieldName'],'type':_0x342da0[_0xc76f('0x2c')][_0xc76f('0x2d')]};});_0x59ec7b[_0xc76f('0x2e')]=_[_0xc76f('0x29')](_0x58de8a,_0xc76f('0x26'));_0x59ec7b[_0xc76f('0x2f')]=_[_0xc76f('0x30')](_0x2f903e[_0xc76f('0x2f')]);_0x59ec7b[_0xc76f('0x31')]=_['intersection'](_0x59ec7b[_0xc76f('0x2e')],_0x59ec7b[_0xc76f('0x2f')]);_0x46359a[_0xc76f('0x32')]=_[_0xc76f('0x33')](_0x59ec7b[_0xc76f('0x2e')],qs[_0xc76f('0x34')](_0x2f903e[_0xc76f('0x2f')][_0xc76f('0x34')]));_0x46359a[_0xc76f('0x32')]=_0x46359a[_0xc76f('0x32')][_0xc76f('0x35')]?_0x46359a[_0xc76f('0x32')]:_0x59ec7b[_0xc76f('0x2e')];if(!_0x2f903e[_0xc76f('0x2f')][_0xc76f('0x36')](_0xc76f('0x37'))){_0x46359a[_0xc76f('0x1d')]=qs['limit'](_0x2f903e[_0xc76f('0x2f')]['limit']);_0x46359a['offset']=qs[_0xc76f('0x1c')](_0x2f903e[_0xc76f('0x2f')][_0xc76f('0x1c')]);}_0x46359a[_0xc76f('0x38')]=qs[_0xc76f('0x39')](_0x2f903e[_0xc76f('0x2f')][_0xc76f('0x39')]);_0x46359a[_0xc76f('0x3a')]=qs[_0xc76f('0x31')](_[_0xc76f('0x3b')](_0x2f903e['query'],_0x59ec7b[_0xc76f('0x31')]),_0x58de8a);if(_0x2f903e[_0xc76f('0x2f')][_0xc76f('0x3c')]){_0x46359a[_0xc76f('0x3a')]=_[_0xc76f('0x3d')](_0x46359a[_0xc76f('0x3a')],{'$or':_[_0xc76f('0x29')](_0x58de8a,function(_0x30b634){if(_0x30b634[_0xc76f('0x2c')]!==_0xc76f('0x3e')){var _0x3d7da9={};_0x3d7da9[_0x30b634['name']]={'$like':'%'+_0x2f903e['query'][_0xc76f('0x3c')]+'%'};return _0x3d7da9;}})});}_0x46359a=_[_0xc76f('0x3d')]({},_0x46359a,_0x2f903e['options']);var _0xe971ae={'where':_0x46359a['where']};return db[_0xc76f('0x2a')][_0xc76f('0x3f')](_0xe971ae)['then'](function(_0x12019c){_0x2ca109[_0xc76f('0x3f')]=_0x12019c;if(_0x2f903e[_0xc76f('0x2f')][_0xc76f('0x40')]){_0x46359a[_0xc76f('0x41')]=[{'all':!![]}];}return db[_0xc76f('0x2a')]['findAll'](_0x46359a);})[_0xc76f('0x23')](function(_0x3a12bb){_0x2ca109[_0xc76f('0x42')]=_0x3a12bb;return _0x2ca109;})[_0xc76f('0x23')](respondWithFilteredResult(_0x1913ca,_0x46359a))[_0xc76f('0x43')](handleError(_0x1913ca,null));};exports[_0xc76f('0x44')]=function(_0x4cb6df,_0x3be082){var _0x9b4e44={'raw':!![],'where':{'id':_0x4cb6df[_0xc76f('0x45')]['id']}},_0x4652d8={};_0x4652d8[_0xc76f('0x2e')]=_[_0xc76f('0x30')](db[_0xc76f('0x2a')][_0xc76f('0x2b')]);_0x4652d8[_0xc76f('0x2f')]=_[_0xc76f('0x30')](_0x4cb6df[_0xc76f('0x2f')]);_0x4652d8[_0xc76f('0x31')]=_['intersection'](_0x4652d8[_0xc76f('0x2e')],_0x4652d8[_0xc76f('0x2f')]);_0x9b4e44[_0xc76f('0x32')]=_[_0xc76f('0x33')](_0x4652d8['model'],qs['fields'](_0x4cb6df[_0xc76f('0x2f')][_0xc76f('0x34')]));_0x9b4e44[_0xc76f('0x32')]=_0x9b4e44[_0xc76f('0x32')][_0xc76f('0x35')]?_0x9b4e44[_0xc76f('0x32')]:_0x4652d8[_0xc76f('0x2e')];if(_0x4cb6df[_0xc76f('0x2f')][_0xc76f('0x40')]){_0x9b4e44['include']=[{'all':!![]}];}_0x9b4e44=_[_0xc76f('0x3d')]({},_0x9b4e44,_0x4cb6df[_0xc76f('0x46')]);return db[_0xc76f('0x2a')]['find'](_0x9b4e44)['then'](handleEntityNotFound(_0x3be082,null))['then'](respondWithResult(_0x3be082,null))['catch'](handleError(_0x3be082,null));};exports[_0xc76f('0x47')]=function(_0x361503,_0x4f6087){return db[_0xc76f('0x2a')][_0xc76f('0x47')](_0x361503[_0xc76f('0x48')],{})['then'](respondWithResult(_0x4f6087,0xc9))[_0xc76f('0x43')](handleError(_0x4f6087,null));};exports['update']=function(_0x1afa2f,_0x34c80d){if(_0x1afa2f[_0xc76f('0x48')]['id']){delete _0x1afa2f[_0xc76f('0x48')]['id'];}return db[_0xc76f('0x2a')]['find']({'where':{'id':_0x1afa2f[_0xc76f('0x45')]['id']}})[_0xc76f('0x23')](handleEntityNotFound(_0x34c80d,null))[_0xc76f('0x23')](saveUpdates(_0x1afa2f[_0xc76f('0x48')],null))[_0xc76f('0x23')](respondWithResult(_0x34c80d,null))[_0xc76f('0x43')](handleError(_0x34c80d,null));};exports['destroy']=function(_0xfe54fa,_0x9b4848){return db['AnalyticTreeReport']['find']({'where':{'id':_0xfe54fa[_0xc76f('0x45')]['id']}})[_0xc76f('0x23')](handleEntityNotFound(_0x9b4848,null))[_0xc76f('0x23')](removeEntity(_0x9b4848,null))[_0xc76f('0x43')](handleError(_0x9b4848,null));};