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
@@ -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) {