Built motion from commit f25620e4.|2.6.30
[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 _0xefce=['moment','bluebird','mustache','util','path','sox','to-csv','ejs','fs-extra','crypto','jsforce','desk.js','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/logger','api','../../config/environment','../../config/license/util','../../mysqldb','defaults','redis','localhost','socket.io-emitter','./dashboardItem.socket','register','sendStatus','end','status','json','undefined','limit','count','offset','set','Content-Range','apply','reject','update','then','destroy','stack','name','send','show','params','model','keys','rawAttributes','query','filters','intersection','attributes','fields','include','merge','options','DashboardItem','catch','find','type','iframe','attrs','value','https://','attrPath','clock','attrHourFormat','HH:mm:ss','attrTimezone','0.00','attrFontSize','counter','attrMetric','attrVoiceQueues','attrChannel','voice','attrEmailAccounts','attrFaxAccounts','attrSmsAccounts','attrOpenchannelAccounts','attrWhatsappAccounts','attrChatWebsites','multibar-chart','pie-chart','attrSerie1','total','attrSerie2','attrSerie3','web-report','attrReport','attrRefresh','error','widgetAttributes:\x20%s','create','body','rimraf','request-promise'];(function(_0xc4001c,_0x1bf8f0){var _0x49f7bc=function(_0x1059b8){while(--_0x1059b8){_0xc4001c['push'](_0xc4001c['shift']());}};_0x49f7bc(++_0x1bf8f0);}(_0xefce,0x1e8));var _0xeefc=function(_0x5cfb92,_0x5797e6){_0x5cfb92=_0x5cfb92-0x0;var _0x1cd7c2=_0xefce[_0x5cfb92];return _0x1cd7c2;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0xeefc('0x0'));var zipdir=require('zip-dir');var jsonpatch=require('fast-json-patch');var rp=require(_0xeefc('0x1'));var moment=require(_0xeefc('0x2'));var BPromise=require(_0xeefc('0x3'));var Mustache=require(_0xeefc('0x4'));var util=require(_0xeefc('0x5'));var path=require(_0xeefc('0x6'));var sox=require(_0xeefc('0x7'));var csv=require(_0xeefc('0x8'));var ejs=require(_0xeefc('0x9'));var fs=require('fs');var fs_extra=require(_0xeefc('0xa'));var _=require('lodash');var squel=require('squel');var crypto=require(_0xeefc('0xb'));var jsforce=require(_0xeefc('0xc'));var deskjs=require(_0xeefc('0xd'));var toCsv=require(_0xeefc('0x8'));var querystring=require('querystring');var Papa=require('papaparse');var Redis=require(_0xeefc('0xe'));var authService=require(_0xeefc('0xf'));var qs=require('../../components/parsers/qs');var as=require(_0xeefc('0x10'));var hardwareService=require('../../config/license/hardware');var logger=require(_0xeefc('0x11'))(_0xeefc('0x12'));var utils=require('../../config/utils');var config=require(_0xeefc('0x13'));var licenseUtil=require(_0xeefc('0x14'));var db=require(_0xeefc('0x15'))['db'];config['redis']=_[_0xeefc('0x16')](config[_0xeefc('0x17')],{'host':_0xeefc('0x18'),'port':0x18eb});var socket=require(_0xeefc('0x19'))(new Redis(config[_0xeefc('0x17')]));require(_0xeefc('0x1a'))[_0xeefc('0x1b')](socket);function respondWithStatusCode(_0x4537e2,_0x2d5fc1){_0x2d5fc1=_0x2d5fc1||0xcc;return function(_0x3ac92a){if(_0x3ac92a){return _0x4537e2[_0xeefc('0x1c')](_0x2d5fc1);}return _0x4537e2['status'](_0x2d5fc1)[_0xeefc('0x1d')]();};}function respondWithResult(_0x5c447b,_0x2ce41b){_0x2ce41b=_0x2ce41b||0xc8;return function(_0x2fe7c2){if(_0x2fe7c2){return _0x5c447b[_0xeefc('0x1e')](_0x2ce41b)[_0xeefc('0x1f')](_0x2fe7c2);}};}function respondWithFilteredResult(_0x15baaa,_0x49cfe2){return function(_0x1c247e){if(_0x1c247e){var _0x1ea90e=typeof _0x49cfe2['offset']===_0xeefc('0x20')&&typeof _0x49cfe2[_0xeefc('0x21')]===_0xeefc('0x20');var _0x4ba684=_0x1c247e[_0xeefc('0x22')];var _0x1f2825=_0x1ea90e?0x0:_0x49cfe2['offset'];var _0x25ca4d=_0x1ea90e?_0x1c247e['count']:_0x49cfe2[_0xeefc('0x23')]+_0x49cfe2[_0xeefc('0x21')];var _0x3cebaa;if(_0x25ca4d>=_0x4ba684){_0x25ca4d=_0x4ba684;_0x3cebaa=0xc8;}else{_0x3cebaa=0xce;}_0x15baaa[_0xeefc('0x1e')](_0x3cebaa);return _0x15baaa[_0xeefc('0x24')](_0xeefc('0x25'),_0x1f2825+'-'+_0x25ca4d+'/'+_0x4ba684)[_0xeefc('0x1f')](_0x1c247e);}return null;};}function patchUpdates(_0x4ec1c9){return function(_0x168700){try{jsonpatch[_0xeefc('0x26')](_0x168700,_0x4ec1c9,!![]);}catch(_0x6e690b){return BPromise[_0xeefc('0x27')](_0x6e690b);}return _0x168700['save']();};}function saveUpdates(_0x48246d,_0x1a8b12){return function(_0x1f2d59){if(_0x1f2d59){return _0x1f2d59[_0xeefc('0x28')](_0x48246d)[_0xeefc('0x29')](function(_0x4aeaa7){return _0x4aeaa7;});}return null;};}function removeEntity(_0x16e60e,_0x3ea299){return function(_0xceece3){if(_0xceece3){return _0xceece3[_0xeefc('0x2a')]()['then'](function(){_0x16e60e['status'](0xcc)[_0xeefc('0x1d')]();});}};}function handleEntityNotFound(_0x5b7d0d,_0x27f8cd){return function(_0x2d13b6){if(!_0x2d13b6){_0x5b7d0d['sendStatus'](0x194);}return _0x2d13b6;};}function handleError(_0x52dab1,_0x167fe8){_0x167fe8=_0x167fe8||0x1f4;return function(_0x56ea84){logger['error'](_0x56ea84[_0xeefc('0x2b')]);if(_0x56ea84[_0xeefc('0x2c')]){delete _0x56ea84['name'];}_0x52dab1['status'](_0x167fe8)[_0xeefc('0x2d')](_0x56ea84);};}exports[_0xeefc('0x2e')]=function(_0x4369c9,_0x13a33e){var _0x29fc6b={'raw':![],'where':{'id':_0x4369c9[_0xeefc('0x2f')]['id']}},_0x325578={};_0x325578[_0xeefc('0x30')]=_[_0xeefc('0x31')](db['DashboardItem'][_0xeefc('0x32')]);_0x325578[_0xeefc('0x33')]=_[_0xeefc('0x31')](_0x4369c9[_0xeefc('0x33')]);_0x325578[_0xeefc('0x34')]=_[_0xeefc('0x35')](_0x325578[_0xeefc('0x30')],_0x325578[_0xeefc('0x33')]);_0x29fc6b[_0xeefc('0x36')]=_[_0xeefc('0x35')](_0x325578[_0xeefc('0x30')],qs[_0xeefc('0x37')](_0x4369c9[_0xeefc('0x33')]['fields']));_0x29fc6b[_0xeefc('0x36')]=_0x29fc6b[_0xeefc('0x36')]['length']?_0x29fc6b[_0xeefc('0x36')]:_0x325578[_0xeefc('0x30')];if(_0x4369c9['query']['includeAll']){_0x29fc6b[_0xeefc('0x38')]=[{'all':!![]}];}_0x29fc6b=_[_0xeefc('0x39')]({},_0x29fc6b,_0x4369c9[_0xeefc('0x3a')]);return db[_0xeefc('0x3b')]['find'](_0x29fc6b)[_0xeefc('0x29')](handleEntityNotFound(_0x13a33e,null))['then'](respondWithResult(_0x13a33e,null))[_0xeefc('0x3c')](handleError(_0x13a33e,null));};exports[_0xeefc('0x2a')]=function(_0x52b74a,_0x38d4c2){return db[_0xeefc('0x3b')][_0xeefc('0x3d')]({'where':{'id':_0x52b74a[_0xeefc('0x2f')]['id']}})[_0xeefc('0x29')](handleEntityNotFound(_0x38d4c2,null))[_0xeefc('0x29')](removeEntity(_0x38d4c2,null))[_0xeefc('0x3c')](handleError(_0x38d4c2,null));};function widgetAttributes(_0x11186c){try{switch(_0x11186c[_0xeefc('0x3e')]){case _0xeefc('0x3f'):return[{'name':'attrUrl','value':_0x11186c['attrUrl']||(_0x11186c['attrs']&&_0x11186c[_0xeefc('0x40')][0x0]?_0x11186c[_0xeefc('0x40')][0x0][_0xeefc('0x41')]:undefined)||_0xeefc('0x42')}];case'custom':return[{'name':_0xeefc('0x43'),'value':_0x11186c[_0xeefc('0x43')]||(_0x11186c[_0xeefc('0x40')]&&_0x11186c[_0xeefc('0x40')][0x0]?_0x11186c['attrs'][0x0][_0xeefc('0x41')]:undefined)||''}];case _0xeefc('0x44'):return[{'name':_0xeefc('0x45'),'value':_0x11186c[_0xeefc('0x45')]||(_0x11186c[_0xeefc('0x40')]&&_0x11186c[_0xeefc('0x40')][0x0]?_0x11186c[_0xeefc('0x40')][0x0][_0xeefc('0x41')]:undefined)||_0xeefc('0x46')},{'name':_0xeefc('0x47'),'value':_0x11186c['attrTimezone']||(_0x11186c['attrs']&&_0x11186c[_0xeefc('0x40')][0x1]?_0x11186c[_0xeefc('0x40')][0x1][_0xeefc('0x41')]:undefined)||_0xeefc('0x48')},{'name':_0xeefc('0x49'),'value':_0x11186c[_0xeefc('0x49')]||(_0x11186c['attrs']&&_0x11186c['attrs'][0x2]?_0x11186c[_0xeefc('0x40')][0x2][_0xeefc('0x41')]:undefined)||0xc}];case _0xeefc('0x4a'):return[{'name':_0xeefc('0x4b'),'value':_0x11186c[_0xeefc('0x4b')]||(_0x11186c[_0xeefc('0x40')]&&_0x11186c[_0xeefc('0x40')][0x0]?_0x11186c[_0xeefc('0x40')][0x0][_0xeefc('0x41')]:undefined)||'total'},{'name':_0xeefc('0x4c'),'value':_0x11186c[_0xeefc('0x4c')]||(_0x11186c[_0xeefc('0x40')]&&_0x11186c[_0xeefc('0x40')][0x1]?_0x11186c[_0xeefc('0x40')][0x1][_0xeefc('0x41')]:undefined)||[]},{'name':_0xeefc('0x49'),'value':_0x11186c[_0xeefc('0x49')]||(_0x11186c[_0xeefc('0x40')]&&_0x11186c[_0xeefc('0x40')][0x2]?_0x11186c[_0xeefc('0x40')][0x2][_0xeefc('0x41')]:undefined)||0x14},{'name':_0xeefc('0x4d'),'value':_0x11186c[_0xeefc('0x4d')]||(_0x11186c[_0xeefc('0x40')]&&_0x11186c['attrs'][0x3]?_0x11186c[_0xeefc('0x40')][0x3][_0xeefc('0x41')]:undefined)||_0xeefc('0x4e')},{'name':_0xeefc('0x4f'),'value':_0x11186c[_0xeefc('0x4f')]||(_0x11186c[_0xeefc('0x40')]&&_0x11186c[_0xeefc('0x40')][0x4]?_0x11186c[_0xeefc('0x40')][0x4][_0xeefc('0x41')]:undefined)||''},{'name':_0xeefc('0x50'),'value':_0x11186c[_0xeefc('0x50')]||(_0x11186c[_0xeefc('0x40')]&&_0x11186c[_0xeefc('0x40')][0x5]?_0x11186c[_0xeefc('0x40')][0x5]['value']:undefined)||''},{'name':_0xeefc('0x51'),'value':_0x11186c[_0xeefc('0x51')]||(_0x11186c[_0xeefc('0x40')]&&_0x11186c[_0xeefc('0x40')][0x6]?_0x11186c['attrs'][0x6]['value']:undefined)||''},{'name':_0xeefc('0x52'),'value':_0x11186c[_0xeefc('0x52')]||(_0x11186c[_0xeefc('0x40')]&&_0x11186c[_0xeefc('0x40')][0x7]?_0x11186c[_0xeefc('0x40')][0x7][_0xeefc('0x41')]:undefined)||''},{'name':_0xeefc('0x53'),'value':_0x11186c[_0xeefc('0x53')]||(_0x11186c['attrs']&&_0x11186c['attrs'][0x8]?_0x11186c[_0xeefc('0x40')][0x8][_0xeefc('0x41')]:undefined)||''},{'name':_0xeefc('0x54'),'value':_0x11186c['attrChatWebsites']||(_0x11186c[_0xeefc('0x40')]&&_0x11186c[_0xeefc('0x40')][0x9]?_0x11186c[_0xeefc('0x40')][0x9]['value']:undefined)||''}];case _0xeefc('0x55'):case _0xeefc('0x56'):return[{'name':_0xeefc('0x57'),'value':_0x11186c[_0xeefc('0x57')]||(_0x11186c[_0xeefc('0x40')]&&_0x11186c[_0xeefc('0x40')][0x0]?_0x11186c['attrs'][0x0]['value']:undefined)||_0xeefc('0x58')},{'name':_0xeefc('0x59'),'value':_0x11186c[_0xeefc('0x59')]||(_0x11186c[_0xeefc('0x40')]&&_0x11186c[_0xeefc('0x40')][0x1]?_0x11186c['attrs'][0x1][_0xeefc('0x41')]:undefined)||null},{'name':_0xeefc('0x5a'),'value':_0x11186c[_0xeefc('0x5a')]||(_0x11186c[_0xeefc('0x40')]&&_0x11186c[_0xeefc('0x40')][0x2]?_0x11186c[_0xeefc('0x40')][0x2]['value']:undefined)||null},{'name':_0xeefc('0x4c'),'value':_0x11186c[_0xeefc('0x4c')]||(_0x11186c[_0xeefc('0x40')]&&_0x11186c['attrs'][0x3]?_0x11186c['attrs'][0x3][_0xeefc('0x41')]:undefined)||[]},{'name':_0xeefc('0x4d'),'value':_0x11186c['attrChannel']||(_0x11186c[_0xeefc('0x40')]&&_0x11186c['attrs'][0x4]?_0x11186c[_0xeefc('0x40')][0x4][_0xeefc('0x41')]:undefined)||_0xeefc('0x4e')},{'name':_0xeefc('0x4f'),'value':_0x11186c['attrEmailAccounts']||(_0x11186c[_0xeefc('0x40')]&&_0x11186c[_0xeefc('0x40')][0x5]?_0x11186c[_0xeefc('0x40')][0x5][_0xeefc('0x41')]:undefined)||''},{'name':_0xeefc('0x50'),'value':_0x11186c[_0xeefc('0x50')]||(_0x11186c[_0xeefc('0x40')]&&_0x11186c[_0xeefc('0x40')][0x6]?_0x11186c[_0xeefc('0x40')][0x6]['value']:undefined)||''},{'name':'attrSmsAccounts','value':_0x11186c[_0xeefc('0x51')]||(_0x11186c[_0xeefc('0x40')]&&_0x11186c[_0xeefc('0x40')][0x7]?_0x11186c[_0xeefc('0x40')][0x7][_0xeefc('0x41')]:undefined)||''},{'name':_0xeefc('0x52'),'value':_0x11186c[_0xeefc('0x52')]||(_0x11186c[_0xeefc('0x40')]&&_0x11186c[_0xeefc('0x40')][0x8]?_0x11186c['attrs'][0x8]['value']:undefined)||''},{'name':'attrWhatsappAccounts','value':_0x11186c[_0xeefc('0x53')]||(_0x11186c[_0xeefc('0x40')]&&_0x11186c['attrs'][0x9]?_0x11186c[_0xeefc('0x40')][0x9][_0xeefc('0x41')]:undefined)||''},{'name':_0xeefc('0x54'),'value':_0x11186c[_0xeefc('0x54')]||(_0x11186c[_0xeefc('0x40')]&&_0x11186c[_0xeefc('0x40')][0xa]?_0x11186c[_0xeefc('0x40')][0xa][_0xeefc('0x41')]:undefined)||''}];case _0xeefc('0x5b'):return[{'name':_0xeefc('0x5c'),'type':_0x11186c['reportType']||(_0x11186c[_0xeefc('0x40')]&&_0x11186c['attrs'][0x0]?_0x11186c['attrs'][0x0]['type']:undefined)||null,'value':_0x11186c[_0xeefc('0x5c')]||(_0x11186c['attrs']&&_0x11186c[_0xeefc('0x40')][0x0]?_0x11186c[_0xeefc('0x40')][0x0]['value']:undefined)||null},{'name':_0xeefc('0x5d'),'value':_0x11186c[_0xeefc('0x5d')]||(_0x11186c[_0xeefc('0x40')]&&_0x11186c[_0xeefc('0x40')][0x1]?_0x11186c[_0xeefc('0x40')][0x1][_0xeefc('0x41')]:undefined)||0x0}];default:return[];}}catch(_0xa1c28f){logger[_0xeefc('0x5e')](_0xeefc('0x5f'),JSON['stringify'](_0xa1c28f));return[];}}exports[_0xeefc('0x60')]=function(_0x232c64,_0x5c5ec2){if(_0x232c64[_0xeefc('0x61')]){_0x232c64[_0xeefc('0x61')][_0xeefc('0x40')]=widgetAttributes(_0x232c64['body']);}return db['DashboardItem'][_0xeefc('0x60')](_0x232c64[_0xeefc('0x61')],{})[_0xeefc('0x29')](respondWithResult(_0x5c5ec2,0xc9))[_0xeefc('0x3c')](handleError(_0x5c5ec2,null));};exports[_0xeefc('0x28')]=function(_0x34a816,_0x1f5e28){if(_0x34a816['body']['id']){delete _0x34a816[_0xeefc('0x61')]['id'];}_0x34a816['body'][_0xeefc('0x40')]=widgetAttributes(_0x34a816[_0xeefc('0x61')]);return db[_0xeefc('0x3b')]['find']({'where':{'id':_0x34a816[_0xeefc('0x2f')]['id']}})['then'](handleEntityNotFound(_0x1f5e28,null))[_0xeefc('0x29')](saveUpdates(_0x34a816['body'],null))[_0xeefc('0x29')](respondWithResult(_0x1f5e28,null))[_0xeefc('0x3c')](handleError(_0x1f5e28,null));};