Built motion from commit 980b26c3.|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 _0xccea=['AnalyticTreeReport','includeAll','include','findAll','rows','show','params','rawAttributes','length','find','catch','create','body','destroy','rimraf','zip-dir','fast-json-patch','request-promise','bluebird','mustache','util','path','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','querystring','papaparse','ioredis','../../components/auth/service','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','offset','undefined','count','limit','set','Content-Range','apply','reject','save','update','then','error','stack','name','send','index','fieldName','key','map','query','keys','model','attributes','intersection','fields','hasOwnProperty','nolimit','order','sort','where','filters','pick','filter','merge','type','VIRTUAL','options'];(function(_0x260e8f,_0x7561c5){var _0x3759ea=function(_0x19f5f7){while(--_0x19f5f7){_0x260e8f['push'](_0x260e8f['shift']());}};_0x3759ea(++_0x7561c5);}(_0xccea,0x101));var _0xacce=function(_0x14add3,_0x13ce8d){_0x14add3=_0x14add3-0x0;var _0x4a174f=_0xccea[_0x14add3];return _0x4a174f;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0xacce('0x0'));var zipdir=require(_0xacce('0x1'));var jsonpatch=require(_0xacce('0x2'));var rp=require(_0xacce('0x3'));var moment=require('moment');var BPromise=require(_0xacce('0x4'));var Mustache=require(_0xacce('0x5'));var util=require(_0xacce('0x6'));var path=require(_0xacce('0x7'));var sox=require(_0xacce('0x8'));var csv=require(_0xacce('0x9'));var ejs=require(_0xacce('0xa'));var fs=require('fs');var fs_extra=require(_0xacce('0xb'));var _=require(_0xacce('0xc'));var squel=require(_0xacce('0xd'));var crypto=require(_0xacce('0xe'));var jsforce=require(_0xacce('0xf'));var deskjs=require('desk.js');var toCsv=require(_0xacce('0x9'));var querystring=require(_0xacce('0x10'));var Papa=require(_0xacce('0x11'));var Redis=require(_0xacce('0x12'));var authService=require(_0xacce('0x13'));var qs=require('../../components/parsers/qs');var as=require('../../components/parsers/advancedSearch');var hardwareService=require('../../config/license/hardware');var logger=require(_0xacce('0x14'))(_0xacce('0x15'));var utils=require(_0xacce('0x16'));var config=require(_0xacce('0x17'));var licenseUtil=require(_0xacce('0x18'));var db=require(_0xacce('0x19'))['db'];function respondWithStatusCode(_0x22b879,_0x10bb49){_0x10bb49=_0x10bb49||0xcc;return function(_0x446b4b){if(_0x446b4b){return _0x22b879[_0xacce('0x1a')](_0x10bb49);}return _0x22b879[_0xacce('0x1b')](_0x10bb49)[_0xacce('0x1c')]();};}function respondWithResult(_0x4548a4,_0x3e1846){_0x3e1846=_0x3e1846||0xc8;return function(_0x356a53){if(_0x356a53){return _0x4548a4[_0xacce('0x1b')](_0x3e1846)[_0xacce('0x1d')](_0x356a53);}};}function respondWithFilteredResult(_0x3ef3ea,_0x371a39){return function(_0x556303){if(_0x556303){var _0x3637a0=typeof _0x371a39[_0xacce('0x1e')]===_0xacce('0x1f')&&typeof _0x371a39['limit']==='undefined';var _0x3b4ca0=_0x556303[_0xacce('0x20')];var _0x26bd4a=_0x3637a0?0x0:_0x371a39[_0xacce('0x1e')];var _0x569f4e=_0x3637a0?_0x556303[_0xacce('0x20')]:_0x371a39['offset']+_0x371a39[_0xacce('0x21')];var _0x5c730a;if(_0x569f4e>=_0x3b4ca0){_0x569f4e=_0x3b4ca0;_0x5c730a=0xc8;}else{_0x5c730a=0xce;}_0x3ef3ea['status'](_0x5c730a);return _0x3ef3ea[_0xacce('0x22')](_0xacce('0x23'),_0x26bd4a+'-'+_0x569f4e+'/'+_0x3b4ca0)[_0xacce('0x1d')](_0x556303);}return null;};}function patchUpdates(_0x453192){return function(_0x2d96c7){try{jsonpatch[_0xacce('0x24')](_0x2d96c7,_0x453192,!![]);}catch(_0x1de98b){return BPromise[_0xacce('0x25')](_0x1de98b);}return _0x2d96c7[_0xacce('0x26')]();};}function saveUpdates(_0x56e11a,_0xe20b9e){return function(_0x1c13af){if(_0x1c13af){return _0x1c13af[_0xacce('0x27')](_0x56e11a)['then'](function(_0x1bb9dd){return _0x1bb9dd;});}return null;};}function removeEntity(_0x5586da,_0x1ea8d2){return function(_0x2e684c){if(_0x2e684c){return _0x2e684c['destroy']()[_0xacce('0x28')](function(){_0x5586da[_0xacce('0x1b')](0xcc)[_0xacce('0x1c')]();});}};}function handleEntityNotFound(_0x180891,_0x422672){return function(_0x3dda28){if(!_0x3dda28){_0x180891[_0xacce('0x1a')](0x194);}return _0x3dda28;};}function handleError(_0x4f6092,_0x4dcc20){_0x4dcc20=_0x4dcc20||0x1f4;return function(_0x360a1c){logger[_0xacce('0x29')](_0x360a1c[_0xacce('0x2a')]);if(_0x360a1c[_0xacce('0x2b')]){delete _0x360a1c[_0xacce('0x2b')];}_0x4f6092['status'](_0x4dcc20)[_0xacce('0x2c')](_0x360a1c);};}exports[_0xacce('0x2d')]=function(_0x4b91eb,_0x42a20f){var _0x119e4c={},_0x175bb7={},_0x2f4e4c={'count':0x0,'rows':[]};var _0x506fbe=_['map'](db['AnalyticTreeReport']['rawAttributes'],function(_0x5dbba0){return{'name':_0x5dbba0[_0xacce('0x2e')],'type':_0x5dbba0['type'][_0xacce('0x2f')]};});_0x175bb7['model']=_[_0xacce('0x30')](_0x506fbe,_0xacce('0x2b'));_0x175bb7[_0xacce('0x31')]=_[_0xacce('0x32')](_0x4b91eb[_0xacce('0x31')]);_0x175bb7['filters']=_['intersection'](_0x175bb7[_0xacce('0x33')],_0x175bb7['query']);_0x119e4c[_0xacce('0x34')]=_[_0xacce('0x35')](_0x175bb7['model'],qs[_0xacce('0x36')](_0x4b91eb[_0xacce('0x31')][_0xacce('0x36')]));_0x119e4c['attributes']=_0x119e4c[_0xacce('0x34')]['length']?_0x119e4c[_0xacce('0x34')]:_0x175bb7[_0xacce('0x33')];if(!_0x4b91eb[_0xacce('0x31')][_0xacce('0x37')](_0xacce('0x38'))){_0x119e4c[_0xacce('0x21')]=qs['limit'](_0x4b91eb['query'][_0xacce('0x21')]);_0x119e4c['offset']=qs[_0xacce('0x1e')](_0x4b91eb[_0xacce('0x31')][_0xacce('0x1e')]);}_0x119e4c[_0xacce('0x39')]=qs[_0xacce('0x3a')](_0x4b91eb[_0xacce('0x31')]['sort']);_0x119e4c[_0xacce('0x3b')]=qs[_0xacce('0x3c')](_[_0xacce('0x3d')](_0x4b91eb['query'],_0x175bb7[_0xacce('0x3c')]),_0x506fbe);if(_0x4b91eb[_0xacce('0x31')][_0xacce('0x3e')]){_0x119e4c[_0xacce('0x3b')]=_[_0xacce('0x3f')](_0x119e4c[_0xacce('0x3b')],{'$or':_[_0xacce('0x30')](_0x506fbe,function(_0x3912fa){if(_0x3912fa[_0xacce('0x40')]!==_0xacce('0x41')){var _0x54be72={};_0x54be72[_0x3912fa[_0xacce('0x2b')]]={'$like':'%'+_0x4b91eb[_0xacce('0x31')][_0xacce('0x3e')]+'%'};return _0x54be72;}})});}_0x119e4c=_['merge']({},_0x119e4c,_0x4b91eb[_0xacce('0x42')]);var _0x386810={'where':_0x119e4c['where']};return db[_0xacce('0x43')][_0xacce('0x20')](_0x386810)[_0xacce('0x28')](function(_0x2656d3){_0x2f4e4c[_0xacce('0x20')]=_0x2656d3;if(_0x4b91eb[_0xacce('0x31')][_0xacce('0x44')]){_0x119e4c[_0xacce('0x45')]=[{'all':!![]}];}return db[_0xacce('0x43')][_0xacce('0x46')](_0x119e4c);})['then'](function(_0x2ff814){_0x2f4e4c[_0xacce('0x47')]=_0x2ff814;return _0x2f4e4c;})[_0xacce('0x28')](respondWithFilteredResult(_0x42a20f,_0x119e4c))['catch'](handleError(_0x42a20f,null));};exports[_0xacce('0x48')]=function(_0x3acd4b,_0x422ed2){var _0x853d75={'raw':!![],'where':{'id':_0x3acd4b[_0xacce('0x49')]['id']}},_0x4cc345={};_0x4cc345[_0xacce('0x33')]=_[_0xacce('0x32')](db[_0xacce('0x43')][_0xacce('0x4a')]);_0x4cc345['query']=_['keys'](_0x3acd4b['query']);_0x4cc345['filters']=_['intersection'](_0x4cc345[_0xacce('0x33')],_0x4cc345[_0xacce('0x31')]);_0x853d75[_0xacce('0x34')]=_[_0xacce('0x35')](_0x4cc345[_0xacce('0x33')],qs[_0xacce('0x36')](_0x3acd4b[_0xacce('0x31')]['fields']));_0x853d75[_0xacce('0x34')]=_0x853d75[_0xacce('0x34')][_0xacce('0x4b')]?_0x853d75[_0xacce('0x34')]:_0x4cc345[_0xacce('0x33')];if(_0x3acd4b[_0xacce('0x31')][_0xacce('0x44')]){_0x853d75['include']=[{'all':!![]}];}_0x853d75=_[_0xacce('0x3f')]({},_0x853d75,_0x3acd4b['options']);return db[_0xacce('0x43')][_0xacce('0x4c')](_0x853d75)['then'](handleEntityNotFound(_0x422ed2,null))[_0xacce('0x28')](respondWithResult(_0x422ed2,null))[_0xacce('0x4d')](handleError(_0x422ed2,null));};exports['create']=function(_0x1f9215,_0x5f1f6b){return db[_0xacce('0x43')][_0xacce('0x4e')](_0x1f9215[_0xacce('0x4f')],{})['then'](respondWithResult(_0x5f1f6b,0xc9))[_0xacce('0x4d')](handleError(_0x5f1f6b,null));};exports['update']=function(_0x3f91ba,_0xcc352){if(_0x3f91ba[_0xacce('0x4f')]['id']){delete _0x3f91ba[_0xacce('0x4f')]['id'];}return db[_0xacce('0x43')][_0xacce('0x4c')]({'where':{'id':_0x3f91ba['params']['id']}})[_0xacce('0x28')](handleEntityNotFound(_0xcc352,null))[_0xacce('0x28')](saveUpdates(_0x3f91ba[_0xacce('0x4f')],null))[_0xacce('0x28')](respondWithResult(_0xcc352,null))['catch'](handleError(_0xcc352,null));};exports[_0xacce('0x50')]=function(_0x5ef5c3,_0x5d8789){return db['AnalyticTreeReport']['find']({'where':{'id':_0x5ef5c3[_0xacce('0x49')]['id']}})['then'](handleEntityNotFound(_0x5d8789,null))[_0xacce('0x28')](removeEntity(_0x5d8789,null))['catch'](handleError(_0x5d8789,null));};