Files
dukang/server/dukang-api/src/modules/ops/partner-activity-posters.controller.ts
T
jacy 3166467518 feat(ops): v4.0.2 活动图模板、合伙人选择持久化与用户管理主图
HQ 上传底图与码栏;合伙人单选写入 partner_account.activity_poster_id,用户管理下次登录仍显示同一张图。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-30 21:36:43 +08:00

39 lines
1.5 KiB
TypeScript

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);
}
}