Built motion from commit 52c8a02d.|2.6.29
[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 _0xc68b=['sort','where','merge','type','filter','options','AnalyticTreeReport','findAll','rows','catch','show','rawAttributes','includeAll','include','find','create','body','params','rimraf','fast-json-patch','moment','bluebird','mustache','util','path','sox','to-csv','ejs','fs-extra','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/environment','sendStatus','status','end','json','undefined','limit','count','offset','set','Content-Range','apply','save','update','then','destroy','error','stack','name','send','map','fieldName','key','query','keys','filters','intersection','model','attributes','fields','length','hasOwnProperty','order'];(function(_0x12e015,_0x480c3e){var _0x47fc1e=function(_0x3a2186){while(--_0x3a2186){_0x12e015['push'](_0x12e015['shift']());}};_0x47fc1e(++_0x480c3e);}(_0xc68b,0x1c8));var _0xbc68=function(_0x1a390c,_0x6d3e27){_0x1a390c=_0x1a390c-0x0;var _0x4aa513=_0xc68b[_0x1a390c];return _0x4aa513;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0xbc68('0x0'));var zipdir=require('zip-dir');var jsonpatch=require(_0xbc68('0x1'));var rp=require('request-promise');var moment=require(_0xbc68('0x2'));var BPromise=require(_0xbc68('0x3'));var Mustache=require(_0xbc68('0x4'));var util=require(_0xbc68('0x5'));var path=require(_0xbc68('0x6'));var sox=require(_0xbc68('0x7'));var csv=require(_0xbc68('0x8'));var ejs=require(_0xbc68('0x9'));var fs=require('fs');var fs_extra=require(_0xbc68('0xa'));var _=require('lodash');var squel=require(_0xbc68('0xb'));var crypto=require(_0xbc68('0xc'));var jsforce=require(_0xbc68('0xd'));var deskjs=require(_0xbc68('0xe'));var toCsv=require('to-csv');var querystring=require(_0xbc68('0xf'));var Papa=require(_0xbc68('0x10'));var Redis=require(_0xbc68('0x11'));var authService=require('../../components/auth/service');var qs=require(_0xbc68('0x12'));var as=require(_0xbc68('0x13'));var hardwareService=require(_0xbc68('0x14'));var logger=require(_0xbc68('0x15'))('api');var utils=require('../../config/utils');var config=require(_0xbc68('0x16'));var licenseUtil=require('../../config/license/util');var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x5105ed,_0x4b216b){_0x4b216b=_0x4b216b||0xcc;return function(_0x574fbb){if(_0x574fbb){return _0x5105ed[_0xbc68('0x17')](_0x4b216b);}return _0x5105ed[_0xbc68('0x18')](_0x4b216b)[_0xbc68('0x19')]();};}function respondWithResult(_0x4325ae,_0x59505b){_0x59505b=_0x59505b||0xc8;return function(_0x1d989b){if(_0x1d989b){return _0x4325ae[_0xbc68('0x18')](_0x59505b)[_0xbc68('0x1a')](_0x1d989b);}};}function respondWithFilteredResult(_0x25b825,_0x59c5cb){return function(_0x163daf){if(_0x163daf){var _0x333802=typeof _0x59c5cb['offset']===_0xbc68('0x1b')&&typeof _0x59c5cb[_0xbc68('0x1c')]==='undefined';var _0x1f1335=_0x163daf[_0xbc68('0x1d')];var _0x32764b=_0x333802?0x0:_0x59c5cb[_0xbc68('0x1e')];var _0x20bf26=_0x333802?_0x163daf['count']:_0x59c5cb[_0xbc68('0x1e')]+_0x59c5cb[_0xbc68('0x1c')];var _0xfb16eb;if(_0x20bf26>=_0x1f1335){_0x20bf26=_0x1f1335;_0xfb16eb=0xc8;}else{_0xfb16eb=0xce;}_0x25b825[_0xbc68('0x18')](_0xfb16eb);return _0x25b825[_0xbc68('0x1f')](_0xbc68('0x20'),_0x32764b+'-'+_0x20bf26+'/'+_0x1f1335)[_0xbc68('0x1a')](_0x163daf);}return null;};}function patchUpdates(_0x302ddc){return function(_0x19f2ff){try{jsonpatch[_0xbc68('0x21')](_0x19f2ff,_0x302ddc,!![]);}catch(_0x455106){return BPromise['reject'](_0x455106);}return _0x19f2ff[_0xbc68('0x22')]();};}function saveUpdates(_0x592371,_0x2f68af){return function(_0xd2757f){if(_0xd2757f){return _0xd2757f[_0xbc68('0x23')](_0x592371)[_0xbc68('0x24')](function(_0x4f94cf){return _0x4f94cf;});}return null;};}function removeEntity(_0x101926,_0x54c5fc){return function(_0x4f9924){if(_0x4f9924){return _0x4f9924[_0xbc68('0x25')]()[_0xbc68('0x24')](function(){_0x101926['status'](0xcc)['end']();});}};}function handleEntityNotFound(_0x45ed6f,_0x5b11e7){return function(_0x914a14){if(!_0x914a14){_0x45ed6f['sendStatus'](0x194);}return _0x914a14;};}function handleError(_0x35db49,_0x3972ce){_0x3972ce=_0x3972ce||0x1f4;return function(_0x417caa){logger[_0xbc68('0x26')](_0x417caa[_0xbc68('0x27')]);if(_0x417caa[_0xbc68('0x28')]){delete _0x417caa[_0xbc68('0x28')];}_0x35db49['status'](_0x3972ce)[_0xbc68('0x29')](_0x417caa);};}exports['index']=function(_0x4451a3,_0x589634){var _0x1bc7d1={},_0x2c8a4e={},_0x1c3333={'count':0x0,'rows':[]};var _0x58c0fd=_[_0xbc68('0x2a')](db['AnalyticTreeReport']['rawAttributes'],function(_0x1a4ceb){return{'name':_0x1a4ceb[_0xbc68('0x2b')],'type':_0x1a4ceb['type'][_0xbc68('0x2c')]};});_0x2c8a4e['model']=_[_0xbc68('0x2a')](_0x58c0fd,_0xbc68('0x28'));_0x2c8a4e[_0xbc68('0x2d')]=_[_0xbc68('0x2e')](_0x4451a3['query']);_0x2c8a4e[_0xbc68('0x2f')]=_[_0xbc68('0x30')](_0x2c8a4e[_0xbc68('0x31')],_0x2c8a4e[_0xbc68('0x2d')]);_0x1bc7d1[_0xbc68('0x32')]=_[_0xbc68('0x30')](_0x2c8a4e[_0xbc68('0x31')],qs[_0xbc68('0x33')](_0x4451a3['query'][_0xbc68('0x33')]));_0x1bc7d1['attributes']=_0x1bc7d1[_0xbc68('0x32')][_0xbc68('0x34')]?_0x1bc7d1[_0xbc68('0x32')]:_0x2c8a4e[_0xbc68('0x31')];if(!_0x4451a3['query'][_0xbc68('0x35')]('nolimit')){_0x1bc7d1[_0xbc68('0x1c')]=qs['limit'](_0x4451a3[_0xbc68('0x2d')][_0xbc68('0x1c')]);_0x1bc7d1[_0xbc68('0x1e')]=qs[_0xbc68('0x1e')](_0x4451a3[_0xbc68('0x2d')][_0xbc68('0x1e')]);}_0x1bc7d1[_0xbc68('0x36')]=qs[_0xbc68('0x37')](_0x4451a3[_0xbc68('0x2d')][_0xbc68('0x37')]);_0x1bc7d1[_0xbc68('0x38')]=qs[_0xbc68('0x2f')](_['pick'](_0x4451a3[_0xbc68('0x2d')],_0x2c8a4e[_0xbc68('0x2f')]),_0x58c0fd);if(_0x4451a3[_0xbc68('0x2d')]['filter']){_0x1bc7d1['where']=_[_0xbc68('0x39')](_0x1bc7d1[_0xbc68('0x38')],{'$or':_[_0xbc68('0x2a')](_0x58c0fd,function(_0x3625e9){if(_0x3625e9[_0xbc68('0x3a')]!=='VIRTUAL'){var _0x44f7f8={};_0x44f7f8[_0x3625e9['name']]={'$like':'%'+_0x4451a3[_0xbc68('0x2d')][_0xbc68('0x3b')]+'%'};return _0x44f7f8;}})});}_0x1bc7d1=_['merge']({},_0x1bc7d1,_0x4451a3[_0xbc68('0x3c')]);var _0x19ef09={'where':_0x1bc7d1[_0xbc68('0x38')]};return db[_0xbc68('0x3d')]['count'](_0x19ef09)[_0xbc68('0x24')](function(_0x227274){_0x1c3333[_0xbc68('0x1d')]=_0x227274;if(_0x4451a3[_0xbc68('0x2d')]['includeAll']){_0x1bc7d1['include']=[{'all':!![]}];}return db[_0xbc68('0x3d')][_0xbc68('0x3e')](_0x1bc7d1);})[_0xbc68('0x24')](function(_0x37ee07){_0x1c3333[_0xbc68('0x3f')]=_0x37ee07;return _0x1c3333;})['then'](respondWithFilteredResult(_0x589634,_0x1bc7d1))[_0xbc68('0x40')](handleError(_0x589634,null));};exports[_0xbc68('0x41')]=function(_0xd7deb4,_0x19096b){var _0x4acb33={'raw':!![],'where':{'id':_0xd7deb4['params']['id']}},_0x6baf36={};_0x6baf36['model']=_[_0xbc68('0x2e')](db[_0xbc68('0x3d')][_0xbc68('0x42')]);_0x6baf36[_0xbc68('0x2d')]=_['keys'](_0xd7deb4['query']);_0x6baf36[_0xbc68('0x2f')]=_[_0xbc68('0x30')](_0x6baf36[_0xbc68('0x31')],_0x6baf36[_0xbc68('0x2d')]);_0x4acb33[_0xbc68('0x32')]=_[_0xbc68('0x30')](_0x6baf36[_0xbc68('0x31')],qs[_0xbc68('0x33')](_0xd7deb4[_0xbc68('0x2d')][_0xbc68('0x33')]));_0x4acb33[_0xbc68('0x32')]=_0x4acb33[_0xbc68('0x32')]['length']?_0x4acb33[_0xbc68('0x32')]:_0x6baf36[_0xbc68('0x31')];if(_0xd7deb4[_0xbc68('0x2d')][_0xbc68('0x43')]){_0x4acb33[_0xbc68('0x44')]=[{'all':!![]}];}_0x4acb33=_[_0xbc68('0x39')]({},_0x4acb33,_0xd7deb4['options']);return db[_0xbc68('0x3d')][_0xbc68('0x45')](_0x4acb33)[_0xbc68('0x24')](handleEntityNotFound(_0x19096b,null))[_0xbc68('0x24')](respondWithResult(_0x19096b,null))[_0xbc68('0x40')](handleError(_0x19096b,null));};exports[_0xbc68('0x46')]=function(_0x218321,_0x624f94){return db[_0xbc68('0x3d')][_0xbc68('0x46')](_0x218321[_0xbc68('0x47')],{})[_0xbc68('0x24')](respondWithResult(_0x624f94,0xc9))[_0xbc68('0x40')](handleError(_0x624f94,null));};exports[_0xbc68('0x23')]=function(_0x492652,_0x46c745){if(_0x492652[_0xbc68('0x47')]['id']){delete _0x492652[_0xbc68('0x47')]['id'];}return db[_0xbc68('0x3d')]['find']({'where':{'id':_0x492652[_0xbc68('0x48')]['id']}})[_0xbc68('0x24')](handleEntityNotFound(_0x46c745,null))['then'](saveUpdates(_0x492652[_0xbc68('0x47')],null))[_0xbc68('0x24')](respondWithResult(_0x46c745,null))[_0xbc68('0x40')](handleError(_0x46c745,null));};exports[_0xbc68('0x25')]=function(_0x333beb,_0x36c096){return db['AnalyticTreeReport'][_0xbc68('0x45')]({'where':{'id':_0x333beb[_0xbc68('0x48')]['id']}})['then'](handleEntityNotFound(_0x36c096,null))[_0xbc68('0x24')](removeEntity(_0x36c096,null))[_0xbc68('0x40')](handleError(_0x36c096,null));};