Spaces:
Running
Running
| import { | |
| Controller, | |
| Get, | |
| Post, | |
| Delete, | |
| Body, | |
| Param, | |
| Query, | |
| UseGuards, | |
| Request, | |
| HttpCode, | |
| HttpStatus, | |
| ParseIntPipe, | |
| Inject, | |
| forwardRef, | |
| } from "@nestjs/common"; | |
| import { SymptomsService } from "./symptoms.service"; | |
| import { CreateSymptomDto } from "./dto/create-symptom.dto"; | |
| import { JwtAuthGuard } from "../auth/guards/jwt-auth.guard"; | |
| import { HealthAssessmentService } from "../care-priority/health-assessment.service"; | |
| ("symptoms") | |
| (JwtAuthGuard) | |
| export class SymptomsController { | |
| constructor( | |
| private readonly symptomsService: SymptomsService, | |
| (forwardRef(() => HealthAssessmentService)) | |
| private readonly healthAssessmentService: HealthAssessmentService | |
| ) {} | |
| () | |
| (HttpStatus.CREATED) | |
| async create( | |
| () req: any, | |
| () createSymptomDto: CreateSymptomDto | |
| ) { | |
| const userId = req.user.id; | |
| const symptom = await this.symptomsService.create(userId, createSymptomDto); | |
| // Trigger health assessment and notifications | |
| this.healthAssessmentService.assessAndNotify(userId); | |
| return symptom; | |
| } | |
| /** | |
| * Get all symptoms for authenticated user | |
| * | |
| * @param req - Request with authenticated user | |
| * @param limit - Optional limit (default: 100) | |
| * @returns Array of symptom records | |
| */ | |
| () | |
| (HttpStatus.OK) | |
| async getSymptoms( | |
| () req: any, | |
| ("limit", new ParseIntPipe({ optional: true })) limit?: number | |
| ) { | |
| const userId = req.user.id; | |
| return this.symptomsService.findByUserId(userId, limit); | |
| } | |
| /** | |
| * Get recent symptoms (last 48 hours by default) | |
| * | |
| * @param req - Request with authenticated user | |
| * @param hours - Number of hours to look back | |
| * @returns Array of recent symptom records | |
| */ | |
| ("recent") | |
| (HttpStatus.OK) | |
| async getRecent( | |
| () req: any, | |
| ("hours", new ParseIntPipe({ optional: true })) hours?: number | |
| ) { | |
| const userId = req.user.id; | |
| return this.symptomsService.getRecentSymptoms(userId, hours); | |
| } | |
| /** | |
| * Delete a symptom record | |
| * | |
| * @param req - Request with authenticated user | |
| * @param id - Symptom record ID | |
| * @returns Success message | |
| */ | |
| (":id") | |
| (HttpStatus.OK) | |
| async delete(() req: any, ("id") id: string) { | |
| const userId = req.user.id; | |
| return this.symptomsService.delete(id, userId); | |
| } | |
| } | |