Built motion from commit c738b9ac.|2.6.25
[motion2.git] / server / api / dashboardItem / dashboardItem.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 _0x2eb2=['0.00','attrFontSize','counter','attrMetric','attrVoiceQueues','attrChannel','voice','attrEmailAccounts','attrFaxAccounts','attrSmsAccounts','attrOpenchannelAccounts','attrWhatsappAccounts','attrChatWebsites','pie-chart','attrSerie1','total','attrSerie2','attrSerie3','web-report','attrReport','reportType','attrRefresh','widgetAttributes:\x20%s','stringify','create','body','catch','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','util','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/parsers/qs','../../config/logger','../../config/utils','../../config/environment','redis','defaults','localhost','socket.io-emitter','./dashboardItem.socket','sendStatus','json','offset','undefined','limit','count','Content-Range','apply','reject','update','then','status','error','stack','name','send','show','params','keys','rawAttributes','query','filters','intersection','model','attributes','length','includeAll','include','merge','options','DashboardItem','destroy','find','type','attrUrl','attrs','custom','attrPath','clock','attrHourFormat','HH:mm:ss','attrTimezone','value'];(function(_0x1159cc,_0x567178){var _0x210403=function(_0x27c347){while(--_0x27c347){_0x1159cc['push'](_0x1159cc['shift']());}};_0x210403(++_0x567178);}(_0x2eb2,0x19f));var _0x22eb=function(_0x42245d,_0x51758f){_0x42245d=_0x42245d-0x0;var _0x4b211a=_0x2eb2[_0x42245d];return _0x4b211a;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x22eb('0x0'));var zipdir=require(_0x22eb('0x1'));var jsonpatch=require(_0x22eb('0x2'));var rp=require(_0x22eb('0x3'));var moment=require(_0x22eb('0x4'));var BPromise=require(_0x22eb('0x5'));var Mustache=require('mustache');var util=require(_0x22eb('0x6'));var path=require('path');var sox=require('sox');var csv=require(_0x22eb('0x7'));var ejs=require(_0x22eb('0x8'));var fs=require('fs');var fs_extra=require(_0x22eb('0x9'));var _=require(_0x22eb('0xa'));var squel=require(_0x22eb('0xb'));var crypto=require(_0x22eb('0xc'));var jsforce=require(_0x22eb('0xd'));var deskjs=require(_0x22eb('0xe'));var toCsv=require(_0x22eb('0x7'));var querystring=require(_0x22eb('0xf'));var Papa=require(_0x22eb('0x10'));var Redis=require(_0x22eb('0x11'));var authService=require('../../components/auth/service');var qs=require(_0x22eb('0x12'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require('../../config/license/hardware');var logger=require(_0x22eb('0x13'))('api');var utils=require(_0x22eb('0x14'));var config=require(_0x22eb('0x15'));var licenseUtil=require('../../config/license/util');var db=require('../../mysqldb')['db'];config[_0x22eb('0x16')]=_[_0x22eb('0x17')](config[_0x22eb('0x16')],{'host':_0x22eb('0x18'),'port':0x18eb});var socket=require(_0x22eb('0x19'))(new Redis(config['redis']));require(_0x22eb('0x1a'))['register'](socket);function respondWithStatusCode(_0x1f5089,_0x55ede8){_0x55ede8=_0x55ede8||0xcc;return function(_0x40c8cb){if(_0x40c8cb){return _0x1f5089[_0x22eb('0x1b')](_0x55ede8);}return _0x1f5089['status'](_0x55ede8)['end']();};}function respondWithResult(_0x4bc29a,_0x2ed8a7){_0x2ed8a7=_0x2ed8a7||0xc8;return function(_0x5245fe){if(_0x5245fe){return _0x4bc29a['status'](_0x2ed8a7)[_0x22eb('0x1c')](_0x5245fe);}};}function respondWithFilteredResult(_0x4d9a71,_0x4d9b09){return function(_0xb7a73a){if(_0xb7a73a){var _0x2a55e4=typeof _0x4d9b09[_0x22eb('0x1d')]===_0x22eb('0x1e')&&typeof _0x4d9b09[_0x22eb('0x1f')]==='undefined';var _0x4182a8=_0xb7a73a[_0x22eb('0x20')];var _0x10d182=_0x2a55e4?0x0:_0x4d9b09[_0x22eb('0x1d')];var _0x36be50=_0x2a55e4?_0xb7a73a['count']:_0x4d9b09[_0x22eb('0x1d')]+_0x4d9b09[_0x22eb('0x1f')];var _0x2fc36e;if(_0x36be50>=_0x4182a8){_0x36be50=_0x4182a8;_0x2fc36e=0xc8;}else{_0x2fc36e=0xce;}_0x4d9a71['status'](_0x2fc36e);return _0x4d9a71['set'](_0x22eb('0x21'),_0x10d182+'-'+_0x36be50+'/'+_0x4182a8)[_0x22eb('0x1c')](_0xb7a73a);}return null;};}function patchUpdates(_0x434ecb){return function(_0x44639a){try{jsonpatch[_0x22eb('0x22')](_0x44639a,_0x434ecb,!![]);}catch(_0x3e8c1c){return BPromise[_0x22eb('0x23')](_0x3e8c1c);}return _0x44639a['save']();};}function saveUpdates(_0x2e8f7c,_0x11edbd){return function(_0x3ffa9e){if(_0x3ffa9e){return _0x3ffa9e[_0x22eb('0x24')](_0x2e8f7c)[_0x22eb('0x25')](function(_0x4da252){return _0x4da252;});}return null;};}function removeEntity(_0x12c133,_0x6f8ff3){return function(_0x2f3b39){if(_0x2f3b39){return _0x2f3b39['destroy']()[_0x22eb('0x25')](function(){_0x12c133[_0x22eb('0x26')](0xcc)['end']();});}};}function handleEntityNotFound(_0x32a4b6,_0x222ef3){return function(_0x1e3015){if(!_0x1e3015){_0x32a4b6[_0x22eb('0x1b')](0x194);}return _0x1e3015;};}function handleError(_0x2da5c6,_0x4f4f56){_0x4f4f56=_0x4f4f56||0x1f4;return function(_0x49dd59){logger[_0x22eb('0x27')](_0x49dd59[_0x22eb('0x28')]);if(_0x49dd59[_0x22eb('0x29')]){delete _0x49dd59[_0x22eb('0x29')];}_0x2da5c6[_0x22eb('0x26')](_0x4f4f56)[_0x22eb('0x2a')](_0x49dd59);};}exports[_0x22eb('0x2b')]=function(_0x13814f,_0x382784){var _0x39cec1={'raw':![],'where':{'id':_0x13814f[_0x22eb('0x2c')]['id']}},_0x24e9dc={};_0x24e9dc['model']=_[_0x22eb('0x2d')](db['DashboardItem'][_0x22eb('0x2e')]);_0x24e9dc[_0x22eb('0x2f')]=_[_0x22eb('0x2d')](_0x13814f[_0x22eb('0x2f')]);_0x24e9dc[_0x22eb('0x30')]=_[_0x22eb('0x31')](_0x24e9dc[_0x22eb('0x32')],_0x24e9dc[_0x22eb('0x2f')]);_0x39cec1[_0x22eb('0x33')]=_[_0x22eb('0x31')](_0x24e9dc['model'],qs['fields'](_0x13814f[_0x22eb('0x2f')]['fields']));_0x39cec1['attributes']=_0x39cec1[_0x22eb('0x33')][_0x22eb('0x34')]?_0x39cec1[_0x22eb('0x33')]:_0x24e9dc[_0x22eb('0x32')];if(_0x13814f[_0x22eb('0x2f')][_0x22eb('0x35')]){_0x39cec1[_0x22eb('0x36')]=[{'all':!![]}];}_0x39cec1=_[_0x22eb('0x37')]({},_0x39cec1,_0x13814f[_0x22eb('0x38')]);return db[_0x22eb('0x39')]['find'](_0x39cec1)[_0x22eb('0x25')](handleEntityNotFound(_0x382784,null))['then'](respondWithResult(_0x382784,null))['catch'](handleError(_0x382784,null));};exports[_0x22eb('0x3a')]=function(_0x2b5cb5,_0x48e47e){return db[_0x22eb('0x39')][_0x22eb('0x3b')]({'where':{'id':_0x2b5cb5[_0x22eb('0x2c')]['id']}})[_0x22eb('0x25')](handleEntityNotFound(_0x48e47e,null))[_0x22eb('0x25')](removeEntity(_0x48e47e,null))['catch'](handleError(_0x48e47e,null));};function widgetAttributes(_0x25f140){try{switch(_0x25f140[_0x22eb('0x3c')]){case'iframe':return[{'name':_0x22eb('0x3d'),'value':_0x25f140[_0x22eb('0x3d')]||(_0x25f140[_0x22eb('0x3e')]&&_0x25f140[_0x22eb('0x3e')][0x0]?_0x25f140[_0x22eb('0x3e')][0x0]['value']:undefined)||'https://'}];case _0x22eb('0x3f'):return[{'name':_0x22eb('0x40'),'value':_0x25f140['attrPath']||(_0x25f140[_0x22eb('0x3e')]&&_0x25f140[_0x22eb('0x3e')][0x0]?_0x25f140[_0x22eb('0x3e')][0x0]['value']:undefined)||''}];case _0x22eb('0x41'):return[{'name':_0x22eb('0x42'),'value':_0x25f140[_0x22eb('0x42')]||(_0x25f140[_0x22eb('0x3e')]&&_0x25f140[_0x22eb('0x3e')][0x0]?_0x25f140[_0x22eb('0x3e')][0x0]['value']:undefined)||_0x22eb('0x43')},{'name':_0x22eb('0x44'),'value':_0x25f140['attrTimezone']||(_0x25f140[_0x22eb('0x3e')]&&_0x25f140[_0x22eb('0x3e')][0x1]?_0x25f140[_0x22eb('0x3e')][0x1][_0x22eb('0x45')]:undefined)||_0x22eb('0x46')},{'name':_0x22eb('0x47'),'value':_0x25f140[_0x22eb('0x47')]||(_0x25f140[_0x22eb('0x3e')]&&_0x25f140[_0x22eb('0x3e')][0x2]?_0x25f140[_0x22eb('0x3e')][0x2][_0x22eb('0x45')]:undefined)||0xc}];case _0x22eb('0x48'):return[{'name':_0x22eb('0x49'),'value':_0x25f140[_0x22eb('0x49')]||(_0x25f140[_0x22eb('0x3e')]&&_0x25f140[_0x22eb('0x3e')][0x0]?_0x25f140[_0x22eb('0x3e')][0x0][_0x22eb('0x45')]:undefined)||'total'},{'name':_0x22eb('0x4a'),'value':_0x25f140[_0x22eb('0x4a')]||(_0x25f140['attrs']&&_0x25f140[_0x22eb('0x3e')][0x1]?_0x25f140[_0x22eb('0x3e')][0x1]['value']:undefined)||[]},{'name':'attrFontSize','value':_0x25f140['attrFontSize']||(_0x25f140[_0x22eb('0x3e')]&&_0x25f140[_0x22eb('0x3e')][0x2]?_0x25f140['attrs'][0x2]['value']:undefined)||0x14},{'name':_0x22eb('0x4b'),'value':_0x25f140[_0x22eb('0x4b')]||(_0x25f140[_0x22eb('0x3e')]&&_0x25f140[_0x22eb('0x3e')][0x3]?_0x25f140[_0x22eb('0x3e')][0x3][_0x22eb('0x45')]:undefined)||_0x22eb('0x4c')},{'name':_0x22eb('0x4d'),'value':_0x25f140['attrEmailAccounts']||(_0x25f140['attrs']&&_0x25f140[_0x22eb('0x3e')][0x4]?_0x25f140['attrs'][0x4][_0x22eb('0x45')]:undefined)||''},{'name':'attrFaxAccounts','value':_0x25f140[_0x22eb('0x4e')]||(_0x25f140['attrs']&&_0x25f140['attrs'][0x5]?_0x25f140['attrs'][0x5]['value']:undefined)||''},{'name':_0x22eb('0x4f'),'value':_0x25f140['attrSmsAccounts']||(_0x25f140[_0x22eb('0x3e')]&&_0x25f140[_0x22eb('0x3e')][0x6]?_0x25f140['attrs'][0x6][_0x22eb('0x45')]:undefined)||''},{'name':'attrOpenchannelAccounts','value':_0x25f140[_0x22eb('0x50')]||(_0x25f140[_0x22eb('0x3e')]&&_0x25f140[_0x22eb('0x3e')][0x7]?_0x25f140[_0x22eb('0x3e')][0x7][_0x22eb('0x45')]:undefined)||''},{'name':_0x22eb('0x51'),'value':_0x25f140[_0x22eb('0x51')]||(_0x25f140[_0x22eb('0x3e')]&&_0x25f140[_0x22eb('0x3e')][0x8]?_0x25f140['attrs'][0x8][_0x22eb('0x45')]:undefined)||''},{'name':_0x22eb('0x52'),'value':_0x25f140['attrChatWebsites']||(_0x25f140[_0x22eb('0x3e')]&&_0x25f140[_0x22eb('0x3e')][0x9]?_0x25f140[_0x22eb('0x3e')][0x9][_0x22eb('0x45')]:undefined)||''}];case'multibar-chart':case _0x22eb('0x53'):return[{'name':_0x22eb('0x54'),'value':_0x25f140[_0x22eb('0x54')]||(_0x25f140[_0x22eb('0x3e')]&&_0x25f140[_0x22eb('0x3e')][0x0]?_0x25f140[_0x22eb('0x3e')][0x0]['value']:undefined)||_0x22eb('0x55')},{'name':'attrSerie2','value':_0x25f140[_0x22eb('0x56')]||(_0x25f140['attrs']&&_0x25f140[_0x22eb('0x3e')][0x1]?_0x25f140[_0x22eb('0x3e')][0x1][_0x22eb('0x45')]:undefined)||null},{'name':_0x22eb('0x57'),'value':_0x25f140[_0x22eb('0x57')]||(_0x25f140['attrs']&&_0x25f140['attrs'][0x2]?_0x25f140[_0x22eb('0x3e')][0x2][_0x22eb('0x45')]:undefined)||null},{'name':'attrVoiceQueues','value':_0x25f140[_0x22eb('0x4a')]||(_0x25f140[_0x22eb('0x3e')]&&_0x25f140[_0x22eb('0x3e')][0x3]?_0x25f140[_0x22eb('0x3e')][0x3][_0x22eb('0x45')]:undefined)||[]},{'name':_0x22eb('0x4b'),'value':_0x25f140[_0x22eb('0x4b')]||(_0x25f140[_0x22eb('0x3e')]&&_0x25f140[_0x22eb('0x3e')][0x4]?_0x25f140[_0x22eb('0x3e')][0x4][_0x22eb('0x45')]:undefined)||'voice'},{'name':_0x22eb('0x4d'),'value':_0x25f140[_0x22eb('0x4d')]||(_0x25f140[_0x22eb('0x3e')]&&_0x25f140[_0x22eb('0x3e')][0x5]?_0x25f140[_0x22eb('0x3e')][0x5][_0x22eb('0x45')]:undefined)||''},{'name':_0x22eb('0x4e'),'value':_0x25f140[_0x22eb('0x4e')]||(_0x25f140[_0x22eb('0x3e')]&&_0x25f140[_0x22eb('0x3e')][0x6]?_0x25f140[_0x22eb('0x3e')][0x6][_0x22eb('0x45')]:undefined)||''},{'name':_0x22eb('0x4f'),'value':_0x25f140[_0x22eb('0x4f')]||(_0x25f140['attrs']&&_0x25f140['attrs'][0x7]?_0x25f140[_0x22eb('0x3e')][0x7][_0x22eb('0x45')]:undefined)||''},{'name':_0x22eb('0x50'),'value':_0x25f140[_0x22eb('0x50')]||(_0x25f140[_0x22eb('0x3e')]&&_0x25f140['attrs'][0x8]?_0x25f140[_0x22eb('0x3e')][0x8][_0x22eb('0x45')]:undefined)||''},{'name':'attrWhatsappAccounts','value':_0x25f140['attrWhatsappAccounts']||(_0x25f140[_0x22eb('0x3e')]&&_0x25f140[_0x22eb('0x3e')][0x9]?_0x25f140[_0x22eb('0x3e')][0x9][_0x22eb('0x45')]:undefined)||''},{'name':_0x22eb('0x52'),'value':_0x25f140[_0x22eb('0x52')]||(_0x25f140[_0x22eb('0x3e')]&&_0x25f140[_0x22eb('0x3e')][0xa]?_0x25f140[_0x22eb('0x3e')][0xa][_0x22eb('0x45')]:undefined)||''}];case _0x22eb('0x58'):return[{'name':_0x22eb('0x59'),'type':_0x25f140[_0x22eb('0x5a')]||(_0x25f140[_0x22eb('0x3e')]&&_0x25f140['attrs'][0x0]?_0x25f140[_0x22eb('0x3e')][0x0][_0x22eb('0x3c')]:undefined)||null,'value':_0x25f140[_0x22eb('0x59')]||(_0x25f140['attrs']&&_0x25f140[_0x22eb('0x3e')][0x0]?_0x25f140['attrs'][0x0][_0x22eb('0x45')]:undefined)||null},{'name':'attrRefresh','value':_0x25f140[_0x22eb('0x5b')]||(_0x25f140[_0x22eb('0x3e')]&&_0x25f140['attrs'][0x1]?_0x25f140[_0x22eb('0x3e')][0x1][_0x22eb('0x45')]:undefined)||0x0}];default:return[];}}catch(_0x538bc0){logger['error'](_0x22eb('0x5c'),JSON[_0x22eb('0x5d')](_0x538bc0));return[];}}exports[_0x22eb('0x5e')]=function(_0x344064,_0x3468ca){if(_0x344064[_0x22eb('0x5f')]){_0x344064['body'][_0x22eb('0x3e')]=widgetAttributes(_0x344064['body']);}return db['DashboardItem'][_0x22eb('0x5e')](_0x344064[_0x22eb('0x5f')],{})[_0x22eb('0x25')](respondWithResult(_0x3468ca,0xc9))[_0x22eb('0x60')](handleError(_0x3468ca,null));};exports[_0x22eb('0x24')]=function(_0x797700,_0x400dbe){if(_0x797700[_0x22eb('0x5f')]['id']){delete _0x797700['body']['id'];}_0x797700['body'][_0x22eb('0x3e')]=widgetAttributes(_0x797700[_0x22eb('0x5f')]);return db['DashboardItem'][_0x22eb('0x3b')]({'where':{'id':_0x797700[_0x22eb('0x2c')]['id']}})[_0x22eb('0x25')](handleEntityNotFound(_0x400dbe,null))[_0x22eb('0x25')](saveUpdates(_0x797700[_0x22eb('0x5f')],null))[_0x22eb('0x25')](respondWithResult(_0x400dbe,null))['catch'](handleError(_0x400dbe,null));};