Files
HealthCarePregnant/pcm-platform/backend/src/modules/emotion/emotion.controller.ts
T
2026-06-18 09:48:05 +08:00

38 lines
1.2 KiB
TypeScript

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<EmotionCheckin> {
// 强制关联为当前登录孕妇患者 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<EmotionCheckin[]> {
return this.service.listByPatient(patientId);
}
@Get()
@RequireCaps('emotion:read')
async getAll(): Promise<EmotionCheckin[]> {
return this.service.listAll();
}
}