Built motion from commit 43538d75.|2.5.35
[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 _0x7f58=['end','json','offset','undefined','limit','count','set','Content-Range','save','update','then','destroy','stack','name','send','index','map','AnalyticTreeReport','rawAttributes','fieldName','key','query','keys','filters','intersection','model','attributes','fields','length','nolimit','order','sort','where','merge','type','VIRTUAL','options','includeAll','findAll','rows','catch','show','params','include','find','create','body','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','mustache','path','to-csv','ejs','lodash','crypto','jsforce','desk.js','papaparse','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','../../config/environment','sendStatus','status'];(function(_0x29632c,_0x57fac4){var _0x2af7b3=function(_0x337512){while(--_0x337512){_0x29632c['push'](_0x29632c['shift']());}};_0x2af7b3(++_0x57fac4);}(_0x7f58,0x1d3));var _0x87f5=function(_0x5daeb2,_0x4b007c){_0x5daeb2=_0x5daeb2-0x0;var _0x2dbb9f=_0x7f58[_0x5daeb2];return _0x2dbb9f;};'use strict';var emlformat=require(_0x87f5('0x0'));var rimraf=require(_0x87f5('0x1'));var zipdir=require(_0x87f5('0x2'));var jsonpatch=require(_0x87f5('0x3'));var rp=require(_0x87f5('0x4'));var moment=require('moment');var BPromise=require('bluebird');var Mustache=require(_0x87f5('0x5'));var util=require('util');var path=require(_0x87f5('0x6'));var sox=require('sox');var csv=require(_0x87f5('0x7'));var ejs=require(_0x87f5('0x8'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0x87f5('0x9'));var squel=require('squel');var crypto=require(_0x87f5('0xa'));var jsforce=require(_0x87f5('0xb'));var deskjs=require(_0x87f5('0xc'));var toCsv=require(_0x87f5('0x7'));var querystring=require('querystring');var Papa=require(_0x87f5('0xd'));var Redis=require(_0x87f5('0xe'));var authService=require('../../components/auth/service');var qs=require(_0x87f5('0xf'));var as=require(_0x87f5('0x10'));var hardwareService=require(_0x87f5('0x11'));var logger=require('../../config/logger')(_0x87f5('0x12'));var utils=require(_0x87f5('0x13'));var config=require(_0x87f5('0x14'));var licenseUtil=require('../../config/license/util');var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x165f9c,_0x26634d){_0x26634d=_0x26634d||0xcc;return function(_0x2307a2){if(_0x2307a2){return _0x165f9c[_0x87f5('0x15')](_0x26634d);}return _0x165f9c[_0x87f5('0x16')](_0x26634d)[_0x87f5('0x17')]();};}function respondWithResult(_0x24c4f6,_0x3746a5){_0x3746a5=_0x3746a5||0xc8;return function(_0x56c660){if(_0x56c660){return _0x24c4f6['status'](_0x3746a5)[_0x87f5('0x18')](_0x56c660);}};}function respondWithFilteredResult(_0x3b03a1,_0x261db9){return function(_0x5f1822){if(_0x5f1822){var _0x2d53bd=typeof _0x261db9[_0x87f5('0x19')]===_0x87f5('0x1a')&&typeof _0x261db9[_0x87f5('0x1b')]==='undefined';var _0x51396b=_0x5f1822['count'];var _0x3151ad=_0x2d53bd?0x0:_0x261db9[_0x87f5('0x19')];var _0x519c6d=_0x2d53bd?_0x5f1822[_0x87f5('0x1c')]:_0x261db9[_0x87f5('0x19')]+_0x261db9[_0x87f5('0x1b')];var _0x3a6312;if(_0x519c6d>=_0x51396b){_0x519c6d=_0x51396b;_0x3a6312=0xc8;}else{_0x3a6312=0xce;}_0x3b03a1[_0x87f5('0x16')](_0x3a6312);return _0x3b03a1[_0x87f5('0x1d')](_0x87f5('0x1e'),_0x3151ad+'-'+_0x519c6d+'/'+_0x51396b)[_0x87f5('0x18')](_0x5f1822);}return null;};}function patchUpdates(_0x298a8b){return function(_0x221615){try{jsonpatch['apply'](_0x221615,_0x298a8b,!![]);}catch(_0x2a9489){return BPromise['reject'](_0x2a9489);}return _0x221615[_0x87f5('0x1f')]();};}function saveUpdates(_0x9a6b1e,_0x2f64f1){return function(_0x304661){if(_0x304661){return _0x304661[_0x87f5('0x20')](_0x9a6b1e)[_0x87f5('0x21')](function(_0x57ff86){return _0x57ff86;});}return null;};}function removeEntity(_0x58053c,_0x15e08c){return function(_0x2a8239){if(_0x2a8239){return _0x2a8239[_0x87f5('0x22')]()[_0x87f5('0x21')](function(){_0x58053c[_0x87f5('0x16')](0xcc)[_0x87f5('0x17')]();});}};}function handleEntityNotFound(_0x55194e,_0x59fdb8){return function(_0x543f35){if(!_0x543f35){_0x55194e['sendStatus'](0x194);}return _0x543f35;};}function handleError(_0x170d2c,_0x57e32b){_0x57e32b=_0x57e32b||0x1f4;return function(_0x575872){logger['error'](_0x575872[_0x87f5('0x23')]);if(_0x575872[_0x87f5('0x24')]){delete _0x575872[_0x87f5('0x24')];}_0x170d2c['status'](_0x57e32b)[_0x87f5('0x25')](_0x575872);};}exports[_0x87f5('0x26')]=function(_0x137117,_0x27c096){var _0x21ba1c={},_0x53608d={},_0x3416b4={'count':0x0,'rows':[]};var _0x22997f=_[_0x87f5('0x27')](db[_0x87f5('0x28')][_0x87f5('0x29')],function(_0x2e2509){return{'name':_0x2e2509[_0x87f5('0x2a')],'type':_0x2e2509['type'][_0x87f5('0x2b')]};});_0x53608d['model']=_[_0x87f5('0x27')](_0x22997f,_0x87f5('0x24'));_0x53608d[_0x87f5('0x2c')]=_[_0x87f5('0x2d')](_0x137117[_0x87f5('0x2c')]);_0x53608d[_0x87f5('0x2e')]=_[_0x87f5('0x2f')](_0x53608d[_0x87f5('0x30')],_0x53608d[_0x87f5('0x2c')]);_0x21ba1c[_0x87f5('0x31')]=_['intersection'](_0x53608d[_0x87f5('0x30')],qs[_0x87f5('0x32')](_0x137117[_0x87f5('0x2c')][_0x87f5('0x32')]));_0x21ba1c[_0x87f5('0x31')]=_0x21ba1c[_0x87f5('0x31')][_0x87f5('0x33')]?_0x21ba1c[_0x87f5('0x31')]:_0x53608d['model'];if(!_0x137117['query']['hasOwnProperty'](_0x87f5('0x34'))){_0x21ba1c[_0x87f5('0x1b')]=qs[_0x87f5('0x1b')](_0x137117[_0x87f5('0x2c')][_0x87f5('0x1b')]);_0x21ba1c['offset']=qs[_0x87f5('0x19')](_0x137117[_0x87f5('0x2c')]['offset']);}_0x21ba1c[_0x87f5('0x35')]=qs[_0x87f5('0x36')](_0x137117[_0x87f5('0x2c')][_0x87f5('0x36')]);_0x21ba1c['where']=qs['filters'](_['pick'](_0x137117[_0x87f5('0x2c')],_0x53608d[_0x87f5('0x2e')]),_0x22997f);if(_0x137117[_0x87f5('0x2c')]['filter']){_0x21ba1c[_0x87f5('0x37')]=_[_0x87f5('0x38')](_0x21ba1c['where'],{'$or':_[_0x87f5('0x27')](_0x22997f,function(_0x452006){if(_0x452006[_0x87f5('0x39')]!==_0x87f5('0x3a')){var _0x2b5e11={};_0x2b5e11[_0x452006[_0x87f5('0x24')]]={'$like':'%'+_0x137117[_0x87f5('0x2c')]['filter']+'%'};return _0x2b5e11;}})});}_0x21ba1c=_[_0x87f5('0x38')]({},_0x21ba1c,_0x137117[_0x87f5('0x3b')]);var _0x3801a6={'where':_0x21ba1c['where']};return db[_0x87f5('0x28')][_0x87f5('0x1c')](_0x3801a6)['then'](function(_0x4d9ebb){_0x3416b4[_0x87f5('0x1c')]=_0x4d9ebb;if(_0x137117[_0x87f5('0x2c')][_0x87f5('0x3c')]){_0x21ba1c['include']=[{'all':!![]}];}return db['AnalyticTreeReport'][_0x87f5('0x3d')](_0x21ba1c);})[_0x87f5('0x21')](function(_0x26e817){_0x3416b4[_0x87f5('0x3e')]=_0x26e817;return _0x3416b4;})[_0x87f5('0x21')](respondWithFilteredResult(_0x27c096,_0x21ba1c))[_0x87f5('0x3f')](handleError(_0x27c096,null));};exports[_0x87f5('0x40')]=function(_0x342cef,_0x4200d4){var _0x23e16b={'raw':!![],'where':{'id':_0x342cef[_0x87f5('0x41')]['id']}},_0x46d556={};_0x46d556[_0x87f5('0x30')]=_['keys'](db[_0x87f5('0x28')]['rawAttributes']);_0x46d556['query']=_[_0x87f5('0x2d')](_0x342cef[_0x87f5('0x2c')]);_0x46d556[_0x87f5('0x2e')]=_[_0x87f5('0x2f')](_0x46d556[_0x87f5('0x30')],_0x46d556[_0x87f5('0x2c')]);_0x23e16b[_0x87f5('0x31')]=_[_0x87f5('0x2f')](_0x46d556[_0x87f5('0x30')],qs[_0x87f5('0x32')](_0x342cef[_0x87f5('0x2c')][_0x87f5('0x32')]));_0x23e16b['attributes']=_0x23e16b[_0x87f5('0x31')][_0x87f5('0x33')]?_0x23e16b[_0x87f5('0x31')]:_0x46d556['model'];if(_0x342cef['query'][_0x87f5('0x3c')]){_0x23e16b[_0x87f5('0x42')]=[{'all':!![]}];}_0x23e16b=_[_0x87f5('0x38')]({},_0x23e16b,_0x342cef['options']);return db[_0x87f5('0x28')][_0x87f5('0x43')](_0x23e16b)[_0x87f5('0x21')](handleEntityNotFound(_0x4200d4,null))[_0x87f5('0x21')](respondWithResult(_0x4200d4,null))[_0x87f5('0x3f')](handleError(_0x4200d4,null));};exports[_0x87f5('0x44')]=function(_0x59788b,_0x534fac){return db[_0x87f5('0x28')]['create'](_0x59788b[_0x87f5('0x45')],{})[_0x87f5('0x21')](respondWithResult(_0x534fac,0xc9))[_0x87f5('0x3f')](handleError(_0x534fac,null));};exports[_0x87f5('0x20')]=function(_0x4eecf6,_0x4cb1f0){if(_0x4eecf6['body']['id']){delete _0x4eecf6[_0x87f5('0x45')]['id'];}return db['AnalyticTreeReport'][_0x87f5('0x43')]({'where':{'id':_0x4eecf6[_0x87f5('0x41')]['id']}})[_0x87f5('0x21')](handleEntityNotFound(_0x4cb1f0,null))[_0x87f5('0x21')](saveUpdates(_0x4eecf6[_0x87f5('0x45')],null))['then'](respondWithResult(_0x4cb1f0,null))[_0x87f5('0x3f')](handleError(_0x4cb1f0,null));};exports[_0x87f5('0x22')]=function(_0x455dd0,_0x30902f){return db[_0x87f5('0x28')][_0x87f5('0x43')]({'where':{'id':_0x455dd0['params']['id']}})[_0x87f5('0x21')](handleEntityNotFound(_0x30902f,null))[_0x87f5('0x21')](removeEntity(_0x30902f,null))[_0x87f5('0x3f')](handleError(_0x30902f,null));};