import { Controller, Get, Query, Logger } from '@nestjs/common'; import { MasterdataService } from './masterdata.service'; @Controller('api/masterdata') export class MasterdataController { private readonly logger = new Logger(MasterdataController.name); constructor(private masterdata: MasterdataService) {} @Get('departments') async departments() { return this.masterdata.getDepartments(); } @Get('doctors') async doctors() { return this.masterdata.getDoctors(); } @Get('clinics') async clinics() { return this.masterdata.getClinics(); } // Available time slots for a doctor on a given date. // Computed from DoctorVisitSlot entities (doctor × clinic × dayOfWeek). // Returns 30-min slots within the doctor's visiting window for that day. // // GET /api/masterdata/slots?doctorId=xxx&date=2026-04-15 @Get('slots') async slots( @Query('doctorId') doctorId: string, @Query('date') date: string, ) { if (!doctorId || !date) return []; return this.masterdata.getAvailableSlots(doctorId, date); } // Force cache refresh (admin use) @Get('refresh') async refresh() { await this.masterdata.invalidateAll(); return { refreshed: true }; } }