import { Body, Controller, Delete, Get, Param, Post, Put, Patch, Req, UnauthorizedException, } from '@nestjs/common'; import { CanvasService } from './canvas.service.js'; type AuthedRequest = { userId?: string }; type CanvasBody = { title?: string; format?: string; source?: string }; @Controller('channels/:id/canvas') export class CanvasController { constructor(private readonly canvas: CanvasService) {} private uid(req: AuthedRequest): string { const userId = req.userId ?? ''; if (!userId) throw new UnauthorizedException('missing user'); return userId; } @Get() get(@Req() req: AuthedRequest, @Param('id') channelId: string) { return this.canvas.get(channelId, this.uid(req)); } // share / replace (caller becomes the sharer) @Put() @Post() share( @Req() req: AuthedRequest, @Param('id') channelId: string, @Body() body: CanvasBody, ) { return this.canvas.share(channelId, this.uid(req), body ?? {}); } // update in place (original sharer only) @Patch() update( @Req() req: AuthedRequest, @Param('id') channelId: string, @Body() body: CanvasBody, ) { return this.canvas.update(channelId, this.uid(req), body ?? {}); } @Delete() remove(@Req() req: AuthedRequest, @Param('id') channelId: string) { return this.canvas.remove(channelId, this.uid(req)); } }