Built motion from commit c738b9ac.|2.6.25
[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 _0xcb8f=['body','find','eml-format','rimraf','request-promise','bluebird','util','sox','to-csv','ejs','fs-extra','lodash','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','offset','limit','undefined','count','set','Content-Range','reject','save','update','destroy','then','error','name','send','index','map','rawAttributes','fieldName','type','key','model','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','order','sort','where','pick','filter','VIRTUAL','merge','AnalyticTreeReport','include','findAll','rows','catch','show','params','includeAll','options','create'];(function(_0x17bdd7,_0xa97743){var _0x2404dc=function(_0xf6727b){while(--_0xf6727b){_0x17bdd7['push'](_0x17bdd7['shift']());}};_0x2404dc(++_0xa97743);}(_0xcb8f,0x136));var _0xfcb8=function(_0x2590f8,_0x5debfc){_0x2590f8=_0x2590f8-0x0;var _0x45685a=_0xcb8f[_0x2590f8];return _0x45685a;};'use strict';var emlformat=require(_0xfcb8('0x0'));var rimraf=require(_0xfcb8('0x1'));var zipdir=require('zip-dir');var jsonpatch=require('fast-json-patch');var rp=require(_0xfcb8('0x2'));var moment=require('moment');var BPromise=require(_0xfcb8('0x3'));var Mustache=require('mustache');var util=require(_0xfcb8('0x4'));var path=require('path');var sox=require(_0xfcb8('0x5'));var csv=require(_0xfcb8('0x6'));var ejs=require(_0xfcb8('0x7'));var fs=require('fs');var fs_extra=require(_0xfcb8('0x8'));var _=require(_0xfcb8('0x9'));var squel=require('squel');var crypto=require(_0xfcb8('0xa'));var jsforce=require(_0xfcb8('0xb'));var deskjs=require(_0xfcb8('0xc'));var toCsv=require(_0xfcb8('0x6'));var querystring=require(_0xfcb8('0xd'));var Papa=require(_0xfcb8('0xe'));var Redis=require(_0xfcb8('0xf'));var authService=require(_0xfcb8('0x10'));var qs=require(_0xfcb8('0x11'));var as=require(_0xfcb8('0x12'));var hardwareService=require('../../config/license/hardware');var logger=require(_0xfcb8('0x13'))(_0xfcb8('0x14'));var utils=require(_0xfcb8('0x15'));var config=require(_0xfcb8('0x16'));var licenseUtil=require(_0xfcb8('0x17'));var db=require(_0xfcb8('0x18'))['db'];function respondWithStatusCode(_0x26a8c4,_0x2edf89){_0x2edf89=_0x2edf89||0xcc;return function(_0x1a032b){if(_0x1a032b){return _0x26a8c4[_0xfcb8('0x19')](_0x2edf89);}return _0x26a8c4[_0xfcb8('0x1a')](_0x2edf89)[_0xfcb8('0x1b')]();};}function respondWithResult(_0x5f21ed,_0x158b44){_0x158b44=_0x158b44||0xc8;return function(_0x17cd21){if(_0x17cd21){return _0x5f21ed[_0xfcb8('0x1a')](_0x158b44)[_0xfcb8('0x1c')](_0x17cd21);}};}function respondWithFilteredResult(_0x4ff8f8,_0x2268d4){return function(_0x4f5067){if(_0x4f5067){var _0xd0f480=typeof _0x2268d4[_0xfcb8('0x1d')]==='undefined'&&typeof _0x2268d4[_0xfcb8('0x1e')]===_0xfcb8('0x1f');var _0x4a4317=_0x4f5067[_0xfcb8('0x20')];var _0xe2f03c=_0xd0f480?0x0:_0x2268d4[_0xfcb8('0x1d')];var _0x25ad4a=_0xd0f480?_0x4f5067[_0xfcb8('0x20')]:_0x2268d4[_0xfcb8('0x1d')]+_0x2268d4[_0xfcb8('0x1e')];var _0x5bd7b9;if(_0x25ad4a>=_0x4a4317){_0x25ad4a=_0x4a4317;_0x5bd7b9=0xc8;}else{_0x5bd7b9=0xce;}_0x4ff8f8[_0xfcb8('0x1a')](_0x5bd7b9);return _0x4ff8f8[_0xfcb8('0x21')](_0xfcb8('0x22'),_0xe2f03c+'-'+_0x25ad4a+'/'+_0x4a4317)['json'](_0x4f5067);}return null;};}function patchUpdates(_0x56d137){return function(_0x51b736){try{jsonpatch['apply'](_0x51b736,_0x56d137,!![]);}catch(_0x37dbea){return BPromise[_0xfcb8('0x23')](_0x37dbea);}return _0x51b736[_0xfcb8('0x24')]();};}function saveUpdates(_0x3a5e23,_0x242d65){return function(_0x3004a1){if(_0x3004a1){return _0x3004a1[_0xfcb8('0x25')](_0x3a5e23)['then'](function(_0x2d04fe){return _0x2d04fe;});}return null;};}function removeEntity(_0x5eb8ac,_0x909109){return function(_0x243d68){if(_0x243d68){return _0x243d68[_0xfcb8('0x26')]()[_0xfcb8('0x27')](function(){_0x5eb8ac[_0xfcb8('0x1a')](0xcc)[_0xfcb8('0x1b')]();});}};}function handleEntityNotFound(_0x500de3,_0x3e2da7){return function(_0x1615a7){if(!_0x1615a7){_0x500de3[_0xfcb8('0x19')](0x194);}return _0x1615a7;};}function handleError(_0x4a56d2,_0xe580d3){_0xe580d3=_0xe580d3||0x1f4;return function(_0x1d9cfe){logger[_0xfcb8('0x28')](_0x1d9cfe['stack']);if(_0x1d9cfe[_0xfcb8('0x29')]){delete _0x1d9cfe[_0xfcb8('0x29')];}_0x4a56d2[_0xfcb8('0x1a')](_0xe580d3)[_0xfcb8('0x2a')](_0x1d9cfe);};}exports[_0xfcb8('0x2b')]=function(_0x5688cf,_0x513739){var _0x258a14={},_0x38ecaf={},_0x279ed6={'count':0x0,'rows':[]};var _0x2c0210=_[_0xfcb8('0x2c')](db['AnalyticTreeReport'][_0xfcb8('0x2d')],function(_0xc33dbb){return{'name':_0xc33dbb[_0xfcb8('0x2e')],'type':_0xc33dbb[_0xfcb8('0x2f')][_0xfcb8('0x30')]};});_0x38ecaf[_0xfcb8('0x31')]=_[_0xfcb8('0x2c')](_0x2c0210,'name');_0x38ecaf[_0xfcb8('0x32')]=_[_0xfcb8('0x33')](_0x5688cf['query']);_0x38ecaf[_0xfcb8('0x34')]=_[_0xfcb8('0x35')](_0x38ecaf['model'],_0x38ecaf[_0xfcb8('0x32')]);_0x258a14[_0xfcb8('0x36')]=_[_0xfcb8('0x35')](_0x38ecaf[_0xfcb8('0x31')],qs[_0xfcb8('0x37')](_0x5688cf[_0xfcb8('0x32')][_0xfcb8('0x37')]));_0x258a14[_0xfcb8('0x36')]=_0x258a14[_0xfcb8('0x36')][_0xfcb8('0x38')]?_0x258a14['attributes']:_0x38ecaf['model'];if(!_0x5688cf[_0xfcb8('0x32')][_0xfcb8('0x39')]('nolimit')){_0x258a14[_0xfcb8('0x1e')]=qs[_0xfcb8('0x1e')](_0x5688cf[_0xfcb8('0x32')]['limit']);_0x258a14[_0xfcb8('0x1d')]=qs[_0xfcb8('0x1d')](_0x5688cf[_0xfcb8('0x32')][_0xfcb8('0x1d')]);}_0x258a14[_0xfcb8('0x3a')]=qs[_0xfcb8('0x3b')](_0x5688cf['query'][_0xfcb8('0x3b')]);_0x258a14[_0xfcb8('0x3c')]=qs['filters'](_[_0xfcb8('0x3d')](_0x5688cf[_0xfcb8('0x32')],_0x38ecaf[_0xfcb8('0x34')]),_0x2c0210);if(_0x5688cf['query'][_0xfcb8('0x3e')]){_0x258a14[_0xfcb8('0x3c')]=_['merge'](_0x258a14[_0xfcb8('0x3c')],{'$or':_[_0xfcb8('0x2c')](_0x2c0210,function(_0x2daa79){if(_0x2daa79['type']!==_0xfcb8('0x3f')){var _0x4f3b7a={};_0x4f3b7a[_0x2daa79[_0xfcb8('0x29')]]={'$like':'%'+_0x5688cf['query'][_0xfcb8('0x3e')]+'%'};return _0x4f3b7a;}})});}_0x258a14=_[_0xfcb8('0x40')]({},_0x258a14,_0x5688cf['options']);var _0x434eb9={'where':_0x258a14[_0xfcb8('0x3c')]};return db[_0xfcb8('0x41')]['count'](_0x434eb9)[_0xfcb8('0x27')](function(_0x4fa2b8){_0x279ed6[_0xfcb8('0x20')]=_0x4fa2b8;if(_0x5688cf['query']['includeAll']){_0x258a14[_0xfcb8('0x42')]=[{'all':!![]}];}return db[_0xfcb8('0x41')][_0xfcb8('0x43')](_0x258a14);})[_0xfcb8('0x27')](function(_0xb7c68a){_0x279ed6[_0xfcb8('0x44')]=_0xb7c68a;return _0x279ed6;})['then'](respondWithFilteredResult(_0x513739,_0x258a14))[_0xfcb8('0x45')](handleError(_0x513739,null));};exports[_0xfcb8('0x46')]=function(_0x3c7744,_0x79676){var _0x3bebdc={'raw':!![],'where':{'id':_0x3c7744[_0xfcb8('0x47')]['id']}},_0x333c22={};_0x333c22['model']=_[_0xfcb8('0x33')](db[_0xfcb8('0x41')]['rawAttributes']);_0x333c22['query']=_['keys'](_0x3c7744[_0xfcb8('0x32')]);_0x333c22[_0xfcb8('0x34')]=_['intersection'](_0x333c22[_0xfcb8('0x31')],_0x333c22[_0xfcb8('0x32')]);_0x3bebdc[_0xfcb8('0x36')]=_[_0xfcb8('0x35')](_0x333c22[_0xfcb8('0x31')],qs[_0xfcb8('0x37')](_0x3c7744['query']['fields']));_0x3bebdc[_0xfcb8('0x36')]=_0x3bebdc[_0xfcb8('0x36')][_0xfcb8('0x38')]?_0x3bebdc[_0xfcb8('0x36')]:_0x333c22[_0xfcb8('0x31')];if(_0x3c7744[_0xfcb8('0x32')][_0xfcb8('0x48')]){_0x3bebdc[_0xfcb8('0x42')]=[{'all':!![]}];}_0x3bebdc=_[_0xfcb8('0x40')]({},_0x3bebdc,_0x3c7744[_0xfcb8('0x49')]);return db[_0xfcb8('0x41')]['find'](_0x3bebdc)['then'](handleEntityNotFound(_0x79676,null))['then'](respondWithResult(_0x79676,null))[_0xfcb8('0x45')](handleError(_0x79676,null));};exports[_0xfcb8('0x4a')]=function(_0x3ca400,_0x397e61){return db[_0xfcb8('0x41')][_0xfcb8('0x4a')](_0x3ca400[_0xfcb8('0x4b')],{})[_0xfcb8('0x27')](respondWithResult(_0x397e61,0xc9))[_0xfcb8('0x45')](handleError(_0x397e61,null));};exports[_0xfcb8('0x25')]=function(_0x12f050,_0x2f6042){if(_0x12f050[_0xfcb8('0x4b')]['id']){delete _0x12f050['body']['id'];}return db[_0xfcb8('0x41')]['find']({'where':{'id':_0x12f050[_0xfcb8('0x47')]['id']}})['then'](handleEntityNotFound(_0x2f6042,null))[_0xfcb8('0x27')](saveUpdates(_0x12f050[_0xfcb8('0x4b')],null))[_0xfcb8('0x27')](respondWithResult(_0x2f6042,null))['catch'](handleError(_0x2f6042,null));};exports[_0xfcb8('0x26')]=function(_0x253716,_0xba2714){return db[_0xfcb8('0x41')][_0xfcb8('0x4c')]({'where':{'id':_0x253716[_0xfcb8('0x47')]['id']}})['then'](handleEntityNotFound(_0xba2714,null))[_0xfcb8('0x27')](removeEntity(_0xba2714,null))[_0xfcb8('0x45')](handleError(_0xba2714,null));};