category
This commit is contained in:
@@ -1,20 +0,0 @@
|
||||
import { Controller, Get, Param } from '@nestjs/common';
|
||||
import { RestaurantsService } from '../providers/restaurants.service';
|
||||
import { RestaurantSpecificationDto } from '../dto/restaurant-specification.dto';
|
||||
import { ApiTags, ApiOperation, ApiOkResponse, ApiParam, ApiNotFoundResponse } from '@nestjs/swagger';
|
||||
|
||||
@ApiTags('public/restaurants')
|
||||
@Controller('public/restaurants')
|
||||
export class PublicRestaurantController {
|
||||
constructor(private readonly restaurantsService: RestaurantsService) {}
|
||||
|
||||
@Get(':slug')
|
||||
@ApiOperation({ summary: 'Get restaurant specification by slug' })
|
||||
@ApiParam({ name: 'slug', required: true, description: 'Restaurant slug' })
|
||||
@ApiOkResponse({ type: RestaurantSpecificationDto, description: 'Restaurant specification found' })
|
||||
@ApiNotFoundResponse({ description: 'Restaurant not found' })
|
||||
findBySlug(@Param('slug') slug: string): Promise<RestaurantSpecificationDto> {
|
||||
return this.restaurantsService.getRestaurantSpecification(slug);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
import { Controller, Get, Param } from '@nestjs/common';
|
||||
import { ScheduleService } from '../providers/schedule.service';
|
||||
import { Schedule } from '../entities/schedule.entity';
|
||||
import { ApiTags, ApiOperation, ApiOkResponse, ApiParam } from '@nestjs/swagger';
|
||||
|
||||
@ApiTags('public/schedules')
|
||||
@Controller('public/schedules')
|
||||
export class PublicScheduleController {
|
||||
constructor(private readonly scheduleService: ScheduleService) {}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
@@ -3,17 +3,33 @@ import { RestaurantsService } from '../providers/restaurants.service';
|
||||
import { CreateRestaurantDto } from '../dto/create-restaurant.dto';
|
||||
import { UpdateRestaurantDto } from '../dto/update-restaurant.dto';
|
||||
import { AdminAuthGuard } from 'src/modules/auth/guards/adminAuth.guard';
|
||||
import { ApiBearerAuth, ApiBody, ApiNotFoundResponse, ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
|
||||
import {
|
||||
ApiBearerAuth,
|
||||
ApiBody,
|
||||
ApiNotFoundResponse,
|
||||
ApiOperation,
|
||||
ApiParam,
|
||||
ApiResponse,
|
||||
ApiTags,
|
||||
} from '@nestjs/swagger';
|
||||
import { RestId } from 'src/common/decorators';
|
||||
|
||||
@UseGuards(AdminAuthGuard)
|
||||
@ApiBearerAuth()
|
||||
@ApiTags('admin/restaurants')
|
||||
@Controller('admin/restaurants')
|
||||
@ApiTags('restaurants')
|
||||
@Controller()
|
||||
export class RestaurantsController {
|
||||
constructor(private readonly restaurantsService: RestaurantsService) {}
|
||||
|
||||
@Post()
|
||||
@Get('public/restaurants/:slug')
|
||||
@ApiOperation({ summary: 'Get restaurant specification by slug' })
|
||||
@ApiParam({ name: 'slug', required: true, description: 'Restaurant slug' })
|
||||
@ApiNotFoundResponse({ description: 'Restaurant not found' })
|
||||
findBySlug(@Param('slug') slug: string) {
|
||||
return this.restaurantsService.getRestaurantSpecification(slug);
|
||||
}
|
||||
|
||||
@UseGuards(AdminAuthGuard)
|
||||
@ApiBearerAuth()
|
||||
@Post('admin/restaurants')
|
||||
@ApiOperation({ summary: 'Create a new restaurant' })
|
||||
@ApiBody({ type: CreateRestaurantDto })
|
||||
@ApiResponse({ status: 201, description: 'Restaurant created' })
|
||||
@@ -28,7 +44,9 @@ export class RestaurantsController {
|
||||
return this.restaurantsService.findAll();
|
||||
}
|
||||
|
||||
@UseGuards(AdminAuthGuard)
|
||||
@ApiBearerAuth()
|
||||
@ApiBearerAuth('admin/restaurants')
|
||||
@ApiOperation({ summary: 'Get restaurant by ID from request' })
|
||||
@ApiResponse({ status: 200, description: 'Restaurant found' })
|
||||
@ApiNotFoundResponse({ description: 'Restaurant not found' })
|
||||
@@ -37,31 +55,34 @@ export class RestaurantsController {
|
||||
return await this.restaurantsService.findOne(restId);
|
||||
}
|
||||
|
||||
@UseGuards(AdminAuthGuard)
|
||||
@ApiBearerAuth()
|
||||
@ApiOperation({ summary: 'Update a restaurant' })
|
||||
@ApiBody({ type: UpdateRestaurantDto })
|
||||
@ApiResponse({ status: 200, description: 'Restaurant updated' })
|
||||
@ApiNotFoundResponse({ type: NotFoundException, description: 'Restaurant not found' })
|
||||
@Patch(':id')
|
||||
@Patch('admin/restaurants/:id')
|
||||
update(@Param('id') id: string, @Body() updateRestaurantDto: UpdateRestaurantDto) {
|
||||
return this.restaurantsService.update(id, updateRestaurantDto);
|
||||
}
|
||||
|
||||
@UseGuards(AdminAuthGuard)
|
||||
@ApiBearerAuth()
|
||||
@ApiOperation({ summary: 'Update a restaurant' })
|
||||
@ApiBody({ type: UpdateRestaurantDto })
|
||||
@ApiResponse({ status: 200, description: 'Restaurant updated' })
|
||||
@ApiNotFoundResponse({ type: NotFoundException, description: 'Restaurant not found' })
|
||||
@Patch('my-restaurant')
|
||||
@Patch('admin/restaurants/my-restaurant')
|
||||
updateMyRestaurant(@RestId() restId: string, @Body() updateRestaurantDto: UpdateRestaurantDto) {
|
||||
return this.restaurantsService.update(restId, updateRestaurantDto);
|
||||
}
|
||||
|
||||
@UseGuards(AdminAuthGuard)
|
||||
@ApiBearerAuth()
|
||||
@ApiOperation({ summary: 'Delete a restaurant' })
|
||||
@ApiResponse({ status: 200, description: 'Restaurant deleted' })
|
||||
@ApiNotFoundResponse({ description: 'Restaurant not found' })
|
||||
@Delete(':id')
|
||||
@Delete('admin/restaurants/:id')
|
||||
remove(@Param('id') id: string) {
|
||||
return this.restaurantsService.remove(id);
|
||||
}
|
||||
|
||||
@@ -18,14 +18,22 @@ import { Schedule } from '../entities/schedule.entity';
|
||||
import { AdminAuthGuard } from 'src/modules/auth/guards/adminAuth.guard';
|
||||
import { RestId } from 'src/common/decorators/rest-id.decorator';
|
||||
|
||||
@UseGuards(AdminAuthGuard)
|
||||
@ApiBearerAuth()
|
||||
@ApiTags('admin/schedules')
|
||||
@Controller('admin/schedules')
|
||||
@ApiTags('schedules')
|
||||
@Controller()
|
||||
export class ScheduleController {
|
||||
constructor(private readonly scheduleService: ScheduleService) {}
|
||||
|
||||
@Post()
|
||||
@Get('public/schedules/restaurant/:slug/today')
|
||||
@ApiOperation({ summary: 'Get today schedule of a restaurant' })
|
||||
@ApiParam({ name: 'slug', description: 'Restaurant Slug' })
|
||||
@ApiOkResponse({ description: 'Today schedule of the restaurant', type: Schedule })
|
||||
async getTodaySchedules(@Param('slug') slug: string): Promise<Schedule | null> {
|
||||
return this.scheduleService.findTodaySchedules(slug);
|
||||
}
|
||||
|
||||
@UseGuards(AdminAuthGuard)
|
||||
@ApiBearerAuth()
|
||||
@Post('admin/schedules')
|
||||
@ApiOperation({ summary: 'Create a new schedule' })
|
||||
@ApiBody({ type: CreateScheduleDto })
|
||||
@ApiCreatedResponse({ description: 'Schedule created successfully', type: Schedule })
|
||||
@@ -33,7 +41,9 @@ export class ScheduleController {
|
||||
return this.scheduleService.create(restId, createScheduleDto);
|
||||
}
|
||||
|
||||
@Get()
|
||||
@UseGuards(AdminAuthGuard)
|
||||
@ApiBearerAuth()
|
||||
@Get('admin/schedules')
|
||||
@ApiOperation({ summary: 'Get all schedules' })
|
||||
@ApiQuery({
|
||||
name: 'weekDay',
|
||||
@@ -49,7 +59,9 @@ export class ScheduleController {
|
||||
return this.scheduleService.findAll(restId, query);
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
@UseGuards(AdminAuthGuard)
|
||||
@ApiBearerAuth()
|
||||
@Get('admin/schedules/:id')
|
||||
@ApiOperation({ summary: 'Get a schedule by ID' })
|
||||
@ApiParam({ name: 'id', description: 'Schedule ID' })
|
||||
@ApiOkResponse({ description: 'Schedule details', type: Schedule })
|
||||
@@ -58,7 +70,9 @@ export class ScheduleController {
|
||||
return this.scheduleService.findOne(id, restId);
|
||||
}
|
||||
|
||||
@Patch(':id')
|
||||
@UseGuards(AdminAuthGuard)
|
||||
@ApiBearerAuth()
|
||||
@Patch('admin/schedules/:id')
|
||||
@ApiOperation({ summary: 'Update a schedule' })
|
||||
@ApiParam({ name: 'id', description: 'Schedule ID' })
|
||||
@ApiBody({ type: UpdateScheduleDto })
|
||||
@@ -68,7 +82,9 @@ export class ScheduleController {
|
||||
return this.scheduleService.update(id, restId, updateScheduleDto);
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
@UseGuards(AdminAuthGuard)
|
||||
@ApiBearerAuth()
|
||||
@Delete('admin/schedules/:id')
|
||||
@ApiOperation({ summary: 'Delete a schedule' })
|
||||
@ApiParam({ name: 'id', description: 'Schedule ID' })
|
||||
@ApiOkResponse({ description: 'Schedule deleted successfully' })
|
||||
|
||||
@@ -7,6 +7,8 @@ import { CreateScheduleDto } from '../dto/create-schedule.dto';
|
||||
import { UpdateScheduleDto } from '../dto/update-schedule.dto';
|
||||
import { FindSchedulesDto } from '../dto/find-schedules.dto';
|
||||
import { RestRepository } from '../repositories/rest.repository';
|
||||
import { Restaurant } from '../entities/restaurant.entity';
|
||||
import { RestMessage } from 'src/common/enums/message.enum';
|
||||
// import { RestMessage } from 'src/common/enums/message.enum';
|
||||
|
||||
@Injectable()
|
||||
@@ -46,12 +48,16 @@ export class ScheduleService {
|
||||
return this.scheduleRepository.find(where, { orderBy: { weekDay: 'asc' } });
|
||||
}
|
||||
|
||||
async findTodaySchedules(restId: string): Promise<Schedule | null> {
|
||||
async findTodaySchedules(slug: string): Promise<Schedule | null> {
|
||||
const restaurant = await this.em.findOne(Restaurant, { slug });
|
||||
if (!restaurant) {
|
||||
throw new NotFoundException(RestMessage.NOT_FOUND);
|
||||
}
|
||||
const today = new Date();
|
||||
const weekDay = today.getDay(); // 0 = Sunday, 6 = Saturday
|
||||
|
||||
const where: FilterQuery<Schedule> = {
|
||||
restId,
|
||||
restId: restaurant.id.toString(),
|
||||
weekDay,
|
||||
isActive: true,
|
||||
};
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { Module, forwardRef } from '@nestjs/common';
|
||||
import { RestaurantsService } from './providers/restaurants.service';
|
||||
import { RestaurantsController } from './controllers/restaurants.controller';
|
||||
import { PublicRestaurantController } from './controllers/public-restaurant.controller';
|
||||
import { MikroOrmModule } from '@mikro-orm/nestjs';
|
||||
import { Restaurant } from './entities/restaurant.entity';
|
||||
import { RestRepository } from './repositories/rest.repository';
|
||||
@@ -9,12 +8,11 @@ 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, PublicScheduleController],
|
||||
controllers: [RestaurantsController, ScheduleController],
|
||||
providers: [RestaurantsService, RestRepository, ScheduleRepository, ScheduleService],
|
||||
imports: [MikroOrmModule.forFeature([Restaurant, Schedule]), JwtModule, forwardRef(() => AuthModule)],
|
||||
exports: [RestRepository, ScheduleRepository, ScheduleService],
|
||||
|
||||
Reference in New Issue
Block a user