schedule bug
This commit is contained in:
@@ -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> {
|
||||
|
||||
Reference in New Issue
Block a user