1f5640dbb8ea89652e5712029913313fcea51beb
[motion2.git] / server / api / dashboard / dashboard.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 _0xf737=['attrSerie3','web-report','attrReport','reportType','attrRefresh','stringify','addItem','DashboardId','DashboardItem','getItems','findOne','order','eml-format','rimraf','fast-json-patch','moment','bluebird','path','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','desk.js','querystring','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','../../config/environment','../../mysqldb','redis','defaults','socket.io-emitter','./dashboard.socket','register','status','end','json','count','offset','set','Content-Range','apply','save','update','destroy','get','CustomDashboards','UserProfileResource','then','stack','name','index','map','Dashboard','rawAttributes','type','model','keys','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','limit','query','sort','pick','filter','merge','where','VIRTUAL','options','includeAll','catch','show','find','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','userProfileId','autoAssociation','error','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','clone','params','include','updatedAt','omit','createdAt','attrUrl','attrs','value','https://','custom','attrPath','clock','attrHourFormat','attrTimezone','0.00','attrFontSize','attrMetric','total','attrVoiceQueues','multibar-chart','pie-chart','attrSerie1','attrSerie2'];(function(_0x26504a,_0x12c510){var _0x5337af=function(_0x1d1281){while(--_0x1d1281){_0x26504a['push'](_0x26504a['shift']());}};_0x5337af(++_0x12c510);}(_0xf737,0x1d8));var _0x7f73=function(_0xb681ec,_0x1a236f){_0xb681ec=_0xb681ec-0x0;var _0x41a6a2=_0xf737[_0xb681ec];return _0x41a6a2;};'use strict';var emlformat=require(_0x7f73('0x0'));var rimraf=require(_0x7f73('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0x7f73('0x2'));var rp=require('request-promise');var moment=require(_0x7f73('0x3'));var BPromise=require(_0x7f73('0x4'));var Mustache=require('mustache');var util=require('util');var path=require(_0x7f73('0x5'));var sox=require(_0x7f73('0x6'));var csv=require(_0x7f73('0x7'));var ejs=require(_0x7f73('0x8'));var fs=require('fs');var fs_extra=require(_0x7f73('0x9'));var _=require(_0x7f73('0xa'));var squel=require(_0x7f73('0xb'));var crypto=require(_0x7f73('0xc'));var jsforce=require('jsforce');var deskjs=require(_0x7f73('0xd'));var toCsv=require(_0x7f73('0x7'));var querystring=require(_0x7f73('0xe'));var Papa=require('papaparse');var Redis=require('ioredis');var authService=require('../../components/auth/service');var qs=require(_0x7f73('0xf'));var as=require(_0x7f73('0x10'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x7f73('0x11'))('api');var utils=require('../../config/utils');var config=require(_0x7f73('0x12'));var licenseUtil=require('../../config/license/util');var db=require(_0x7f73('0x13'))['db'];config[_0x7f73('0x14')]=_[_0x7f73('0x15')](config[_0x7f73('0x14')],{'host':'localhost','port':0x18eb});var socket=require(_0x7f73('0x16'))(new Redis(config['redis']));require(_0x7f73('0x17'))[_0x7f73('0x18')](socket);function respondWithStatusCode(_0x8f3e90,_0x333666){_0x333666=_0x333666||0xcc;return function(_0x2ad3eb){if(_0x2ad3eb){return _0x8f3e90['sendStatus'](_0x333666);}return _0x8f3e90[_0x7f73('0x19')](_0x333666)[_0x7f73('0x1a')]();};}function respondWithResult(_0x2b0cfe,_0x46b7bb){_0x46b7bb=_0x46b7bb||0xc8;return function(_0x15fbda){if(_0x15fbda){return _0x2b0cfe[_0x7f73('0x19')](_0x46b7bb)[_0x7f73('0x1b')](_0x15fbda);}};}function respondWithFilteredResult(_0x24ad5f,_0x2e83b8){return function(_0x1cbca3){if(_0x1cbca3){var _0x20fa07=_0x1cbca3[_0x7f73('0x1c')],_0x33ccde=_0x2e83b8[_0x7f73('0x1d')],_0x4f8230=_0x2e83b8['offset']+_0x2e83b8['limit'],_0x313add;if(_0x4f8230>=_0x20fa07){_0x4f8230=_0x20fa07;_0x313add=0xc8;}else{_0x313add=0xce;}_0x24ad5f[_0x7f73('0x19')](_0x313add);return _0x24ad5f[_0x7f73('0x1e')](_0x7f73('0x1f'),_0x33ccde+'-'+_0x4f8230+'/'+_0x20fa07)[_0x7f73('0x1b')](_0x1cbca3);}return null;};}function patchUpdates(_0x52dbd7){return function(_0x25a36f){try{jsonpatch[_0x7f73('0x20')](_0x25a36f,_0x52dbd7,!![]);}catch(_0x33759a){return BPromise['reject'](_0x33759a);}return _0x25a36f[_0x7f73('0x21')]();};}function saveUpdates(_0x4b6755,_0x1f064d){return function(_0x3cb2f9){if(_0x3cb2f9){return _0x3cb2f9[_0x7f73('0x22')](_0x4b6755)['then'](function(_0x3845c4){return _0x3845c4;});}return null;};}function removeEntity(_0x16a5ea,_0x30a3b0){return function(_0x1c68c2){if(_0x1c68c2){return _0x1c68c2[_0x7f73('0x23')]()['then'](function(){var _0x337d68=_0x1c68c2[_0x7f73('0x24')]({'plain':!![]});var _0x3575b7=_0x7f73('0x25');return db[_0x7f73('0x26')][_0x7f73('0x23')]({'where':{'type':_0x3575b7,'resourceId':_0x337d68['id']}})['then'](function(){return _0x1c68c2;});})[_0x7f73('0x27')](function(){_0x16a5ea[_0x7f73('0x19')](0xcc)[_0x7f73('0x1a')]();});}};}function handleEntityNotFound(_0x23f067,_0x5edfcf){return function(_0x4e6d5b){if(!_0x4e6d5b){_0x23f067['sendStatus'](0x194);}return _0x4e6d5b;};}function handleError(_0x206280,_0x499d6f){_0x499d6f=_0x499d6f||0x1f4;return function(_0x2789c4){logger['error'](_0x2789c4[_0x7f73('0x28')]);if(_0x2789c4['name']){delete _0x2789c4[_0x7f73('0x29')];}_0x206280[_0x7f73('0x19')](_0x499d6f)['send'](_0x2789c4);};}exports[_0x7f73('0x2a')]=function(_0x3f81b3,_0x20bbe1){var _0xd92d93={},_0x59462e={},_0x31bd90={'count':0x0,'rows':[]};var _0x3ac4ac=_[_0x7f73('0x2b')](db[_0x7f73('0x2c')][_0x7f73('0x2d')],function(_0x4ff95e){return{'name':_0x4ff95e['fieldName'],'type':_0x4ff95e[_0x7f73('0x2e')]['key']};});_0x59462e[_0x7f73('0x2f')]=_[_0x7f73('0x2b')](_0x3ac4ac,_0x7f73('0x29'));_0x59462e['query']=_[_0x7f73('0x30')](_0x3f81b3['query']);_0x59462e[_0x7f73('0x31')]=_[_0x7f73('0x32')](_0x59462e[_0x7f73('0x2f')],_0x59462e['query']);_0xd92d93[_0x7f73('0x33')]=_[_0x7f73('0x32')](_0x59462e[_0x7f73('0x2f')],qs[_0x7f73('0x34')](_0x3f81b3['query'][_0x7f73('0x34')]));_0xd92d93[_0x7f73('0x33')]=_0xd92d93[_0x7f73('0x33')][_0x7f73('0x35')]?_0xd92d93['attributes']:_0x59462e['model'];if(!_0x3f81b3['query'][_0x7f73('0x36')](_0x7f73('0x37'))){_0xd92d93[_0x7f73('0x38')]=qs[_0x7f73('0x38')](_0x3f81b3[_0x7f73('0x39')][_0x7f73('0x38')]);_0xd92d93[_0x7f73('0x1d')]=qs[_0x7f73('0x1d')](_0x3f81b3[_0x7f73('0x39')][_0x7f73('0x1d')]);}_0xd92d93['order']=qs[_0x7f73('0x3a')](_0x3f81b3[_0x7f73('0x39')][_0x7f73('0x3a')]);_0xd92d93['where']=qs[_0x7f73('0x31')](_[_0x7f73('0x3b')](_0x3f81b3[_0x7f73('0x39')],_0x59462e[_0x7f73('0x31')]),_0x3ac4ac);if(_0x3f81b3['query'][_0x7f73('0x3c')]){_0xd92d93['where']=_[_0x7f73('0x3d')](_0xd92d93[_0x7f73('0x3e')],{'$or':_[_0x7f73('0x2b')](_0x3ac4ac,function(_0xf2064e){if(_0xf2064e[_0x7f73('0x2e')]!==_0x7f73('0x3f')){var _0x8031f={};_0x8031f[_0xf2064e[_0x7f73('0x29')]]={'$like':'%'+_0x3f81b3[_0x7f73('0x39')][_0x7f73('0x3c')]+'%'};return _0x8031f;}})});}_0xd92d93=_[_0x7f73('0x3d')]({},_0xd92d93,_0x3f81b3[_0x7f73('0x40')]);var _0x4e8d9a={'where':_0xd92d93[_0x7f73('0x3e')]};return db['Dashboard'][_0x7f73('0x1c')](_0x4e8d9a)[_0x7f73('0x27')](function(_0x49da88){_0x31bd90[_0x7f73('0x1c')]=_0x49da88;if(_0x3f81b3[_0x7f73('0x39')][_0x7f73('0x41')]){_0xd92d93['include']=[{'all':!![]}];}return db[_0x7f73('0x2c')]['findAll'](_0xd92d93);})[_0x7f73('0x27')](function(_0x554bae){_0x31bd90['rows']=_0x554bae;return _0x31bd90;})['then'](respondWithFilteredResult(_0x20bbe1,_0xd92d93))[_0x7f73('0x42')](handleError(_0x20bbe1,null));};exports[_0x7f73('0x43')]=function(_0x2b8880,_0x267798){var _0x1ce01a={'raw':![],'where':{'id':_0x2b8880['params']['id']}},_0x5c28f0={};_0x5c28f0[_0x7f73('0x2f')]=_[_0x7f73('0x30')](db[_0x7f73('0x2c')][_0x7f73('0x2d')]);_0x5c28f0['query']=_[_0x7f73('0x30')](_0x2b8880[_0x7f73('0x39')]);_0x5c28f0[_0x7f73('0x31')]=_[_0x7f73('0x32')](_0x5c28f0[_0x7f73('0x2f')],_0x5c28f0[_0x7f73('0x39')]);_0x1ce01a[_0x7f73('0x33')]=_['intersection'](_0x5c28f0[_0x7f73('0x2f')],qs['fields'](_0x2b8880[_0x7f73('0x39')][_0x7f73('0x34')]));_0x1ce01a[_0x7f73('0x33')]=_0x1ce01a['attributes'][_0x7f73('0x35')]?_0x1ce01a[_0x7f73('0x33')]:_0x5c28f0[_0x7f73('0x2f')];if(_0x2b8880[_0x7f73('0x39')][_0x7f73('0x41')]){_0x1ce01a['include']=[{'all':!![]}];}_0x1ce01a=_['merge']({},_0x1ce01a,_0x2b8880[_0x7f73('0x40')]);return db[_0x7f73('0x2c')][_0x7f73('0x44')](_0x1ce01a)[_0x7f73('0x27')](handleEntityNotFound(_0x267798,null))[_0x7f73('0x27')](respondWithResult(_0x267798,null))['catch'](handleError(_0x267798,null));};exports[_0x7f73('0x45')]=function(_0x118e3c,_0x31308a){return db[_0x7f73('0x2c')]['create'](_0x118e3c[_0x7f73('0x46')],{})[_0x7f73('0x27')](function(_0x2f4fc5){var _0x11ee5f=_0x118e3c[_0x7f73('0x47')][_0x7f73('0x24')]({'plain':!![]});if(!_0x11ee5f)throw new Error(_0x7f73('0x48'));if(_0x11ee5f[_0x7f73('0x49')]===_0x7f73('0x47')){var _0x533154=_0x2f4fc5[_0x7f73('0x24')]({'plain':!![]});var _0x20b186=_0x7f73('0x25');return db[_0x7f73('0x4a')][_0x7f73('0x44')]({'where':{'name':_0x20b186,'userProfileId':_0x11ee5f[_0x7f73('0x4b')]},'raw':!![]})['then'](function(_0x4439c1){if(_0x4439c1&&_0x4439c1[_0x7f73('0x4c')]===0x0){return db[_0x7f73('0x26')][_0x7f73('0x45')]({'name':_0x533154['name'],'resourceId':_0x533154['id'],'type':_0x4439c1[_0x7f73('0x29')],'sectionId':_0x4439c1['id']},{})[_0x7f73('0x27')](function(){return _0x2f4fc5;});}else{return _0x2f4fc5;}})[_0x7f73('0x42')](function(_0x4485b4){logger[_0x7f73('0x4d')](_0x7f73('0x4e'),_0x4485b4);throw _0x4485b4;});}return _0x2f4fc5;})[_0x7f73('0x27')](respondWithResult(_0x31308a,0xc9))[_0x7f73('0x42')](handleError(_0x31308a,null));};exports[_0x7f73('0x4f')]=function(_0x4a6081,_0xb3bccb){var _0xdacd8a={'where':{'id':_0x4a6081[_0x7f73('0x50')]['id']}},_0x14cf8e={};_0x14cf8e[_0x7f73('0x2f')]=_[_0x7f73('0x30')](db[_0x7f73('0x2c')][_0x7f73('0x2d')]);_0xdacd8a[_0x7f73('0x33')]=_[_0x7f73('0x32')](_0x14cf8e['model'],qs[_0x7f73('0x34')](_0x4a6081['query'][_0x7f73('0x34')]));_0xdacd8a[_0x7f73('0x33')]=_0xdacd8a[_0x7f73('0x33')]['length']?_0xdacd8a[_0x7f73('0x33')]:_0x14cf8e[_0x7f73('0x2f')];if(_0x4a6081[_0x7f73('0x39')][_0x7f73('0x41')]){_0xdacd8a[_0x7f73('0x51')]=[{'all':!![]}];}_0xdacd8a=_['merge']({},_0xdacd8a,_0x4a6081[_0x7f73('0x40')]);return db['Dashboard'][_0x7f73('0x44')](_0xdacd8a)[_0x7f73('0x27')](handleEntityNotFound(_0xb3bccb,null))['then'](function(_0x57bfbb){if(_0x57bfbb){var _0x4f702=_0x57bfbb[_0x7f73('0x24')]({'plain':!![]});_0x4f702=qs['omit'](_0x4f702,['id','createdAt',_0x7f73('0x52')]);_0x4a6081[_0x7f73('0x46')]=_[_0x7f73('0x53')](_0x4a6081[_0x7f73('0x46')],['id',_0x7f73('0x54'),_0x7f73('0x52')]);return db[_0x7f73('0x2c')][_0x7f73('0x45')](_[_0x7f73('0x3d')](_0x4f702,_0x4a6081[_0x7f73('0x46')]),{'include':_0x4a6081[_0x7f73('0x39')][_0x7f73('0x41')]?[{'all':!![]}]:undefined})[_0x7f73('0x27')](function(_0x3824c8){var _0x450898=_0x4a6081[_0x7f73('0x47')][_0x7f73('0x24')]({'plain':!![]});if(!_0x450898)throw new Error(_0x7f73('0x48'));if(_0x450898[_0x7f73('0x49')]===_0x7f73('0x47')){var _0x31860e=_0x3824c8[_0x7f73('0x24')]({'plain':!![]});var _0x1636b2=_0x7f73('0x25');return db[_0x7f73('0x4a')][_0x7f73('0x44')]({'where':{'name':_0x1636b2,'userProfileId':_0x450898[_0x7f73('0x4b')]},'raw':!![]})[_0x7f73('0x27')](function(_0x2f5241){if(_0x2f5241&&_0x2f5241[_0x7f73('0x4c')]===0x0){return db[_0x7f73('0x26')][_0x7f73('0x45')]({'name':_0x31860e[_0x7f73('0x29')],'resourceId':_0x31860e['id'],'type':_0x2f5241[_0x7f73('0x29')],'sectionId':_0x2f5241['id']},{})['then'](function(){return _0x3824c8;});}else{return _0x3824c8;}})[_0x7f73('0x42')](function(_0x43439d){logger['error'](_0x7f73('0x4e'),_0x43439d);throw _0x43439d;});}return _0x3824c8;});}})[_0x7f73('0x27')](respondWithResult(_0xb3bccb,0xc9))[_0x7f73('0x42')](handleError(_0xb3bccb,null));};exports['update']=function(_0x5654ba,_0x168194){if(_0x5654ba['body']['id']){delete _0x5654ba['body']['id'];}return db['Dashboard']['find']({'where':{'id':_0x5654ba[_0x7f73('0x50')]['id']}})[_0x7f73('0x27')](handleEntityNotFound(_0x168194,null))['then'](saveUpdates(_0x5654ba[_0x7f73('0x46')],null))[_0x7f73('0x27')](respondWithResult(_0x168194,null))[_0x7f73('0x42')](handleError(_0x168194,null));};exports[_0x7f73('0x23')]=function(_0x5d9ea2,_0x144fe9){return db[_0x7f73('0x2c')][_0x7f73('0x44')]({'where':{'id':_0x5d9ea2['params']['id']}})[_0x7f73('0x27')](handleEntityNotFound(_0x144fe9,null))[_0x7f73('0x27')](removeEntity(_0x144fe9,null))[_0x7f73('0x42')](handleError(_0x144fe9,null));};function widgetAttributes(_0xd1c7b9){try{switch(_0xd1c7b9['type']){case'iframe':return[{'name':_0x7f73('0x55'),'value':_0xd1c7b9['attrUrl']||(_0xd1c7b9[_0x7f73('0x56')]&&_0xd1c7b9[_0x7f73('0x56')][0x0]?_0xd1c7b9['attrs'][0x0][_0x7f73('0x57')]:undefined)||_0x7f73('0x58')}];case _0x7f73('0x59'):return[{'name':_0x7f73('0x5a'),'value':_0xd1c7b9[_0x7f73('0x5a')]||(_0xd1c7b9['attrs']&&_0xd1c7b9[_0x7f73('0x56')][0x0]?_0xd1c7b9['attrs'][0x0][_0x7f73('0x57')]:undefined)||''}];case _0x7f73('0x5b'):return[{'name':'attrHourFormat','value':_0xd1c7b9[_0x7f73('0x5c')]||(_0xd1c7b9['attrs']&&_0xd1c7b9[_0x7f73('0x56')][0x0]?_0xd1c7b9['attrs'][0x0][_0x7f73('0x57')]:undefined)||'HH:mm:ss'},{'name':'attrTimezone','value':_0xd1c7b9[_0x7f73('0x5d')]||(_0xd1c7b9[_0x7f73('0x56')]&&_0xd1c7b9[_0x7f73('0x56')][0x1]?_0xd1c7b9['attrs'][0x1][_0x7f73('0x57')]:undefined)||_0x7f73('0x5e')},{'name':_0x7f73('0x5f'),'value':_0xd1c7b9['attrFontSize']||(_0xd1c7b9[_0x7f73('0x56')]&&_0xd1c7b9[_0x7f73('0x56')][0x2]?_0xd1c7b9['attrs'][0x2][_0x7f73('0x57')]:undefined)||0xc}];case'counter':return[{'name':_0x7f73('0x60'),'value':_0xd1c7b9['attrMetric']||(_0xd1c7b9[_0x7f73('0x56')]&&_0xd1c7b9[_0x7f73('0x56')][0x0]?_0xd1c7b9['attrs'][0x0][_0x7f73('0x57')]:undefined)||_0x7f73('0x61')},{'name':_0x7f73('0x62'),'value':_0xd1c7b9['attrVoiceQueues']||(_0xd1c7b9[_0x7f73('0x56')]&&_0xd1c7b9[_0x7f73('0x56')][0x1]?_0xd1c7b9[_0x7f73('0x56')][0x1][_0x7f73('0x57')]:undefined)||[]},{'name':'attrFontSize','value':_0xd1c7b9[_0x7f73('0x5f')]||(_0xd1c7b9[_0x7f73('0x56')]&&_0xd1c7b9[_0x7f73('0x56')][0x2]?_0xd1c7b9[_0x7f73('0x56')][0x2][_0x7f73('0x57')]:undefined)||0x14}];case _0x7f73('0x63'):case _0x7f73('0x64'):return[{'name':_0x7f73('0x65'),'value':_0xd1c7b9[_0x7f73('0x65')]||(_0xd1c7b9['attrs']&&_0xd1c7b9[_0x7f73('0x56')][0x0]?_0xd1c7b9['attrs'][0x0][_0x7f73('0x57')]:undefined)||_0x7f73('0x61')},{'name':_0x7f73('0x66'),'value':_0xd1c7b9[_0x7f73('0x66')]||(_0xd1c7b9[_0x7f73('0x56')]&&_0xd1c7b9[_0x7f73('0x56')][0x1]?_0xd1c7b9[_0x7f73('0x56')][0x1][_0x7f73('0x57')]:undefined)||null},{'name':_0x7f73('0x67'),'value':_0xd1c7b9[_0x7f73('0x67')]||(_0xd1c7b9['attrs']&&_0xd1c7b9[_0x7f73('0x56')][0x2]?_0xd1c7b9[_0x7f73('0x56')][0x2]['value']:undefined)||null},{'name':'attrVoiceQueues','value':_0xd1c7b9[_0x7f73('0x62')]||(_0xd1c7b9[_0x7f73('0x56')]&&_0xd1c7b9[_0x7f73('0x56')][0x3]?_0xd1c7b9[_0x7f73('0x56')][0x3]['value']:undefined)||[]}];case _0x7f73('0x68'):return[{'name':_0x7f73('0x69'),'type':_0xd1c7b9[_0x7f73('0x6a')]||(_0xd1c7b9[_0x7f73('0x56')]&&_0xd1c7b9[_0x7f73('0x56')][0x0]?_0xd1c7b9[_0x7f73('0x56')][0x0][_0x7f73('0x2e')]:undefined)||null,'value':_0xd1c7b9[_0x7f73('0x69')]||(_0xd1c7b9[_0x7f73('0x56')]&&_0xd1c7b9[_0x7f73('0x56')][0x0]?_0xd1c7b9['attrs'][0x0][_0x7f73('0x57')]:undefined)||null},{'name':_0x7f73('0x6b'),'value':_0xd1c7b9[_0x7f73('0x6b')]||(_0xd1c7b9[_0x7f73('0x56')]&&_0xd1c7b9[_0x7f73('0x56')][0x1]?_0xd1c7b9[_0x7f73('0x56')][0x1][_0x7f73('0x57')]:undefined)||0x0}];default:return[];}}catch(_0x1c3105){logger[_0x7f73('0x4d')]('widgetAttributes:\x20%s',JSON[_0x7f73('0x6c')](_0x1c3105));return[];}}exports[_0x7f73('0x6d')]=function(_0x1b6a92,_0xd48632,_0x45a195){if(_0x1b6a92['body']['id']){delete _0x1b6a92[_0x7f73('0x46')]['id'];}return db['Dashboard'][_0x7f73('0x44')]({'where':{'id':_0x1b6a92[_0x7f73('0x50')]['id']}})[_0x7f73('0x27')](handleEntityNotFound(_0xd48632,null))[_0x7f73('0x27')](function(_0x9c5f0b){if(_0x9c5f0b){_0x1b6a92[_0x7f73('0x46')][_0x7f73('0x6e')]=_0x9c5f0b['id'];_0x1b6a92[_0x7f73('0x46')]['attrs']=widgetAttributes(_0x1b6a92['body']);return db[_0x7f73('0x6f')]['create'](_0x1b6a92['body']);}})[_0x7f73('0x27')](respondWithResult(_0xd48632,null))[_0x7f73('0x42')](handleError(_0xd48632,null));};exports[_0x7f73('0x70')]=function(_0x2dc774,_0x3218c1,_0x56c507){var _0x414479={};var _0x16c009={};var _0x392815;var _0x4e227c;return db[_0x7f73('0x2c')][_0x7f73('0x71')]({'where':{'id':_0x2dc774[_0x7f73('0x50')]['id']}})['then'](handleEntityNotFound(_0x3218c1,null))[_0x7f73('0x27')](function(_0x617fb2){if(_0x617fb2){_0x392815=_0x617fb2;_0x16c009[_0x7f73('0x2f')]=_[_0x7f73('0x30')](db['DashboardItem'][_0x7f73('0x2d')]);_0x16c009[_0x7f73('0x39')]=_[_0x7f73('0x30')](_0x2dc774['query']);_0x16c009['filters']=_[_0x7f73('0x32')](_0x16c009[_0x7f73('0x2f')],_0x16c009[_0x7f73('0x39')]);_0x414479['attributes']=_['intersection'](_0x16c009[_0x7f73('0x2f')],qs[_0x7f73('0x34')](_0x2dc774[_0x7f73('0x39')][_0x7f73('0x34')]));_0x414479['attributes']=_0x414479[_0x7f73('0x33')][_0x7f73('0x35')]?_0x414479[_0x7f73('0x33')]:_0x16c009[_0x7f73('0x2f')];_0x414479[_0x7f73('0x72')]=qs['sort'](_0x2dc774[_0x7f73('0x39')][_0x7f73('0x3a')]);_0x414479[_0x7f73('0x3e')]=qs[_0x7f73('0x31')](_['pick'](_0x2dc774['query'],_0x16c009[_0x7f73('0x31')]));if(_0x2dc774['query'][_0x7f73('0x3c')]){_0x414479['where']=_[_0x7f73('0x3d')](_0x414479[_0x7f73('0x3e')],{'$or':_[_0x7f73('0x2b')](_0x414479[_0x7f73('0x33')],function(_0x2795bb){var _0x3da06a={};_0x3da06a[_0x2795bb]={'$like':'%'+_0x2dc774[_0x7f73('0x39')][_0x7f73('0x3c')]+'%'};return _0x3da06a;})});}_0x414479=_[_0x7f73('0x3d')]({},_0x414479,_0x2dc774['options']);return _0x392815[_0x7f73('0x70')](_0x414479);}})[_0x7f73('0x27')](function(_0x2eb18c){if(_0x2eb18c){_0x4e227c=_0x2eb18c[_0x7f73('0x35')];if(!_0x2dc774[_0x7f73('0x39')][_0x7f73('0x36')]('nolimit')){_0x414479[_0x7f73('0x38')]=qs[_0x7f73('0x38')](_0x2dc774[_0x7f73('0x39')][_0x7f73('0x38')]);_0x414479[_0x7f73('0x1d')]=qs[_0x7f73('0x1d')](_0x2dc774[_0x7f73('0x39')][_0x7f73('0x1d')]);}return _0x392815[_0x7f73('0x70')](_0x414479);}})['then'](function(_0x18107c){if(_0x18107c){return _0x18107c?{'count':_0x4e227c,'rows':_0x18107c}:null;}})['then'](respondWithResult(_0x3218c1,null))[_0x7f73('0x42')](handleError(_0x3218c1,null));};