4afa59bd1d6da09ef2df2bd8edc0fa2327bed42e
[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 _0x398f=['body','eml-format','zip-dir','fast-json-patch','request-promise','bluebird','mustache','util','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','papaparse','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','../../config/utils','../../mysqldb','sendStatus','status','json','undefined','limit','count','offset','set','apply','reject','save','then','destroy','end','stack','name','send','index','map','AnalyticTreeReport','fieldName','type','key','model','query','keys','filters','intersection','fields','attributes','length','hasOwnProperty','nolimit','order','sort','where','filter','merge','VIRTUAL','includeAll','include','findAll','rows','catch','params','rawAttributes','options','find','create'];(function(_0x15fc3c,_0x35665b){var _0x94c5c8=function(_0xbab268){while(--_0xbab268){_0x15fc3c['push'](_0x15fc3c['shift']());}};_0x94c5c8(++_0x35665b);}(_0x398f,0x1bd));var _0xf398=function(_0x426e08,_0x3b7dbf){_0x426e08=_0x426e08-0x0;var _0x2688fe=_0x398f[_0x426e08];return _0x2688fe;};'use strict';var emlformat=require(_0xf398('0x0'));var rimraf=require('rimraf');var zipdir=require(_0xf398('0x1'));var jsonpatch=require(_0xf398('0x2'));var rp=require(_0xf398('0x3'));var moment=require('moment');var BPromise=require(_0xf398('0x4'));var Mustache=require(_0xf398('0x5'));var util=require(_0xf398('0x6'));var path=require('path');var sox=require(_0xf398('0x7'));var csv=require(_0xf398('0x8'));var ejs=require(_0xf398('0x9'));var fs=require('fs');var fs_extra=require(_0xf398('0xa'));var _=require(_0xf398('0xb'));var squel=require(_0xf398('0xc'));var crypto=require(_0xf398('0xd'));var jsforce=require(_0xf398('0xe'));var deskjs=require(_0xf398('0xf'));var toCsv=require(_0xf398('0x8'));var querystring=require('querystring');var Papa=require(_0xf398('0x10'));var Redis=require('ioredis');var authService=require(_0xf398('0x11'));var qs=require(_0xf398('0x12'));var as=require(_0xf398('0x13'));var hardwareService=require('../../config/license/hardware');var logger=require(_0xf398('0x14'))(_0xf398('0x15'));var utils=require(_0xf398('0x16'));var config=require('../../config/environment');var licenseUtil=require('../../config/license/util');var db=require(_0xf398('0x17'))['db'];function respondWithStatusCode(_0x191b48,_0x2ae63b){_0x2ae63b=_0x2ae63b||0xcc;return function(_0x130b8d){if(_0x130b8d){return _0x191b48[_0xf398('0x18')](_0x2ae63b);}return _0x191b48[_0xf398('0x19')](_0x2ae63b)['end']();};}function respondWithResult(_0xddddca,_0x31705f){_0x31705f=_0x31705f||0xc8;return function(_0x585ef6){if(_0x585ef6){return _0xddddca[_0xf398('0x19')](_0x31705f)[_0xf398('0x1a')](_0x585ef6);}};}function respondWithFilteredResult(_0x2c539f,_0x34a50c){return function(_0x45ce67){if(_0x45ce67){var _0x5b2236=typeof _0x34a50c['offset']===_0xf398('0x1b')&&typeof _0x34a50c[_0xf398('0x1c')]===_0xf398('0x1b');var _0x415a9c=_0x45ce67[_0xf398('0x1d')];var _0x3a37dd=_0x5b2236?0x0:_0x34a50c[_0xf398('0x1e')];var _0x41ae46=_0x5b2236?_0x45ce67[_0xf398('0x1d')]:_0x34a50c[_0xf398('0x1e')]+_0x34a50c[_0xf398('0x1c')];var _0x40a86a;if(_0x41ae46>=_0x415a9c){_0x41ae46=_0x415a9c;_0x40a86a=0xc8;}else{_0x40a86a=0xce;}_0x2c539f[_0xf398('0x19')](_0x40a86a);return _0x2c539f[_0xf398('0x1f')]('Content-Range',_0x3a37dd+'-'+_0x41ae46+'/'+_0x415a9c)[_0xf398('0x1a')](_0x45ce67);}return null;};}function patchUpdates(_0x335b56){return function(_0x475d76){try{jsonpatch[_0xf398('0x20')](_0x475d76,_0x335b56,!![]);}catch(_0x1edbe1){return BPromise[_0xf398('0x21')](_0x1edbe1);}return _0x475d76[_0xf398('0x22')]();};}function saveUpdates(_0x4e947c,_0xd23aa3){return function(_0x11a99d){if(_0x11a99d){return _0x11a99d['update'](_0x4e947c)[_0xf398('0x23')](function(_0x8954ea){return _0x8954ea;});}return null;};}function removeEntity(_0x101b85,_0x472030){return function(_0x347ee0){if(_0x347ee0){return _0x347ee0[_0xf398('0x24')]()['then'](function(){_0x101b85['status'](0xcc)[_0xf398('0x25')]();});}};}function handleEntityNotFound(_0x139294,_0xbace7d){return function(_0x3a3b81){if(!_0x3a3b81){_0x139294[_0xf398('0x18')](0x194);}return _0x3a3b81;};}function handleError(_0x1d0105,_0x544f82){_0x544f82=_0x544f82||0x1f4;return function(_0x462c7f){logger['error'](_0x462c7f[_0xf398('0x26')]);if(_0x462c7f[_0xf398('0x27')]){delete _0x462c7f[_0xf398('0x27')];}_0x1d0105[_0xf398('0x19')](_0x544f82)[_0xf398('0x28')](_0x462c7f);};}exports[_0xf398('0x29')]=function(_0x343cf0,_0x3933d1){var _0x33b1b8={},_0xb1cde6={},_0x2fe7cd={'count':0x0,'rows':[]};var _0x594a0f=_[_0xf398('0x2a')](db[_0xf398('0x2b')]['rawAttributes'],function(_0x1c50fd){return{'name':_0x1c50fd[_0xf398('0x2c')],'type':_0x1c50fd[_0xf398('0x2d')][_0xf398('0x2e')]};});_0xb1cde6[_0xf398('0x2f')]=_[_0xf398('0x2a')](_0x594a0f,_0xf398('0x27'));_0xb1cde6[_0xf398('0x30')]=_[_0xf398('0x31')](_0x343cf0[_0xf398('0x30')]);_0xb1cde6[_0xf398('0x32')]=_[_0xf398('0x33')](_0xb1cde6['model'],_0xb1cde6[_0xf398('0x30')]);_0x33b1b8['attributes']=_['intersection'](_0xb1cde6[_0xf398('0x2f')],qs[_0xf398('0x34')](_0x343cf0[_0xf398('0x30')]['fields']));_0x33b1b8[_0xf398('0x35')]=_0x33b1b8[_0xf398('0x35')][_0xf398('0x36')]?_0x33b1b8['attributes']:_0xb1cde6[_0xf398('0x2f')];if(!_0x343cf0[_0xf398('0x30')][_0xf398('0x37')](_0xf398('0x38'))){_0x33b1b8[_0xf398('0x1c')]=qs[_0xf398('0x1c')](_0x343cf0[_0xf398('0x30')][_0xf398('0x1c')]);_0x33b1b8[_0xf398('0x1e')]=qs[_0xf398('0x1e')](_0x343cf0[_0xf398('0x30')][_0xf398('0x1e')]);}_0x33b1b8[_0xf398('0x39')]=qs[_0xf398('0x3a')](_0x343cf0['query'][_0xf398('0x3a')]);_0x33b1b8[_0xf398('0x3b')]=qs[_0xf398('0x32')](_['pick'](_0x343cf0[_0xf398('0x30')],_0xb1cde6[_0xf398('0x32')]),_0x594a0f);if(_0x343cf0[_0xf398('0x30')][_0xf398('0x3c')]){_0x33b1b8[_0xf398('0x3b')]=_[_0xf398('0x3d')](_0x33b1b8['where'],{'$or':_[_0xf398('0x2a')](_0x594a0f,function(_0x3d079e){if(_0x3d079e[_0xf398('0x2d')]!==_0xf398('0x3e')){var _0x3eea4e={};_0x3eea4e[_0x3d079e[_0xf398('0x27')]]={'$like':'%'+_0x343cf0['query'][_0xf398('0x3c')]+'%'};return _0x3eea4e;}})});}_0x33b1b8=_[_0xf398('0x3d')]({},_0x33b1b8,_0x343cf0['options']);var _0x3b2b48={'where':_0x33b1b8[_0xf398('0x3b')]};return db[_0xf398('0x2b')][_0xf398('0x1d')](_0x3b2b48)['then'](function(_0x49dd0c){_0x2fe7cd[_0xf398('0x1d')]=_0x49dd0c;if(_0x343cf0[_0xf398('0x30')][_0xf398('0x3f')]){_0x33b1b8[_0xf398('0x40')]=[{'all':!![]}];}return db[_0xf398('0x2b')][_0xf398('0x41')](_0x33b1b8);})[_0xf398('0x23')](function(_0x372e26){_0x2fe7cd[_0xf398('0x42')]=_0x372e26;return _0x2fe7cd;})[_0xf398('0x23')](respondWithFilteredResult(_0x3933d1,_0x33b1b8))[_0xf398('0x43')](handleError(_0x3933d1,null));};exports['show']=function(_0x3065c1,_0x2a16db){var _0x8de5fc={'raw':!![],'where':{'id':_0x3065c1[_0xf398('0x44')]['id']}},_0x6ae1b2={};_0x6ae1b2['model']=_[_0xf398('0x31')](db[_0xf398('0x2b')][_0xf398('0x45')]);_0x6ae1b2['query']=_[_0xf398('0x31')](_0x3065c1['query']);_0x6ae1b2[_0xf398('0x32')]=_['intersection'](_0x6ae1b2[_0xf398('0x2f')],_0x6ae1b2['query']);_0x8de5fc[_0xf398('0x35')]=_[_0xf398('0x33')](_0x6ae1b2[_0xf398('0x2f')],qs[_0xf398('0x34')](_0x3065c1[_0xf398('0x30')][_0xf398('0x34')]));_0x8de5fc[_0xf398('0x35')]=_0x8de5fc[_0xf398('0x35')][_0xf398('0x36')]?_0x8de5fc[_0xf398('0x35')]:_0x6ae1b2['model'];if(_0x3065c1[_0xf398('0x30')][_0xf398('0x3f')]){_0x8de5fc[_0xf398('0x40')]=[{'all':!![]}];}_0x8de5fc=_[_0xf398('0x3d')]({},_0x8de5fc,_0x3065c1[_0xf398('0x46')]);return db[_0xf398('0x2b')][_0xf398('0x47')](_0x8de5fc)[_0xf398('0x23')](handleEntityNotFound(_0x2a16db,null))['then'](respondWithResult(_0x2a16db,null))[_0xf398('0x43')](handleError(_0x2a16db,null));};exports['create']=function(_0x5ae8aa,_0x3997d8){return db['AnalyticTreeReport'][_0xf398('0x48')](_0x5ae8aa[_0xf398('0x49')],{})[_0xf398('0x23')](respondWithResult(_0x3997d8,0xc9))[_0xf398('0x43')](handleError(_0x3997d8,null));};exports['update']=function(_0x412223,_0x41d449){if(_0x412223[_0xf398('0x49')]['id']){delete _0x412223[_0xf398('0x49')]['id'];}return db['AnalyticTreeReport'][_0xf398('0x47')]({'where':{'id':_0x412223[_0xf398('0x44')]['id']}})[_0xf398('0x23')](handleEntityNotFound(_0x41d449,null))[_0xf398('0x23')](saveUpdates(_0x412223[_0xf398('0x49')],null))['then'](respondWithResult(_0x41d449,null))[_0xf398('0x43')](handleError(_0x41d449,null));};exports['destroy']=function(_0x5de2bd,_0xb1f797){return db[_0xf398('0x2b')][_0xf398('0x47')]({'where':{'id':_0x5de2bd[_0xf398('0x44')]['id']}})[_0xf398('0x23')](handleEntityNotFound(_0xb1f797,null))[_0xf398('0x23')](removeEntity(_0xb1f797,null))[_0xf398('0x43')](handleError(_0xb1f797,null));};