import { Controller, Post, Get, Body, Param } from '@nestjs/common'; import { EmotionService } from './emotion.service'; import { CreateEmotionDto, EmotionCheckin } from './emotion.types'; import { RequireCaps } from '../../common/auth/capabilities.decorator'; import { CurrentUser } from '../../common/auth/current-user.decorator'; import { RequestUser } from '../../common/auth/request-user'; @Controller('emotions') export class EmotionController { constructor(private readonly service: EmotionService) {} @Post() @RequireCaps('emotion:create') async create( @CurrentUser() user: RequestUser, @Body() dto: CreateEmotionDto, ): Promise { // 强制关联为当前登录孕妇患者 ID const patientId = user.role === 'patient' ? user.id : dto.patientId; return this.service.create({ ...dto, patientId, }); } @Get('patient/:patientId') @RequireCaps('emotion:read') async getByPatient(@Param('patientId') patientId: string): Promise { return this.service.listByPatient(patientId); } @Get() @RequireCaps('emotion:read') async getAll(): Promise { return this.service.listAll(); } }