import { Body, Controller, Get, Param, Put, Res, UseGuards } from '@nestjs/common'; import type { Response } from 'express'; import { JwtAuthGuard, AuthUser } from '../../common/guards/jwt-auth.guard'; import { PartnerPrimaryGuard } from '../../common/guards/partner-primary.guard'; import { CurrentUser } from '../../common/decorators/current-user.decorator'; import { ActivityPosterService } from './activity-poster.service'; import { ActivityPosterSelectionDto } from './dto/activity-poster.dto'; @Controller('partner/activity-posters') @UseGuards(JwtAuthGuard, PartnerPrimaryGuard) export class PartnerActivityPostersController { constructor(private readonly service: ActivityPosterService) {} @Get() list() { return this.service.listForPartner(); } @Get('selection') getSelection(@CurrentUser() user: AuthUser) { return this.service.getSelection(user.actorId); } @Put('selection') setSelection(@CurrentUser() user: AuthUser, @Body() dto: ActivityPosterSelectionDto) { const raw = dto.posterId?.trim(); const posterId = raw && /^\d+$/.test(raw) ? BigInt(raw) : null; return this.service.setSelection(user.actorId, posterId); } @Get(':id/image') async image(@CurrentUser() user: AuthUser, @Param('id') id: string, @Res() res: Response) { const { buffer, fileName } = await this.service.composeForPartner(user.actorId, BigInt(id)); res.setHeader('Content-Type', 'image/png'); res.setHeader('Content-Disposition', `attachment; filename="${fileName}"`); res.send(buffer); } }