Built motion from commit b0a9a629.|2.6.33
[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 _0x7278=['stack','name','show','params','model','keys','DashboardItem','rawAttributes','query','filters','intersection','attributes','fields','includeAll','merge','options','find','catch','type','attrUrl','attrs','value','https://','custom','attrPath','attrHourFormat','HH:mm:ss','attrTimezone','0.00','attrFontSize','counter','attrMetric','total','attrVoiceQueues','attrChannel','voice','attrEmailAccounts','attrFaxAccounts','attrSmsAccounts','attrOpenchannelAccounts','attrWhatsappAccounts','multibar-chart','pie-chart','attrSerie1','attrSerie2','attrSerie3','web-report','attrReport','reportType','attrRefresh','widgetAttributes:\x20%s','create','body','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','bluebird','mustache','util','path','sox','to-csv','ejs','lodash','squel','crypto','jsforce','desk.js','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/license/util','../../mysqldb','redis','localhost','./dashboardItem.socket','register','sendStatus','status','end','json','undefined','count','offset','limit','set','Content-Range','apply','save','update','then','destroy','error'];(function(_0x4124e3,_0x4af20c){var _0x2b9d71=function(_0x1370cb){while(--_0x1370cb){_0x4124e3['push'](_0x4124e3['shift']());}};_0x2b9d71(++_0x4af20c);}(_0x7278,0x161));var _0x8727=function(_0x86adbe,_0x4f03d4){_0x86adbe=_0x86adbe-0x0;var _0x1b5164=_0x7278[_0x86adbe];return _0x1b5164;};'use strict';var emlformat=require(_0x8727('0x0'));var rimraf=require(_0x8727('0x1'));var zipdir=require(_0x8727('0x2'));var jsonpatch=require(_0x8727('0x3'));var rp=require(_0x8727('0x4'));var moment=require('moment');var BPromise=require(_0x8727('0x5'));var Mustache=require(_0x8727('0x6'));var util=require(_0x8727('0x7'));var path=require(_0x8727('0x8'));var sox=require(_0x8727('0x9'));var csv=require(_0x8727('0xa'));var ejs=require(_0x8727('0xb'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0x8727('0xc'));var squel=require(_0x8727('0xd'));var crypto=require(_0x8727('0xe'));var jsforce=require(_0x8727('0xf'));var deskjs=require(_0x8727('0x10'));var toCsv=require('to-csv');var querystring=require('querystring');var Papa=require('papaparse');var Redis=require(_0x8727('0x11'));var authService=require(_0x8727('0x12'));var qs=require(_0x8727('0x13'));var as=require(_0x8727('0x14'));var hardwareService=require(_0x8727('0x15'));var logger=require(_0x8727('0x16'))(_0x8727('0x17'));var utils=require(_0x8727('0x18'));var config=require('../../config/environment');var licenseUtil=require(_0x8727('0x19'));var db=require(_0x8727('0x1a'))['db'];config[_0x8727('0x1b')]=_['defaults'](config[_0x8727('0x1b')],{'host':_0x8727('0x1c'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x8727('0x1b')]));require(_0x8727('0x1d'))[_0x8727('0x1e')](socket);function respondWithStatusCode(_0x2185e5,_0x2ea789){_0x2ea789=_0x2ea789||0xcc;return function(_0x3d84db){if(_0x3d84db){return _0x2185e5[_0x8727('0x1f')](_0x2ea789);}return _0x2185e5[_0x8727('0x20')](_0x2ea789)[_0x8727('0x21')]();};}function respondWithResult(_0x88857c,_0x4842a0){_0x4842a0=_0x4842a0||0xc8;return function(_0x17baba){if(_0x17baba){return _0x88857c[_0x8727('0x20')](_0x4842a0)[_0x8727('0x22')](_0x17baba);}};}function respondWithFilteredResult(_0x2f6e1d,_0x112f04){return function(_0xba0af5){if(_0xba0af5){var _0x533e6d=typeof _0x112f04['offset']===_0x8727('0x23')&&typeof _0x112f04['limit']===_0x8727('0x23');var _0xfd266f=_0xba0af5[_0x8727('0x24')];var _0x22e6c9=_0x533e6d?0x0:_0x112f04[_0x8727('0x25')];var _0x537aaf=_0x533e6d?_0xba0af5[_0x8727('0x24')]:_0x112f04[_0x8727('0x25')]+_0x112f04[_0x8727('0x26')];var _0x1d78df;if(_0x537aaf>=_0xfd266f){_0x537aaf=_0xfd266f;_0x1d78df=0xc8;}else{_0x1d78df=0xce;}_0x2f6e1d[_0x8727('0x20')](_0x1d78df);return _0x2f6e1d[_0x8727('0x27')](_0x8727('0x28'),_0x22e6c9+'-'+_0x537aaf+'/'+_0xfd266f)[_0x8727('0x22')](_0xba0af5);}return null;};}function patchUpdates(_0x117f58){return function(_0x56ffd5){try{jsonpatch[_0x8727('0x29')](_0x56ffd5,_0x117f58,!![]);}catch(_0x1a69d5){return BPromise['reject'](_0x1a69d5);}return _0x56ffd5[_0x8727('0x2a')]();};}function saveUpdates(_0x3d3592,_0x4c468d){return function(_0x5adefe){if(_0x5adefe){return _0x5adefe[_0x8727('0x2b')](_0x3d3592)[_0x8727('0x2c')](function(_0x15e8bf){return _0x15e8bf;});}return null;};}function removeEntity(_0x5de6fa,_0x98261b){return function(_0x4cacf2){if(_0x4cacf2){return _0x4cacf2[_0x8727('0x2d')]()[_0x8727('0x2c')](function(){_0x5de6fa[_0x8727('0x20')](0xcc)[_0x8727('0x21')]();});}};}function handleEntityNotFound(_0x262f36,_0xd92f77){return function(_0x5d03f2){if(!_0x5d03f2){_0x262f36[_0x8727('0x1f')](0x194);}return _0x5d03f2;};}function handleError(_0x307055,_0x54034d){_0x54034d=_0x54034d||0x1f4;return function(_0x23325f){logger[_0x8727('0x2e')](_0x23325f[_0x8727('0x2f')]);if(_0x23325f[_0x8727('0x30')]){delete _0x23325f[_0x8727('0x30')];}_0x307055[_0x8727('0x20')](_0x54034d)['send'](_0x23325f);};}exports[_0x8727('0x31')]=function(_0x563201,_0x34c58e){var _0x47e9f9={'raw':![],'where':{'id':_0x563201[_0x8727('0x32')]['id']}},_0x44ed83={};_0x44ed83[_0x8727('0x33')]=_[_0x8727('0x34')](db[_0x8727('0x35')][_0x8727('0x36')]);_0x44ed83[_0x8727('0x37')]=_['keys'](_0x563201[_0x8727('0x37')]);_0x44ed83[_0x8727('0x38')]=_[_0x8727('0x39')](_0x44ed83[_0x8727('0x33')],_0x44ed83[_0x8727('0x37')]);_0x47e9f9[_0x8727('0x3a')]=_[_0x8727('0x39')](_0x44ed83[_0x8727('0x33')],qs[_0x8727('0x3b')](_0x563201[_0x8727('0x37')][_0x8727('0x3b')]));_0x47e9f9[_0x8727('0x3a')]=_0x47e9f9['attributes']['length']?_0x47e9f9[_0x8727('0x3a')]:_0x44ed83[_0x8727('0x33')];if(_0x563201[_0x8727('0x37')][_0x8727('0x3c')]){_0x47e9f9['include']=[{'all':!![]}];}_0x47e9f9=_[_0x8727('0x3d')]({},_0x47e9f9,_0x563201[_0x8727('0x3e')]);return db[_0x8727('0x35')][_0x8727('0x3f')](_0x47e9f9)[_0x8727('0x2c')](handleEntityNotFound(_0x34c58e,null))['then'](respondWithResult(_0x34c58e,null))[_0x8727('0x40')](handleError(_0x34c58e,null));};exports[_0x8727('0x2d')]=function(_0x8e9de8,_0x1b0e88){return db[_0x8727('0x35')][_0x8727('0x3f')]({'where':{'id':_0x8e9de8[_0x8727('0x32')]['id']}})[_0x8727('0x2c')](handleEntityNotFound(_0x1b0e88,null))[_0x8727('0x2c')](removeEntity(_0x1b0e88,null))[_0x8727('0x40')](handleError(_0x1b0e88,null));};function widgetAttributes(_0x396f12){try{switch(_0x396f12[_0x8727('0x41')]){case'iframe':return[{'name':_0x8727('0x42'),'value':_0x396f12[_0x8727('0x42')]||(_0x396f12[_0x8727('0x43')]&&_0x396f12[_0x8727('0x43')][0x0]?_0x396f12[_0x8727('0x43')][0x0][_0x8727('0x44')]:undefined)||_0x8727('0x45')}];case _0x8727('0x46'):return[{'name':_0x8727('0x47'),'value':_0x396f12[_0x8727('0x47')]||(_0x396f12[_0x8727('0x43')]&&_0x396f12[_0x8727('0x43')][0x0]?_0x396f12[_0x8727('0x43')][0x0][_0x8727('0x44')]:undefined)||''}];case'clock':return[{'name':_0x8727('0x48'),'value':_0x396f12[_0x8727('0x48')]||(_0x396f12[_0x8727('0x43')]&&_0x396f12['attrs'][0x0]?_0x396f12[_0x8727('0x43')][0x0][_0x8727('0x44')]:undefined)||_0x8727('0x49')},{'name':_0x8727('0x4a'),'value':_0x396f12['attrTimezone']||(_0x396f12[_0x8727('0x43')]&&_0x396f12[_0x8727('0x43')][0x1]?_0x396f12[_0x8727('0x43')][0x1][_0x8727('0x44')]:undefined)||_0x8727('0x4b')},{'name':_0x8727('0x4c'),'value':_0x396f12[_0x8727('0x4c')]||(_0x396f12[_0x8727('0x43')]&&_0x396f12[_0x8727('0x43')][0x2]?_0x396f12[_0x8727('0x43')][0x2]['value']:undefined)||0xc}];case _0x8727('0x4d'):return[{'name':_0x8727('0x4e'),'value':_0x396f12[_0x8727('0x4e')]||(_0x396f12[_0x8727('0x43')]&&_0x396f12[_0x8727('0x43')][0x0]?_0x396f12['attrs'][0x0][_0x8727('0x44')]:undefined)||_0x8727('0x4f')},{'name':_0x8727('0x50'),'value':_0x396f12['attrVoiceQueues']||(_0x396f12[_0x8727('0x43')]&&_0x396f12[_0x8727('0x43')][0x1]?_0x396f12[_0x8727('0x43')][0x1][_0x8727('0x44')]:undefined)||[]},{'name':_0x8727('0x4c'),'value':_0x396f12[_0x8727('0x4c')]||(_0x396f12['attrs']&&_0x396f12[_0x8727('0x43')][0x2]?_0x396f12[_0x8727('0x43')][0x2][_0x8727('0x44')]:undefined)||0x14},{'name':'attrChannel','value':_0x396f12[_0x8727('0x51')]||(_0x396f12[_0x8727('0x43')]&&_0x396f12[_0x8727('0x43')][0x3]?_0x396f12[_0x8727('0x43')][0x3][_0x8727('0x44')]:undefined)||_0x8727('0x52')},{'name':_0x8727('0x53'),'value':_0x396f12['attrEmailAccounts']||(_0x396f12[_0x8727('0x43')]&&_0x396f12[_0x8727('0x43')][0x4]?_0x396f12[_0x8727('0x43')][0x4][_0x8727('0x44')]:undefined)||''},{'name':_0x8727('0x54'),'value':_0x396f12[_0x8727('0x54')]||(_0x396f12[_0x8727('0x43')]&&_0x396f12['attrs'][0x5]?_0x396f12[_0x8727('0x43')][0x5][_0x8727('0x44')]:undefined)||''},{'name':_0x8727('0x55'),'value':_0x396f12['attrSmsAccounts']||(_0x396f12[_0x8727('0x43')]&&_0x396f12[_0x8727('0x43')][0x6]?_0x396f12[_0x8727('0x43')][0x6][_0x8727('0x44')]:undefined)||''},{'name':_0x8727('0x56'),'value':_0x396f12[_0x8727('0x56')]||(_0x396f12[_0x8727('0x43')]&&_0x396f12['attrs'][0x7]?_0x396f12[_0x8727('0x43')][0x7]['value']:undefined)||''},{'name':_0x8727('0x57'),'value':_0x396f12[_0x8727('0x57')]||(_0x396f12['attrs']&&_0x396f12[_0x8727('0x43')][0x8]?_0x396f12[_0x8727('0x43')][0x8][_0x8727('0x44')]:undefined)||''},{'name':'attrChatWebsites','value':_0x396f12['attrChatWebsites']||(_0x396f12[_0x8727('0x43')]&&_0x396f12[_0x8727('0x43')][0x9]?_0x396f12[_0x8727('0x43')][0x9]['value']:undefined)||''}];case _0x8727('0x58'):case _0x8727('0x59'):return[{'name':_0x8727('0x5a'),'value':_0x396f12[_0x8727('0x5a')]||(_0x396f12[_0x8727('0x43')]&&_0x396f12[_0x8727('0x43')][0x0]?_0x396f12[_0x8727('0x43')][0x0][_0x8727('0x44')]:undefined)||'total'},{'name':_0x8727('0x5b'),'value':_0x396f12[_0x8727('0x5b')]||(_0x396f12[_0x8727('0x43')]&&_0x396f12[_0x8727('0x43')][0x1]?_0x396f12['attrs'][0x1][_0x8727('0x44')]:undefined)||null},{'name':_0x8727('0x5c'),'value':_0x396f12[_0x8727('0x5c')]||(_0x396f12[_0x8727('0x43')]&&_0x396f12[_0x8727('0x43')][0x2]?_0x396f12[_0x8727('0x43')][0x2][_0x8727('0x44')]:undefined)||null},{'name':_0x8727('0x50'),'value':_0x396f12['attrVoiceQueues']||(_0x396f12[_0x8727('0x43')]&&_0x396f12[_0x8727('0x43')][0x3]?_0x396f12[_0x8727('0x43')][0x3]['value']:undefined)||[]},{'name':_0x8727('0x51'),'value':_0x396f12['attrChannel']||(_0x396f12[_0x8727('0x43')]&&_0x396f12['attrs'][0x4]?_0x396f12[_0x8727('0x43')][0x4][_0x8727('0x44')]:undefined)||'voice'},{'name':_0x8727('0x53'),'value':_0x396f12[_0x8727('0x53')]||(_0x396f12[_0x8727('0x43')]&&_0x396f12['attrs'][0x5]?_0x396f12['attrs'][0x5]['value']:undefined)||''},{'name':'attrFaxAccounts','value':_0x396f12[_0x8727('0x54')]||(_0x396f12[_0x8727('0x43')]&&_0x396f12[_0x8727('0x43')][0x6]?_0x396f12[_0x8727('0x43')][0x6][_0x8727('0x44')]:undefined)||''},{'name':'attrSmsAccounts','value':_0x396f12['attrSmsAccounts']||(_0x396f12[_0x8727('0x43')]&&_0x396f12[_0x8727('0x43')][0x7]?_0x396f12[_0x8727('0x43')][0x7][_0x8727('0x44')]:undefined)||''},{'name':_0x8727('0x56'),'value':_0x396f12[_0x8727('0x56')]||(_0x396f12[_0x8727('0x43')]&&_0x396f12[_0x8727('0x43')][0x8]?_0x396f12[_0x8727('0x43')][0x8][_0x8727('0x44')]:undefined)||''},{'name':_0x8727('0x57'),'value':_0x396f12[_0x8727('0x57')]||(_0x396f12['attrs']&&_0x396f12[_0x8727('0x43')][0x9]?_0x396f12[_0x8727('0x43')][0x9]['value']:undefined)||''},{'name':'attrChatWebsites','value':_0x396f12['attrChatWebsites']||(_0x396f12['attrs']&&_0x396f12[_0x8727('0x43')][0xa]?_0x396f12[_0x8727('0x43')][0xa]['value']:undefined)||''}];case _0x8727('0x5d'):return[{'name':_0x8727('0x5e'),'type':_0x396f12[_0x8727('0x5f')]||(_0x396f12[_0x8727('0x43')]&&_0x396f12[_0x8727('0x43')][0x0]?_0x396f12['attrs'][0x0][_0x8727('0x41')]:undefined)||null,'value':_0x396f12[_0x8727('0x5e')]||(_0x396f12[_0x8727('0x43')]&&_0x396f12[_0x8727('0x43')][0x0]?_0x396f12[_0x8727('0x43')][0x0][_0x8727('0x44')]:undefined)||null},{'name':_0x8727('0x60'),'value':_0x396f12[_0x8727('0x60')]||(_0x396f12[_0x8727('0x43')]&&_0x396f12['attrs'][0x1]?_0x396f12[_0x8727('0x43')][0x1][_0x8727('0x44')]:undefined)||0x0}];default:return[];}}catch(_0x221597){logger['error'](_0x8727('0x61'),JSON['stringify'](_0x221597));return[];}}exports[_0x8727('0x62')]=function(_0x1e8cba,_0xb8e231){if(_0x1e8cba[_0x8727('0x63')]){_0x1e8cba[_0x8727('0x63')]['attrs']=widgetAttributes(_0x1e8cba['body']);}return db[_0x8727('0x35')][_0x8727('0x62')](_0x1e8cba[_0x8727('0x63')],{})[_0x8727('0x2c')](respondWithResult(_0xb8e231,0xc9))[_0x8727('0x40')](handleError(_0xb8e231,null));};exports['update']=function(_0x29da1c,_0x56a275){if(_0x29da1c[_0x8727('0x63')]['id']){delete _0x29da1c['body']['id'];}_0x29da1c['body'][_0x8727('0x43')]=widgetAttributes(_0x29da1c[_0x8727('0x63')]);return db[_0x8727('0x35')][_0x8727('0x3f')]({'where':{'id':_0x29da1c[_0x8727('0x32')]['id']}})['then'](handleEntityNotFound(_0x56a275,null))['then'](saveUpdates(_0x29da1c[_0x8727('0x63')],null))[_0x8727('0x2c')](respondWithResult(_0x56a275,null))['catch'](handleError(_0x56a275,null));};