From 14e0108f028bdadfdd6aca4fbcd0c9bc0a76b7ee Mon Sep 17 00:00:00 2001 From: Pavel Gnedov Date: Tue, 3 Oct 2023 07:04:15 +0700 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D1=8B=20=D0=B0=D0=B4=D1=80=D0=B5=D1=81=D0=B0=20?= =?UTF-8?q?=D0=B5=D0=BD=D0=B4=D0=BF=D0=BE=D0=B8=D0=BD=D1=82=D0=BE=D0=B2=20?= =?UTF-8?q?=D0=B8=20=D1=84=D0=BE=D1=80=D0=BC=D0=B0=D1=82=20=D0=B2=D0=BE?= =?UTF-8?q?=D0=B7=D0=B2=D1=80=D0=B0=D1=89=D0=B0=D0=B5=D0=BC=D1=8B=D1=85=20?= =?UTF-8?q?=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B=D1=85=20=D0=B8=D0=B7=20=D0=B2?= =?UTF-8?q?=D0=B8=D0=B4=D0=B6=D0=B5=D1=82=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/dashboards/dashboard.controller.ts | 2 +- .../src/dashboards/dashboards-data.service.ts | 14 +++----------- .../src/dashboards/interactive-widget-factory.ts | 10 ++++++++-- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/libs/event-emitter/src/dashboards/dashboard.controller.ts b/libs/event-emitter/src/dashboards/dashboard.controller.ts index a8889e8..013f769 100644 --- a/libs/event-emitter/src/dashboards/dashboard.controller.ts +++ b/libs/event-emitter/src/dashboards/dashboard.controller.ts @@ -3,7 +3,7 @@ import { DashboardsService } from './dashboards.service'; import { BadRequestErrorHandler, getOrAppErrorOrThrow } from '../utils/result'; import { DashboardsDataService } from './dashboards-data.service'; -@Controller('dashboard') +@Controller('api/dashboard') export class DashboardController { constructor( private dashboardsService: DashboardsService, diff --git a/libs/event-emitter/src/dashboards/dashboards-data.service.ts b/libs/event-emitter/src/dashboards/dashboards-data.service.ts index 4fab49f..74fe340 100644 --- a/libs/event-emitter/src/dashboards/dashboards-data.service.ts +++ b/libs/event-emitter/src/dashboards/dashboards-data.service.ts @@ -1,13 +1,7 @@ import { Injectable, Logger } from '@nestjs/common'; import { DashboardsService } from './dashboards.service'; import * as DashboardModel from '../models/dashboard'; -import { - AppError, - Result, - createAppError, - fail, - success, -} from '../utils/result'; +import { AppError, Result, createAppError, fail } from '../utils/result'; import { WidgetsCollectionService } from './widgets-collection.service'; export type WidgetWithData = { @@ -38,10 +32,8 @@ export class DashboardsDataService { ); if (loadRes.result) { isSuccess = true; - results.push({ - widget: widget, - data: loadRes.result, - }); + loadRes.result.widgetId = widget.id; + results.push(loadRes.result); } } if (!isSuccess) throw createAppError('CANNOT_LOAD_DATA'); diff --git a/libs/event-emitter/src/dashboards/interactive-widget-factory.ts b/libs/event-emitter/src/dashboards/interactive-widget-factory.ts index b426f93..7e8876e 100644 --- a/libs/event-emitter/src/dashboards/interactive-widget-factory.ts +++ b/libs/event-emitter/src/dashboards/interactive-widget-factory.ts @@ -1,4 +1,4 @@ -import { Result, AppError } from '../utils/result'; +import { Result, AppError, fail, success } from '../utils/result'; import { WidgetDataLoaderInterface } from './widget-data-loader-interface'; import { WidgetInterface } from './widget-interface'; @@ -16,7 +16,13 @@ export class InteractiveWidget dashboardParams: any, ): Promise> { const data = await this.dataLoader.load(dataLoaderParams, dashboardParams); - return data; + return data.error + ? fail(data.error) + : success({ + data: data.result, + widgetParams: widgetParams, + dashboardParams: dashboardParams, + }); } }