schedule bug

This commit is contained in:
2025-11-22 16:03:03 +03:30
parent 23dc27e611
commit f30b1729d3
2 changed files with 11 additions and 9 deletions
@@ -1,17 +1,18 @@
import { Controller, Get } from '@nestjs/common';
import { Controller, Get, Param } from '@nestjs/common';
import { ScheduleService } from '../providers/schedule.service';
import { Schedule } from '../entities/schedule.entity';
import { ApiTags, ApiOperation, ApiOkResponse } from '@nestjs/swagger';
import { ApiTags, ApiOperation, ApiOkResponse, ApiParam } from '@nestjs/swagger';
@ApiTags('schedules')
@Controller('schedules')
export class PublicScheduleController {
constructor(private readonly scheduleService: ScheduleService) {}
@Get('today')
@ApiOperation({ summary: 'Get all today schedules of restaurants' })
@ApiOkResponse({ description: 'List of today schedules', type: [Schedule] })
async getTodaySchedules(): Promise<Schedule[]> {
return await this.scheduleService.findTodaySchedules();
@Get(':restId/today')
@ApiOperation({ summary: 'Get today schedule of a restaurant' })
@ApiParam({ name: 'restId', description: 'Restaurant ID' })
@ApiOkResponse({ description: 'Today schedule of the restaurant', type: Schedule })
async getTodaySchedules(@Param('restId') restId: string): Promise<Schedule | null> {
return await this.scheduleService.findTodaySchedules(restId);
}
}
@@ -46,16 +46,17 @@ export class ScheduleService {
return this.scheduleRepository.find(where, { orderBy: { weekDay: 'asc' } });
}
async findTodaySchedules(): Promise<Schedule[]> {
async findTodaySchedules(restId: string): Promise<Schedule | null> {
const today = new Date();
const weekDay = today.getDay(); // 0 = Sunday, 6 = Saturday
const where: FilterQuery<Schedule> = {
restId,
weekDay,
isActive: true,
};
return this.scheduleRepository.find(where, { orderBy: { openTime: 'asc' } });
return this.scheduleRepository.findOne(where);
}
async findOne(id: string, restId: string): Promise<Schedule> {