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 { ScheduleService } from '../providers/schedule.service';
import { Schedule } from '../entities/schedule.entity'; import { Schedule } from '../entities/schedule.entity';
import { ApiTags, ApiOperation, ApiOkResponse } from '@nestjs/swagger'; import { ApiTags, ApiOperation, ApiOkResponse, ApiParam } from '@nestjs/swagger';
@ApiTags('schedules') @ApiTags('schedules')
@Controller('schedules') @Controller('schedules')
export class PublicScheduleController { export class PublicScheduleController {
constructor(private readonly scheduleService: ScheduleService) {} constructor(private readonly scheduleService: ScheduleService) {}
@Get('today') @Get(':restId/today')
@ApiOperation({ summary: 'Get all today schedules of restaurants' }) @ApiOperation({ summary: 'Get today schedule of a restaurant' })
@ApiOkResponse({ description: 'List of today schedules', type: [Schedule] }) @ApiParam({ name: 'restId', description: 'Restaurant ID' })
async getTodaySchedules(): Promise<Schedule[]> { @ApiOkResponse({ description: 'Today schedule of the restaurant', type: Schedule })
return await this.scheduleService.findTodaySchedules(); 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' } }); return this.scheduleRepository.find(where, { orderBy: { weekDay: 'asc' } });
} }
async findTodaySchedules(): Promise<Schedule[]> { async findTodaySchedules(restId: string): Promise<Schedule | null> {
const today = new Date(); const today = new Date();
const weekDay = today.getDay(); // 0 = Sunday, 6 = Saturday const weekDay = today.getDay(); // 0 = Sunday, 6 = Saturday
const where: FilterQuery<Schedule> = { const where: FilterQuery<Schedule> = {
restId,
weekDay, weekDay,
isActive: true, isActive: true,
}; };
return this.scheduleRepository.find(where, { orderBy: { openTime: 'asc' } }); return this.scheduleRepository.findOne(where);
} }
async findOne(id: string, restId: string): Promise<Schedule> { async findOne(id: string, restId: string): Promise<Schedule> {