import { Body, Controller, Post, UseGuards } from '@nestjs/common'; import { FeedbackService } from './feedback.service'; import { AuthGuard } from '../common/auth.guard'; import { CurrentUser } from '../common/current-user.decorator'; import { IsOptional, IsString, MaxLength, MinLength } from 'class-validator'; class FeedbackBody { @IsString() @MinLength(1, { message: '留言内容不能为空' }) @MaxLength(1000, { message: '留言内容不能超过 1000 字' }) content: string; @IsOptional() @IsString() @MaxLength(100, { message: '联系方式不能超过 100 字' }) contact?: string; } @Controller('api/feedback') @UseGuards(AuthGuard) export class FeedbackController { constructor(private readonly svc: FeedbackService) {} @Post() submit( @CurrentUser() u: { openid: string }, @Body() body: FeedbackBody, ) { return this.svc.submit(u.openid, body.content, body.contact); } }