b530bb527bf11d82bd7324cbae1a03f7c4e9bae3
[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 _0x280f=['moment','bluebird','mustache','util','path','sox','to-csv','fs-extra','lodash','crypto','jsforce','desk.js','papaparse','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','json','limit','count','offset','set','Content-Range','apply','save','update','then','destroy','end','stack','name','send','index','AnalyticTreeReport','rawAttributes','model','map','query','filters','intersection','fields','hasOwnProperty','nolimit','order','sort','where','filter','type','merge','options','includeAll','include','findAll','rows','catch','keys','attributes','length','find','create','body','params','eml-format','rimraf','zip-dir','fast-json-patch','request-promise'];(function(_0x1ba52b,_0xe8055a){var _0xf14517=function(_0x33bb2e){while(--_0x33bb2e){_0x1ba52b['push'](_0x1ba52b['shift']());}};_0xf14517(++_0xe8055a);}(_0x280f,0xdc));var _0xf280=function(_0x2718c7,_0x5a1636){_0x2718c7=_0x2718c7-0x0;var _0x59d89c=_0x280f[_0x2718c7];return _0x59d89c;};'use strict';var emlformat=require(_0xf280('0x0'));var rimraf=require(_0xf280('0x1'));var zipdir=require(_0xf280('0x2'));var jsonpatch=require(_0xf280('0x3'));var rp=require(_0xf280('0x4'));var moment=require(_0xf280('0x5'));var BPromise=require(_0xf280('0x6'));var Mustache=require(_0xf280('0x7'));var util=require(_0xf280('0x8'));var path=require(_0xf280('0x9'));var sox=require(_0xf280('0xa'));var csv=require(_0xf280('0xb'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0xf280('0xc'));var _=require(_0xf280('0xd'));var squel=require('squel');var crypto=require(_0xf280('0xe'));var jsforce=require(_0xf280('0xf'));var deskjs=require(_0xf280('0x10'));var toCsv=require(_0xf280('0xb'));var querystring=require('querystring');var Papa=require(_0xf280('0x11'));var Redis=require(_0xf280('0x12'));var authService=require('../../components/auth/service');var qs=require(_0xf280('0x13'));var as=require(_0xf280('0x14'));var hardwareService=require(_0xf280('0x15'));var logger=require(_0xf280('0x16'))(_0xf280('0x17'));var utils=require(_0xf280('0x18'));var config=require(_0xf280('0x19'));var licenseUtil=require(_0xf280('0x1a'));var db=require(_0xf280('0x1b'))['db'];function respondWithStatusCode(_0x3006a6,_0x2247e5){_0x2247e5=_0x2247e5||0xcc;return function(_0x3652d4){if(_0x3652d4){return _0x3006a6[_0xf280('0x1c')](_0x2247e5);}return _0x3006a6['status'](_0x2247e5)['end']();};}function respondWithResult(_0x1b4b75,_0x23f85c){_0x23f85c=_0x23f85c||0xc8;return function(_0x299de3){if(_0x299de3){return _0x1b4b75[_0xf280('0x1d')](_0x23f85c)[_0xf280('0x1e')](_0x299de3);}};}function respondWithFilteredResult(_0x2c00e5,_0x363049){return function(_0x3eeecc){if(_0x3eeecc){var _0x4dd261=typeof _0x363049['offset']==='undefined'&&typeof _0x363049[_0xf280('0x1f')]==='undefined';var _0x5d7427=_0x3eeecc[_0xf280('0x20')];var _0x4d7745=_0x4dd261?0x0:_0x363049['offset'];var _0x71208=_0x4dd261?_0x3eeecc[_0xf280('0x20')]:_0x363049[_0xf280('0x21')]+_0x363049[_0xf280('0x1f')];var _0x6b9c21;if(_0x71208>=_0x5d7427){_0x71208=_0x5d7427;_0x6b9c21=0xc8;}else{_0x6b9c21=0xce;}_0x2c00e5[_0xf280('0x1d')](_0x6b9c21);return _0x2c00e5[_0xf280('0x22')](_0xf280('0x23'),_0x4d7745+'-'+_0x71208+'/'+_0x5d7427)['json'](_0x3eeecc);}return null;};}function patchUpdates(_0x377f76){return function(_0x46d975){try{jsonpatch[_0xf280('0x24')](_0x46d975,_0x377f76,!![]);}catch(_0x274dc8){return BPromise['reject'](_0x274dc8);}return _0x46d975[_0xf280('0x25')]();};}function saveUpdates(_0x42c42e,_0x5aeea1){return function(_0x414d92){if(_0x414d92){return _0x414d92[_0xf280('0x26')](_0x42c42e)[_0xf280('0x27')](function(_0x56bad9){return _0x56bad9;});}return null;};}function removeEntity(_0x249904,_0x171e73){return function(_0xf76d3b){if(_0xf76d3b){return _0xf76d3b[_0xf280('0x28')]()[_0xf280('0x27')](function(){_0x249904[_0xf280('0x1d')](0xcc)[_0xf280('0x29')]();});}};}function handleEntityNotFound(_0x5595ab,_0x38d9c7){return function(_0x416a3b){if(!_0x416a3b){_0x5595ab[_0xf280('0x1c')](0x194);}return _0x416a3b;};}function handleError(_0x66b8fc,_0x22c5a1){_0x22c5a1=_0x22c5a1||0x1f4;return function(_0x3b7232){logger['error'](_0x3b7232[_0xf280('0x2a')]);if(_0x3b7232[_0xf280('0x2b')]){delete _0x3b7232[_0xf280('0x2b')];}_0x66b8fc[_0xf280('0x1d')](_0x22c5a1)[_0xf280('0x2c')](_0x3b7232);};}exports[_0xf280('0x2d')]=function(_0x4d407b,_0x5125b8){var _0x128d0f={},_0x22ef11={},_0x27b6a3={'count':0x0,'rows':[]};var _0x1a2e92=_['map'](db[_0xf280('0x2e')][_0xf280('0x2f')],function(_0x375058){return{'name':_0x375058['fieldName'],'type':_0x375058['type']['key']};});_0x22ef11[_0xf280('0x30')]=_[_0xf280('0x31')](_0x1a2e92,_0xf280('0x2b'));_0x22ef11[_0xf280('0x32')]=_['keys'](_0x4d407b[_0xf280('0x32')]);_0x22ef11[_0xf280('0x33')]=_[_0xf280('0x34')](_0x22ef11[_0xf280('0x30')],_0x22ef11[_0xf280('0x32')]);_0x128d0f['attributes']=_[_0xf280('0x34')](_0x22ef11[_0xf280('0x30')],qs[_0xf280('0x35')](_0x4d407b[_0xf280('0x32')][_0xf280('0x35')]));_0x128d0f['attributes']=_0x128d0f['attributes']['length']?_0x128d0f['attributes']:_0x22ef11[_0xf280('0x30')];if(!_0x4d407b[_0xf280('0x32')][_0xf280('0x36')](_0xf280('0x37'))){_0x128d0f[_0xf280('0x1f')]=qs[_0xf280('0x1f')](_0x4d407b[_0xf280('0x32')]['limit']);_0x128d0f['offset']=qs[_0xf280('0x21')](_0x4d407b[_0xf280('0x32')]['offset']);}_0x128d0f[_0xf280('0x38')]=qs[_0xf280('0x39')](_0x4d407b['query'][_0xf280('0x39')]);_0x128d0f[_0xf280('0x3a')]=qs[_0xf280('0x33')](_['pick'](_0x4d407b[_0xf280('0x32')],_0x22ef11[_0xf280('0x33')]),_0x1a2e92);if(_0x4d407b[_0xf280('0x32')][_0xf280('0x3b')]){_0x128d0f[_0xf280('0x3a')]=_['merge'](_0x128d0f[_0xf280('0x3a')],{'$or':_[_0xf280('0x31')](_0x1a2e92,function(_0x1f90af){if(_0x1f90af[_0xf280('0x3c')]!=='VIRTUAL'){var _0x5a0bd9={};_0x5a0bd9[_0x1f90af['name']]={'$like':'%'+_0x4d407b['query'][_0xf280('0x3b')]+'%'};return _0x5a0bd9;}})});}_0x128d0f=_[_0xf280('0x3d')]({},_0x128d0f,_0x4d407b[_0xf280('0x3e')]);var _0x495ef4={'where':_0x128d0f[_0xf280('0x3a')]};return db[_0xf280('0x2e')][_0xf280('0x20')](_0x495ef4)['then'](function(_0x1c4612){_0x27b6a3[_0xf280('0x20')]=_0x1c4612;if(_0x4d407b[_0xf280('0x32')][_0xf280('0x3f')]){_0x128d0f[_0xf280('0x40')]=[{'all':!![]}];}return db['AnalyticTreeReport'][_0xf280('0x41')](_0x128d0f);})[_0xf280('0x27')](function(_0x425f7b){_0x27b6a3[_0xf280('0x42')]=_0x425f7b;return _0x27b6a3;})[_0xf280('0x27')](respondWithFilteredResult(_0x5125b8,_0x128d0f))[_0xf280('0x43')](handleError(_0x5125b8,null));};exports['show']=function(_0x3a4d31,_0x15e8a9){var _0x5a4c59={'raw':!![],'where':{'id':_0x3a4d31['params']['id']}},_0x371d3b={};_0x371d3b[_0xf280('0x30')]=_[_0xf280('0x44')](db[_0xf280('0x2e')][_0xf280('0x2f')]);_0x371d3b['query']=_['keys'](_0x3a4d31[_0xf280('0x32')]);_0x371d3b[_0xf280('0x33')]=_[_0xf280('0x34')](_0x371d3b['model'],_0x371d3b[_0xf280('0x32')]);_0x5a4c59[_0xf280('0x45')]=_['intersection'](_0x371d3b[_0xf280('0x30')],qs[_0xf280('0x35')](_0x3a4d31[_0xf280('0x32')]['fields']));_0x5a4c59['attributes']=_0x5a4c59['attributes'][_0xf280('0x46')]?_0x5a4c59[_0xf280('0x45')]:_0x371d3b[_0xf280('0x30')];if(_0x3a4d31[_0xf280('0x32')][_0xf280('0x3f')]){_0x5a4c59[_0xf280('0x40')]=[{'all':!![]}];}_0x5a4c59=_[_0xf280('0x3d')]({},_0x5a4c59,_0x3a4d31[_0xf280('0x3e')]);return db[_0xf280('0x2e')][_0xf280('0x47')](_0x5a4c59)[_0xf280('0x27')](handleEntityNotFound(_0x15e8a9,null))[_0xf280('0x27')](respondWithResult(_0x15e8a9,null))[_0xf280('0x43')](handleError(_0x15e8a9,null));};exports[_0xf280('0x48')]=function(_0x212c7f,_0x17df68){return db[_0xf280('0x2e')][_0xf280('0x48')](_0x212c7f['body'],{})[_0xf280('0x27')](respondWithResult(_0x17df68,0xc9))[_0xf280('0x43')](handleError(_0x17df68,null));};exports[_0xf280('0x26')]=function(_0x7706e9,_0x3ad9fd){if(_0x7706e9[_0xf280('0x49')]['id']){delete _0x7706e9[_0xf280('0x49')]['id'];}return db[_0xf280('0x2e')][_0xf280('0x47')]({'where':{'id':_0x7706e9[_0xf280('0x4a')]['id']}})[_0xf280('0x27')](handleEntityNotFound(_0x3ad9fd,null))[_0xf280('0x27')](saveUpdates(_0x7706e9['body'],null))[_0xf280('0x27')](respondWithResult(_0x3ad9fd,null))[_0xf280('0x43')](handleError(_0x3ad9fd,null));};exports[_0xf280('0x28')]=function(_0x4174da,_0xbf05){return db[_0xf280('0x2e')][_0xf280('0x47')]({'where':{'id':_0x4174da[_0xf280('0x4a')]['id']}})[_0xf280('0x27')](handleEntityNotFound(_0xbf05,null))[_0xf280('0x27')](removeEntity(_0xbf05,null))[_0xf280('0x43')](handleError(_0xbf05,null));};