Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 | import { Controller, Get, Post, Put, Delete, Param, Body, Query, Req, } from '@nestjs/common'; import { WidgetService } from './widget.service'; import { ApiTags, ApiOperation, ApiResponse } from '@nestjs/swagger'; @Controller('api/v1') @ApiTags('Widget') export class WidgetController { constructor(private readonly widgetService: WidgetService) {} private getContext(req: any) { const tenantId = req.user?.tenantId || req.headers['x-tenant-id'] || 'SYSTEM'; const userId = req.user?.id || req.headers['x-user-id'] || 'system-user-id'; return { tenantId, userId }; } @Get('widget-catalog') @ApiOperation({ summary: 'Get catalog operation' }) @ApiResponse({ status: 200, description: 'Operation successful' }) async getCatalog() { return this.widgetService.getCatalog(); } @Get('dashboards') @ApiOperation({ summary: 'Get dashboards operation' }) @ApiResponse({ status: 200, description: 'Operation successful' }) async getDashboards(@Req() req: any) { const ctx = this.getContext(req); return this.widgetService.getDashboards(ctx.tenantId, ctx.userId); } @Post('dashboards') @ApiOperation({ summary: 'Create dashboard operation' }) @ApiResponse({ status: 201, description: 'Operation successful' }) async createDashboard( @Body() body: { name: string; scope?: string; role?: string }, @Req() req: any, ) { const ctx = this.getContext(req); return this.widgetService.createDashboard({ ...body, tenantId: ctx.tenantId, userId: ctx.userId, }); } @Get('dashboards/:id') @ApiOperation({ summary: 'Get dashboard operation' }) @ApiResponse({ status: 200, description: 'Operation successful' }) async getDashboard(@Param('id') id: string, @Req() req: any) { const ctx = this.getContext(req); return this.widgetService.getDashboard(id, ctx.tenantId); } @Put('dashboards/:id') @ApiOperation({ summary: 'Update dashboard operation' }) @ApiResponse({ status: 200, description: 'Operation successful' }) async updateDashboard( @Param('id') id: string, @Body() body: { name?: string }, @Req() req: any, ) { const ctx = this.getContext(req); return this.widgetService.updateDashboard(id, ctx.tenantId, body); } @Put('dashboards/:id/layout') @ApiOperation({ summary: 'Update layout operation' }) @ApiResponse({ status: 200, description: 'Operation successful' }) async updateLayout( @Param('id') id: string, @Body() body: { gridPositions: any }, @Req() req: any, ) { const ctx = this.getContext(req); return this.widgetService.updateLayout( id, ctx.tenantId, body.gridPositions, ); } @Post('dashboards/:id/widgets') @ApiOperation({ summary: 'Add widget operation' }) @ApiResponse({ status: 201, description: 'Operation successful' }) async addWidget( @Param('id') id: string, @Body() body: { widgetKey: string; config?: any }, @Req() req: any, ) { const ctx = this.getContext(req); return this.widgetService.addWidget( id, ctx.tenantId, body.widgetKey, body.config, ); } @Put('dashboards/:id/widgets/:widgetId') @ApiOperation({ summary: 'Update widget operation' }) @ApiResponse({ status: 200, description: 'Operation successful' }) async updateWidget( @Param('id') id: string, @Param('widgetId') widgetId: string, @Body() body: any, ) { return this.widgetService.updateWidget(id, widgetId, body); } @Delete('dashboards/:id/widgets/:widgetId') @ApiOperation({ summary: 'Remove widget operation' }) @ApiResponse({ status: 200, description: 'Operation successful' }) async removeWidget( @Param('id') id: string, @Param('widgetId') widgetId: string, ) { return this.widgetService.removeWidget(id, widgetId); } @Post('dashboards/:id/clone') @ApiOperation({ summary: 'Clone dashboard operation' }) @ApiResponse({ status: 201, description: 'Operation successful' }) async cloneDashboard( @Param('id') id: string, @Body() body: { name: string }, @Req() req: any, ) { const ctx = this.getContext(req); return this.widgetService.cloneDashboard( id, ctx.tenantId, ctx.userId, body.name, ); } @Post('dashboards/:id/reset') @ApiOperation({ summary: 'Reset dashboard operation' }) @ApiResponse({ status: 201, description: 'Operation successful' }) async resetDashboard(@Param('id') id: string, @Req() req: any) { const ctx = this.getContext(req); return this.widgetService.resetDashboard(id, ctx.tenantId); } @Get('dashboards/:id/data') @ApiOperation({ summary: 'Get dashboard data operation' }) @ApiResponse({ status: 200, description: 'Operation successful' }) async getDashboardData( @Param('id') id: string, @Query('timeRange') timeRange: string, @Req() req: any, ) { const ctx = this.getContext(req); return this.widgetService.getDashboardData(id, ctx.tenantId, timeRange); } } |