@@ -1,21 +1,33 @@
|
||||
import {
|
||||
Controller,
|
||||
Get,
|
||||
Post,
|
||||
Body,
|
||||
Param,
|
||||
UseGuards,
|
||||
Request,
|
||||
} from "@nestjs/common";
|
||||
import { WidgetsService } from "./widgets.service";
|
||||
import { WidgetDataService } from "./widget-data.service";
|
||||
import { AuthGuard } from "../auth/guards/auth.guard";
|
||||
import type {
|
||||
StatCardQueryDto,
|
||||
ChartQueryDto,
|
||||
ListQueryDto,
|
||||
CalendarPreviewQueryDto,
|
||||
} from "./dto";
|
||||
|
||||
/**
|
||||
* Controller for widget definition endpoints
|
||||
* Controller for widget definition and data endpoints
|
||||
* All endpoints require authentication
|
||||
* Provides read-only access to available widget definitions
|
||||
*/
|
||||
@Controller("widgets")
|
||||
@UseGuards(AuthGuard)
|
||||
export class WidgetsController {
|
||||
constructor(private readonly widgetsService: WidgetsService) {}
|
||||
constructor(
|
||||
private readonly widgetsService: WidgetsService,
|
||||
private readonly widgetDataService: WidgetDataService
|
||||
) {}
|
||||
|
||||
/**
|
||||
* GET /api/widgets
|
||||
@@ -36,4 +48,47 @@ export class WidgetsController {
|
||||
async findByName(@Param("name") name: string) {
|
||||
return this.widgetsService.findByName(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* POST /api/widgets/data/stat-card
|
||||
* Get stat card widget data
|
||||
*/
|
||||
@Post("data/stat-card")
|
||||
async getStatCardData(@Request() req: any, @Body() query: StatCardQueryDto) {
|
||||
const workspaceId = req.user?.currentWorkspaceId || req.user?.workspaceId;
|
||||
return this.widgetDataService.getStatCardData(workspaceId, query);
|
||||
}
|
||||
|
||||
/**
|
||||
* POST /api/widgets/data/chart
|
||||
* Get chart widget data
|
||||
*/
|
||||
@Post("data/chart")
|
||||
async getChartData(@Request() req: any, @Body() query: ChartQueryDto) {
|
||||
const workspaceId = req.user?.currentWorkspaceId || req.user?.workspaceId;
|
||||
return this.widgetDataService.getChartData(workspaceId, query);
|
||||
}
|
||||
|
||||
/**
|
||||
* POST /api/widgets/data/list
|
||||
* Get list widget data
|
||||
*/
|
||||
@Post("data/list")
|
||||
async getListData(@Request() req: any, @Body() query: ListQueryDto) {
|
||||
const workspaceId = req.user?.currentWorkspaceId || req.user?.workspaceId;
|
||||
return this.widgetDataService.getListData(workspaceId, query);
|
||||
}
|
||||
|
||||
/**
|
||||
* POST /api/widgets/data/calendar-preview
|
||||
* Get calendar preview widget data
|
||||
*/
|
||||
@Post("data/calendar-preview")
|
||||
async getCalendarPreviewData(
|
||||
@Request() req: any,
|
||||
@Body() query: CalendarPreviewQueryDto
|
||||
) {
|
||||
const workspaceId = req.user?.currentWorkspaceId || req.user?.workspaceId;
|
||||
return this.widgetDataService.getCalendarPreviewData(workspaceId, query);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user