Built motion from commit e6806ed6.|2.6.0
[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 _0x7d59=['destroy','error','name','AnalyticTreeReport','fieldName','type','key','model','map','query','keys','filters','intersection','attributes','length','hasOwnProperty','nolimit','order','sort','where','filter','merge','options','includeAll','include','rows','catch','params','fields','find','create','body','rimraf','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','to-csv','ejs','lodash','squel','crypto','jsforce','desk.js','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','offset','undefined','limit','count','set','Content-Range','json','apply','reject','save','update','then'];(function(_0x15b380,_0x1a3c5f){var _0x232c5c=function(_0x12f8e0){while(--_0x12f8e0){_0x15b380['push'](_0x15b380['shift']());}};_0x232c5c(++_0x1a3c5f);}(_0x7d59,0xf2));var _0x97d5=function(_0x412c66,_0x1e5067){_0x412c66=_0x412c66-0x0;var _0x2df7cb=_0x7d59[_0x412c66];return _0x2df7cb;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x97d5('0x0'));var zipdir=require('zip-dir');var jsonpatch=require(_0x97d5('0x1'));var rp=require(_0x97d5('0x2'));var moment=require(_0x97d5('0x3'));var BPromise=require(_0x97d5('0x4'));var Mustache=require(_0x97d5('0x5'));var util=require(_0x97d5('0x6'));var path=require(_0x97d5('0x7'));var sox=require('sox');var csv=require(_0x97d5('0x8'));var ejs=require(_0x97d5('0x9'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0x97d5('0xa'));var squel=require(_0x97d5('0xb'));var crypto=require(_0x97d5('0xc'));var jsforce=require(_0x97d5('0xd'));var deskjs=require(_0x97d5('0xe'));var toCsv=require(_0x97d5('0x8'));var querystring=require('querystring');var Papa=require('papaparse');var Redis=require(_0x97d5('0xf'));var authService=require(_0x97d5('0x10'));var qs=require(_0x97d5('0x11'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x97d5('0x12'));var logger=require(_0x97d5('0x13'))('api');var utils=require('../../config/utils');var config=require(_0x97d5('0x14'));var licenseUtil=require(_0x97d5('0x15'));var db=require(_0x97d5('0x16'))['db'];function respondWithStatusCode(_0x5bd51e,_0x532f06){_0x532f06=_0x532f06||0xcc;return function(_0x13adba){if(_0x13adba){return _0x5bd51e[_0x97d5('0x17')](_0x532f06);}return _0x5bd51e[_0x97d5('0x18')](_0x532f06)[_0x97d5('0x19')]();};}function respondWithResult(_0x5bc84f,_0x37c784){_0x37c784=_0x37c784||0xc8;return function(_0x4c1d67){if(_0x4c1d67){return _0x5bc84f[_0x97d5('0x18')](_0x37c784)['json'](_0x4c1d67);}};}function respondWithFilteredResult(_0x1ec724,_0xd55bde){return function(_0x238c03){if(_0x238c03){var _0x319ba1=typeof _0xd55bde[_0x97d5('0x1a')]===_0x97d5('0x1b')&&typeof _0xd55bde[_0x97d5('0x1c')]===_0x97d5('0x1b');var _0xe633c7=_0x238c03[_0x97d5('0x1d')];var _0x221daa=_0x319ba1?0x0:_0xd55bde[_0x97d5('0x1a')];var _0x1b6434=_0x319ba1?_0x238c03[_0x97d5('0x1d')]:_0xd55bde['offset']+_0xd55bde['limit'];var _0x4e401d;if(_0x1b6434>=_0xe633c7){_0x1b6434=_0xe633c7;_0x4e401d=0xc8;}else{_0x4e401d=0xce;}_0x1ec724[_0x97d5('0x18')](_0x4e401d);return _0x1ec724[_0x97d5('0x1e')](_0x97d5('0x1f'),_0x221daa+'-'+_0x1b6434+'/'+_0xe633c7)[_0x97d5('0x20')](_0x238c03);}return null;};}function patchUpdates(_0x1f0714){return function(_0x2b056d){try{jsonpatch[_0x97d5('0x21')](_0x2b056d,_0x1f0714,!![]);}catch(_0x355e38){return BPromise[_0x97d5('0x22')](_0x355e38);}return _0x2b056d[_0x97d5('0x23')]();};}function saveUpdates(_0x4f2b59,_0x3504be){return function(_0x417f4d){if(_0x417f4d){return _0x417f4d[_0x97d5('0x24')](_0x4f2b59)[_0x97d5('0x25')](function(_0x48fc96){return _0x48fc96;});}return null;};}function removeEntity(_0xf6cf5b,_0x10eaca){return function(_0x480559){if(_0x480559){return _0x480559[_0x97d5('0x26')]()['then'](function(){_0xf6cf5b[_0x97d5('0x18')](0xcc)[_0x97d5('0x19')]();});}};}function handleEntityNotFound(_0x3d9fc2,_0x59196c){return function(_0x3108f1){if(!_0x3108f1){_0x3d9fc2['sendStatus'](0x194);}return _0x3108f1;};}function handleError(_0x4dea18,_0x310b9f){_0x310b9f=_0x310b9f||0x1f4;return function(_0x5c9a3b){logger[_0x97d5('0x27')](_0x5c9a3b['stack']);if(_0x5c9a3b[_0x97d5('0x28')]){delete _0x5c9a3b[_0x97d5('0x28')];}_0x4dea18[_0x97d5('0x18')](_0x310b9f)['send'](_0x5c9a3b);};}exports['index']=function(_0x33f613,_0x3c34e6){var _0x5473eb={},_0x2e33df={},_0x32eb78={'count':0x0,'rows':[]};var _0x2c9985=_['map'](db[_0x97d5('0x29')]['rawAttributes'],function(_0x31ae4d){return{'name':_0x31ae4d[_0x97d5('0x2a')],'type':_0x31ae4d[_0x97d5('0x2b')][_0x97d5('0x2c')]};});_0x2e33df[_0x97d5('0x2d')]=_[_0x97d5('0x2e')](_0x2c9985,'name');_0x2e33df[_0x97d5('0x2f')]=_[_0x97d5('0x30')](_0x33f613[_0x97d5('0x2f')]);_0x2e33df[_0x97d5('0x31')]=_[_0x97d5('0x32')](_0x2e33df['model'],_0x2e33df['query']);_0x5473eb[_0x97d5('0x33')]=_[_0x97d5('0x32')](_0x2e33df[_0x97d5('0x2d')],qs['fields'](_0x33f613[_0x97d5('0x2f')]['fields']));_0x5473eb[_0x97d5('0x33')]=_0x5473eb[_0x97d5('0x33')][_0x97d5('0x34')]?_0x5473eb[_0x97d5('0x33')]:_0x2e33df[_0x97d5('0x2d')];if(!_0x33f613[_0x97d5('0x2f')][_0x97d5('0x35')](_0x97d5('0x36'))){_0x5473eb[_0x97d5('0x1c')]=qs['limit'](_0x33f613['query']['limit']);_0x5473eb[_0x97d5('0x1a')]=qs['offset'](_0x33f613['query']['offset']);}_0x5473eb[_0x97d5('0x37')]=qs[_0x97d5('0x38')](_0x33f613[_0x97d5('0x2f')][_0x97d5('0x38')]);_0x5473eb[_0x97d5('0x39')]=qs['filters'](_['pick'](_0x33f613[_0x97d5('0x2f')],_0x2e33df[_0x97d5('0x31')]),_0x2c9985);if(_0x33f613[_0x97d5('0x2f')][_0x97d5('0x3a')]){_0x5473eb[_0x97d5('0x39')]=_['merge'](_0x5473eb['where'],{'$or':_['map'](_0x2c9985,function(_0x3181e6){if(_0x3181e6[_0x97d5('0x2b')]!=='VIRTUAL'){var _0x42d1ac={};_0x42d1ac[_0x3181e6[_0x97d5('0x28')]]={'$like':'%'+_0x33f613[_0x97d5('0x2f')]['filter']+'%'};return _0x42d1ac;}})});}_0x5473eb=_[_0x97d5('0x3b')]({},_0x5473eb,_0x33f613[_0x97d5('0x3c')]);var _0x1b28a2={'where':_0x5473eb[_0x97d5('0x39')]};return db[_0x97d5('0x29')][_0x97d5('0x1d')](_0x1b28a2)[_0x97d5('0x25')](function(_0x5dcc66){_0x32eb78[_0x97d5('0x1d')]=_0x5dcc66;if(_0x33f613['query'][_0x97d5('0x3d')]){_0x5473eb[_0x97d5('0x3e')]=[{'all':!![]}];}return db[_0x97d5('0x29')]['findAll'](_0x5473eb);})[_0x97d5('0x25')](function(_0x24d901){_0x32eb78[_0x97d5('0x3f')]=_0x24d901;return _0x32eb78;})[_0x97d5('0x25')](respondWithFilteredResult(_0x3c34e6,_0x5473eb))[_0x97d5('0x40')](handleError(_0x3c34e6,null));};exports['show']=function(_0x1a5356,_0x13c048){var _0x1ba423={'raw':!![],'where':{'id':_0x1a5356[_0x97d5('0x41')]['id']}},_0x3dc7c3={};_0x3dc7c3[_0x97d5('0x2d')]=_[_0x97d5('0x30')](db['AnalyticTreeReport']['rawAttributes']);_0x3dc7c3['query']=_['keys'](_0x1a5356[_0x97d5('0x2f')]);_0x3dc7c3[_0x97d5('0x31')]=_['intersection'](_0x3dc7c3[_0x97d5('0x2d')],_0x3dc7c3['query']);_0x1ba423['attributes']=_[_0x97d5('0x32')](_0x3dc7c3[_0x97d5('0x2d')],qs[_0x97d5('0x42')](_0x1a5356['query'][_0x97d5('0x42')]));_0x1ba423[_0x97d5('0x33')]=_0x1ba423['attributes'][_0x97d5('0x34')]?_0x1ba423[_0x97d5('0x33')]:_0x3dc7c3['model'];if(_0x1a5356[_0x97d5('0x2f')][_0x97d5('0x3d')]){_0x1ba423[_0x97d5('0x3e')]=[{'all':!![]}];}_0x1ba423=_[_0x97d5('0x3b')]({},_0x1ba423,_0x1a5356[_0x97d5('0x3c')]);return db[_0x97d5('0x29')][_0x97d5('0x43')](_0x1ba423)[_0x97d5('0x25')](handleEntityNotFound(_0x13c048,null))['then'](respondWithResult(_0x13c048,null))['catch'](handleError(_0x13c048,null));};exports[_0x97d5('0x44')]=function(_0x29066d,_0x3c33e8){return db['AnalyticTreeReport'][_0x97d5('0x44')](_0x29066d[_0x97d5('0x45')],{})['then'](respondWithResult(_0x3c33e8,0xc9))[_0x97d5('0x40')](handleError(_0x3c33e8,null));};exports[_0x97d5('0x24')]=function(_0x96ab83,_0x19056f){if(_0x96ab83[_0x97d5('0x45')]['id']){delete _0x96ab83[_0x97d5('0x45')]['id'];}return db[_0x97d5('0x29')][_0x97d5('0x43')]({'where':{'id':_0x96ab83['params']['id']}})[_0x97d5('0x25')](handleEntityNotFound(_0x19056f,null))[_0x97d5('0x25')](saveUpdates(_0x96ab83[_0x97d5('0x45')],null))[_0x97d5('0x25')](respondWithResult(_0x19056f,null))['catch'](handleError(_0x19056f,null));};exports[_0x97d5('0x26')]=function(_0x2dfcdb,_0xb76d84){return db['AnalyticTreeReport'][_0x97d5('0x43')]({'where':{'id':_0x2dfcdb['params']['id']}})['then'](handleEntityNotFound(_0xb76d84,null))['then'](removeEntity(_0xb76d84,null))['catch'](handleError(_0xb76d84,null));};