rest today schedule
This commit is contained in:
@@ -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 { Injectable, NotFoundException } from '@nestjs/common';
|
||||||
import { EntityManager, RequiredEntityData } from '@mikro-orm/postgresql';
|
import { EntityManager, RequiredEntityData } from '@mikro-orm/postgresql';
|
||||||
|
import { FilterQuery } from '@mikro-orm/core';
|
||||||
import { Schedule } from '../entities/schedule.entity';
|
import { Schedule } from '../entities/schedule.entity';
|
||||||
import { ScheduleRepository } from '../repositories/schedule.repository';
|
import { ScheduleRepository } from '../repositories/schedule.repository';
|
||||||
import { CreateScheduleDto } from '../dto/create-schedule.dto';
|
import { CreateScheduleDto } from '../dto/create-schedule.dto';
|
||||||
@@ -36,15 +37,27 @@ export class ScheduleService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async findAll(restId?: string, query?: FindSchedulesDto): Promise<Schedule[]> {
|
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;
|
where.weekDay = query.weekDay;
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.scheduleRepository.find(where, { orderBy: { weekDay: 'asc' } });
|
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> {
|
async findOne(id: string, restId: string): Promise<Schedule> {
|
||||||
const schedule = await this.scheduleRepository.findOne({ id, restId });
|
const schedule = await this.scheduleRepository.findOne({ id, restId });
|
||||||
if (!schedule) {
|
if (!schedule) {
|
||||||
|
|||||||
@@ -9,11 +9,12 @@ import { ScheduleRepository } from './repositories/schedule.repository';
|
|||||||
import { Schedule } from './entities/schedule.entity';
|
import { Schedule } from './entities/schedule.entity';
|
||||||
import { ScheduleService } from './providers/schedule.service';
|
import { ScheduleService } from './providers/schedule.service';
|
||||||
import { ScheduleController } from './controllers/schedule.controller';
|
import { ScheduleController } from './controllers/schedule.controller';
|
||||||
|
import { PublicScheduleController } from './controllers/public-schedule.controller';
|
||||||
import { JwtModule } from '@nestjs/jwt';
|
import { JwtModule } from '@nestjs/jwt';
|
||||||
import { AuthModule } from '../auth/auth.module';
|
import { AuthModule } from '../auth/auth.module';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
controllers: [RestaurantsController, PublicRestaurantController, ScheduleController],
|
controllers: [RestaurantsController, PublicRestaurantController, ScheduleController, PublicScheduleController],
|
||||||
providers: [RestaurantsService, RestRepository, ScheduleRepository, ScheduleService],
|
providers: [RestaurantsService, RestRepository, ScheduleRepository, ScheduleService],
|
||||||
imports: [MikroOrmModule.forFeature([Restaurant, Schedule]), JwtModule, forwardRef(() => AuthModule)],
|
imports: [MikroOrmModule.forFeature([Restaurant, Schedule]), JwtModule, forwardRef(() => AuthModule)],
|
||||||
exports: [RestRepository, ScheduleRepository, ScheduleService],
|
exports: [RestRepository, ScheduleRepository, ScheduleService],
|
||||||
|
|||||||
Reference in New Issue
Block a user