eab91174db
Co-Authored-By: Claude <noreply@anthropic.com>
38 lines
1.2 KiB
TypeScript
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();
|
|
}
|
|
}
|