rest today schedule

This commit is contained in:
2025-11-22 14:52:36 +03:30
parent 7ad0e03162
commit af1028265d
3 changed files with 34 additions and 3 deletions
@@ -0,0 +1,17 @@
import { Controller, Get } from '@nestjs/common';
import { ScheduleService } from '../providers/schedule.service';
import { Schedule } from '../entities/schedule.entity';
import { ApiTags, ApiOperation, ApiOkResponse } 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();
}
}
@@ -1,5 +1,6 @@
import { Injectable, NotFoundException } from '@nestjs/common';
import { EntityManager, RequiredEntityData } from '@mikro-orm/postgresql';
import { FilterQuery } from '@mikro-orm/core';
import { Schedule } from '../entities/schedule.entity';
import { ScheduleRepository } from '../repositories/schedule.repository';
import { CreateScheduleDto } from '../dto/create-schedule.dto';
@@ -36,15 +37,27 @@ export class ScheduleService {
}
async findAll(restId?: string, query?: FindSchedulesDto): Promise<Schedule[]> {
const where: any = restId ? { restId } : {};
const where: FilterQuery<Schedule> = restId ? { restId } : {};
if (query?.weekDay) {
if (query?.weekDay !== undefined) {
where.weekDay = query.weekDay;
}
return this.scheduleRepository.find(where, { orderBy: { weekDay: 'asc' } });
}
async findTodaySchedules(): Promise<Schedule[]> {
const today = new Date();
const weekDay = today.getDay(); // 0 = Sunday, 6 = Saturday
const where: FilterQuery<Schedule> = {
weekDay,
isActive: true,
};
return this.scheduleRepository.find(where, { orderBy: { openTime: 'asc' } });
}
async findOne(id: string, restId: string): Promise<Schedule> {
const schedule = await this.scheduleRepository.findOne({ id, restId });
if (!schedule) {
@@ -9,11 +9,12 @@ import { ScheduleRepository } from './repositories/schedule.repository';
import { Schedule } from './entities/schedule.entity';
import { ScheduleService } from './providers/schedule.service';
import { ScheduleController } from './controllers/schedule.controller';
import { PublicScheduleController } from './controllers/public-schedule.controller';
import { JwtModule } from '@nestjs/jwt';
import { AuthModule } from '../auth/auth.module';
@Module({
controllers: [RestaurantsController, PublicRestaurantController, ScheduleController],
controllers: [RestaurantsController, PublicRestaurantController, ScheduleController, PublicScheduleController],
providers: [RestaurantsService, RestRepository, ScheduleRepository, ScheduleService],
imports: [MikroOrmModule.forFeature([Restaurant, Schedule]), JwtModule, forwardRef(() => AuthModule)],
exports: [RestRepository, ScheduleRepository, ScheduleService],