57c5a986aa8891bab91561cd773e5d06fe06a3bf
[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 _0x11f5=['send','index','map','rawAttributes','fieldName','type','key','query','filters','intersection','model','attributes','fields','length','hasOwnProperty','nolimit','sort','where','pick','filter','merge','options','AnalyticTreeReport','includeAll','rows','catch','params','keys','include','find','create','body','update','html-pdf','eml-format','rimraf','zip-dir','moment','bluebird','mustache','util','path','sox','ejs','lodash','squel','crypto','desk.js','to-csv','querystring','ioredis','../../components/auth/service','../../config/license/hardware','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','status','end','json','count','offset','limit','set','Content-Range','apply','reject','save','destroy','then','sendStatus','error','stack','name'];(function(_0x64a51,_0x1c61b7){var _0x1eba45=function(_0x230cf8){while(--_0x230cf8){_0x64a51['push'](_0x64a51['shift']());}};_0x1eba45(++_0x1c61b7);}(_0x11f5,0x6c));var _0x511f=function(_0x48a1f4,_0x3603f2){_0x48a1f4=_0x48a1f4-0x0;var _0x193fbb=_0x11f5[_0x48a1f4];return _0x193fbb;};'use strict';var pdf=require(_0x511f('0x0'));var emlformat=require(_0x511f('0x1'));var rimraf=require(_0x511f('0x2'));var zipdir=require(_0x511f('0x3'));var jsonpatch=require('fast-json-patch');var rp=require('request-promise');var moment=require(_0x511f('0x4'));var BPromise=require(_0x511f('0x5'));var Mustache=require(_0x511f('0x6'));var util=require(_0x511f('0x7'));var path=require(_0x511f('0x8'));var sox=require(_0x511f('0x9'));var csv=require('to-csv');var ejs=require(_0x511f('0xa'));var fs=require('fs');var _=require(_0x511f('0xb'));var squel=require(_0x511f('0xc'));var crypto=require(_0x511f('0xd'));var jsforce=require('jsforce');var deskjs=require(_0x511f('0xe'));var toCsv=require(_0x511f('0xf'));var querystring=require(_0x511f('0x10'));var Papa=require('papaparse');var Redis=require(_0x511f('0x11'));var authService=require(_0x511f('0x12'));var qs=require('../../components/parsers/qs');var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x511f('0x13'));var logger=require('../../config/logger')(_0x511f('0x14'));var utils=require(_0x511f('0x15'));var config=require(_0x511f('0x16'));var licenseUtil=require(_0x511f('0x17'));var db=require(_0x511f('0x18'))['db'];function respondWithStatusCode(_0x9c89a1,_0x29105b){_0x29105b=_0x29105b||0xcc;return function(_0x3a203){if(_0x3a203){return _0x9c89a1['sendStatus'](_0x29105b);}return _0x9c89a1[_0x511f('0x19')](_0x29105b)[_0x511f('0x1a')]();};}function respondWithResult(_0x509d2c,_0x232257){_0x232257=_0x232257||0xc8;return function(_0x158ffa){if(_0x158ffa){return _0x509d2c[_0x511f('0x19')](_0x232257)[_0x511f('0x1b')](_0x158ffa);}};}function respondWithFilteredResult(_0x62e66,_0x747c26){return function(_0x1eb52f){if(_0x1eb52f){var _0x16f493=_0x1eb52f[_0x511f('0x1c')],_0x1ac024=_0x747c26[_0x511f('0x1d')],_0x523a5=_0x747c26[_0x511f('0x1d')]+_0x747c26[_0x511f('0x1e')],_0x26aaf0;if(_0x523a5>=_0x16f493){_0x523a5=_0x16f493;_0x26aaf0=0xc8;}else{_0x26aaf0=0xce;}_0x62e66['status'](_0x26aaf0);return _0x62e66[_0x511f('0x1f')](_0x511f('0x20'),_0x1ac024+'-'+_0x523a5+'/'+_0x16f493)['json'](_0x1eb52f);}return null;};}function patchUpdates(_0x1ef7bb){return function(_0x546075){try{jsonpatch[_0x511f('0x21')](_0x546075,_0x1ef7bb,!![]);}catch(_0x5a533a){return BPromise[_0x511f('0x22')](_0x5a533a);}return _0x546075[_0x511f('0x23')]();};}function saveUpdates(_0x8f4949,_0x36d97f){return function(_0x1626df){if(_0x1626df){return _0x1626df['update'](_0x8f4949)['then'](function(_0x13d62b){return _0x13d62b;});}return null;};}function removeEntity(_0x14aae6,_0x440159){return function(_0x467357){if(_0x467357){return _0x467357[_0x511f('0x24')]()[_0x511f('0x25')](function(){_0x14aae6['status'](0xcc)[_0x511f('0x1a')]();});}};}function handleEntityNotFound(_0x3f7f8a,_0x340001){return function(_0x17b194){if(!_0x17b194){_0x3f7f8a[_0x511f('0x26')](0x194);}return _0x17b194;};}function handleError(_0x71207,_0x248ecf){_0x248ecf=_0x248ecf||0x1f4;return function(_0x4fb8f0){logger[_0x511f('0x27')](_0x4fb8f0[_0x511f('0x28')]);if(_0x4fb8f0[_0x511f('0x29')]){delete _0x4fb8f0['name'];}_0x71207[_0x511f('0x19')](_0x248ecf)[_0x511f('0x2a')](_0x4fb8f0);};}exports[_0x511f('0x2b')]=function(_0x563a32,_0x4ea710){var _0x369b88={},_0x73bf4e={},_0x2f40ac={'count':0x0,'rows':[]};var _0xb28e54=_[_0x511f('0x2c')](db['AnalyticTreeReport'][_0x511f('0x2d')],function(_0x4c5887){return{'name':_0x4c5887[_0x511f('0x2e')],'type':_0x4c5887[_0x511f('0x2f')][_0x511f('0x30')]};});_0x73bf4e['model']=_[_0x511f('0x2c')](_0xb28e54,_0x511f('0x29'));_0x73bf4e['query']=_['keys'](_0x563a32[_0x511f('0x31')]);_0x73bf4e[_0x511f('0x32')]=_[_0x511f('0x33')](_0x73bf4e[_0x511f('0x34')],_0x73bf4e[_0x511f('0x31')]);_0x369b88[_0x511f('0x35')]=_[_0x511f('0x33')](_0x73bf4e[_0x511f('0x34')],qs[_0x511f('0x36')](_0x563a32['query'][_0x511f('0x36')]));_0x369b88[_0x511f('0x35')]=_0x369b88[_0x511f('0x35')][_0x511f('0x37')]?_0x369b88['attributes']:_0x73bf4e['model'];if(!_0x563a32['query'][_0x511f('0x38')](_0x511f('0x39'))){_0x369b88[_0x511f('0x1e')]=qs[_0x511f('0x1e')](_0x563a32[_0x511f('0x31')][_0x511f('0x1e')]);_0x369b88[_0x511f('0x1d')]=qs['offset'](_0x563a32['query'][_0x511f('0x1d')]);}_0x369b88['order']=qs['sort'](_0x563a32[_0x511f('0x31')][_0x511f('0x3a')]);_0x369b88[_0x511f('0x3b')]=qs[_0x511f('0x32')](_[_0x511f('0x3c')](_0x563a32[_0x511f('0x31')],_0x73bf4e[_0x511f('0x32')]),_0xb28e54);if(_0x563a32[_0x511f('0x31')][_0x511f('0x3d')]){_0x369b88[_0x511f('0x3b')]=_[_0x511f('0x3e')](_0x369b88[_0x511f('0x3b')],{'$or':_[_0x511f('0x2c')](_0xb28e54,function(_0x4a515d){if(_0x4a515d['type']!=='VIRTUAL'){var _0x46b4b3={};_0x46b4b3[_0x4a515d['name']]={'$like':'%'+_0x563a32[_0x511f('0x31')][_0x511f('0x3d')]+'%'};return _0x46b4b3;}})});}_0x369b88=_[_0x511f('0x3e')]({},_0x369b88,_0x563a32[_0x511f('0x3f')]);var _0x3a9ae6={'where':_0x369b88[_0x511f('0x3b')]};return db[_0x511f('0x40')][_0x511f('0x1c')](_0x3a9ae6)[_0x511f('0x25')](function(_0x9f758f){_0x2f40ac[_0x511f('0x1c')]=_0x9f758f;if(_0x563a32[_0x511f('0x31')][_0x511f('0x41')]){_0x369b88['include']=[{'all':!![]}];}return db[_0x511f('0x40')]['findAll'](_0x369b88);})['then'](function(_0x16ed25){_0x2f40ac[_0x511f('0x42')]=_0x16ed25;return _0x2f40ac;})[_0x511f('0x25')](respondWithFilteredResult(_0x4ea710,_0x369b88))[_0x511f('0x43')](handleError(_0x4ea710,null));};exports['show']=function(_0x9799e4,_0x1dad27){var _0x26e51f={'raw':!![],'where':{'id':_0x9799e4[_0x511f('0x44')]['id']}},_0x8fd432={};_0x8fd432[_0x511f('0x34')]=_[_0x511f('0x45')](db[_0x511f('0x40')][_0x511f('0x2d')]);_0x8fd432[_0x511f('0x31')]=_[_0x511f('0x45')](_0x9799e4[_0x511f('0x31')]);_0x8fd432[_0x511f('0x32')]=_[_0x511f('0x33')](_0x8fd432[_0x511f('0x34')],_0x8fd432['query']);_0x26e51f[_0x511f('0x35')]=_[_0x511f('0x33')](_0x8fd432[_0x511f('0x34')],qs[_0x511f('0x36')](_0x9799e4[_0x511f('0x31')][_0x511f('0x36')]));_0x26e51f['attributes']=_0x26e51f[_0x511f('0x35')][_0x511f('0x37')]?_0x26e51f['attributes']:_0x8fd432['model'];if(_0x9799e4[_0x511f('0x31')][_0x511f('0x41')]){_0x26e51f[_0x511f('0x46')]=[{'all':!![]}];}_0x26e51f=_[_0x511f('0x3e')]({},_0x26e51f,_0x9799e4[_0x511f('0x3f')]);return db[_0x511f('0x40')][_0x511f('0x47')](_0x26e51f)[_0x511f('0x25')](handleEntityNotFound(_0x1dad27,null))[_0x511f('0x25')](respondWithResult(_0x1dad27,null))[_0x511f('0x43')](handleError(_0x1dad27,null));};exports[_0x511f('0x48')]=function(_0x57ed28,_0x2785df){return db['AnalyticTreeReport'][_0x511f('0x48')](_0x57ed28[_0x511f('0x49')],{})[_0x511f('0x25')](respondWithResult(_0x2785df,0xc9))['catch'](handleError(_0x2785df,null));};exports[_0x511f('0x4a')]=function(_0x2c40e5,_0x548f88){if(_0x2c40e5['body']['id']){delete _0x2c40e5['body']['id'];}return db[_0x511f('0x40')][_0x511f('0x47')]({'where':{'id':_0x2c40e5['params']['id']}})[_0x511f('0x25')](handleEntityNotFound(_0x548f88,null))['then'](saveUpdates(_0x2c40e5[_0x511f('0x49')],null))[_0x511f('0x25')](respondWithResult(_0x548f88,null))['catch'](handleError(_0x548f88,null));};exports[_0x511f('0x24')]=function(_0x42e909,_0x4e1e20){return db[_0x511f('0x40')][_0x511f('0x47')]({'where':{'id':_0x42e909[_0x511f('0x44')]['id']}})[_0x511f('0x25')](handleEntityNotFound(_0x4e1e20,null))[_0x511f('0x25')](removeEntity(_0x4e1e20,null))[_0x511f('0x43')](handleError(_0x4e1e20,null));};