This commit is contained in:
2025-11-25 10:08:34 +03:30
parent a5992d8e29
commit d737b3dc24
7 changed files with 64 additions and 63 deletions
@@ -17,8 +17,6 @@ import { AdminAuthGuard } from 'src/modules/auth/guards/adminAuth.guard';
import { UseGuards } from '@nestjs/common'; import { UseGuards } from '@nestjs/common';
import { RestId } from 'src/common/decorators'; import { RestId } from 'src/common/decorators';
@UseGuards(AdminAuthGuard)
@ApiBearerAuth()
@ApiTags('category') @ApiTags('category')
@Controller() @Controller()
export class CategoryController { export class CategoryController {
@@ -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 { CreateRestaurantDto } from '../dto/create-restaurant.dto';
import { UpdateRestaurantDto } from '../dto/update-restaurant.dto'; import { UpdateRestaurantDto } from '../dto/update-restaurant.dto';
import { AdminAuthGuard } from 'src/modules/auth/guards/adminAuth.guard'; 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'; import { RestId } from 'src/common/decorators';
@UseGuards(AdminAuthGuard) @ApiTags('restaurants')
@ApiBearerAuth() @Controller()
@ApiTags('admin/restaurants')
@Controller('admin/restaurants')
export class RestaurantsController { export class RestaurantsController {
constructor(private readonly restaurantsService: RestaurantsService) {} 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' }) @ApiOperation({ summary: 'Create a new restaurant' })
@ApiBody({ type: CreateRestaurantDto }) @ApiBody({ type: CreateRestaurantDto })
@ApiResponse({ status: 201, description: 'Restaurant created' }) @ApiResponse({ status: 201, description: 'Restaurant created' })
@@ -28,7 +44,9 @@ export class RestaurantsController {
return this.restaurantsService.findAll(); return this.restaurantsService.findAll();
} }
@UseGuards(AdminAuthGuard)
@ApiBearerAuth() @ApiBearerAuth()
@ApiBearerAuth('admin/restaurants')
@ApiOperation({ summary: 'Get restaurant by ID from request' }) @ApiOperation({ summary: 'Get restaurant by ID from request' })
@ApiResponse({ status: 200, description: 'Restaurant found' }) @ApiResponse({ status: 200, description: 'Restaurant found' })
@ApiNotFoundResponse({ description: 'Restaurant not found' }) @ApiNotFoundResponse({ description: 'Restaurant not found' })
@@ -37,31 +55,34 @@ export class RestaurantsController {
return await this.restaurantsService.findOne(restId); return await this.restaurantsService.findOne(restId);
} }
@UseGuards(AdminAuthGuard)
@ApiBearerAuth() @ApiBearerAuth()
@ApiOperation({ summary: 'Update a restaurant' }) @ApiOperation({ summary: 'Update a restaurant' })
@ApiBody({ type: UpdateRestaurantDto }) @ApiBody({ type: UpdateRestaurantDto })
@ApiResponse({ status: 200, description: 'Restaurant updated' }) @ApiResponse({ status: 200, description: 'Restaurant updated' })
@ApiNotFoundResponse({ type: NotFoundException, description: 'Restaurant not found' }) @ApiNotFoundResponse({ type: NotFoundException, description: 'Restaurant not found' })
@Patch(':id') @Patch('admin/restaurants/:id')
update(@Param('id') id: string, @Body() updateRestaurantDto: UpdateRestaurantDto) { update(@Param('id') id: string, @Body() updateRestaurantDto: UpdateRestaurantDto) {
return this.restaurantsService.update(id, updateRestaurantDto); return this.restaurantsService.update(id, updateRestaurantDto);
} }
@UseGuards(AdminAuthGuard)
@ApiBearerAuth() @ApiBearerAuth()
@ApiOperation({ summary: 'Update a restaurant' }) @ApiOperation({ summary: 'Update a restaurant' })
@ApiBody({ type: UpdateRestaurantDto }) @ApiBody({ type: UpdateRestaurantDto })
@ApiResponse({ status: 200, description: 'Restaurant updated' }) @ApiResponse({ status: 200, description: 'Restaurant updated' })
@ApiNotFoundResponse({ type: NotFoundException, description: 'Restaurant not found' }) @ApiNotFoundResponse({ type: NotFoundException, description: 'Restaurant not found' })
@Patch('my-restaurant') @Patch('admin/restaurants/my-restaurant')
updateMyRestaurant(@RestId() restId: string, @Body() updateRestaurantDto: UpdateRestaurantDto) { updateMyRestaurant(@RestId() restId: string, @Body() updateRestaurantDto: UpdateRestaurantDto) {
return this.restaurantsService.update(restId, updateRestaurantDto); return this.restaurantsService.update(restId, updateRestaurantDto);
} }
@UseGuards(AdminAuthGuard)
@ApiBearerAuth() @ApiBearerAuth()
@ApiOperation({ summary: 'Delete a restaurant' }) @ApiOperation({ summary: 'Delete a restaurant' })
@ApiResponse({ status: 200, description: 'Restaurant deleted' }) @ApiResponse({ status: 200, description: 'Restaurant deleted' })
@ApiNotFoundResponse({ description: 'Restaurant not found' }) @ApiNotFoundResponse({ description: 'Restaurant not found' })
@Delete(':id') @Delete('admin/restaurants/:id')
remove(@Param('id') id: string) { remove(@Param('id') id: string) {
return this.restaurantsService.remove(id); 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 { AdminAuthGuard } from 'src/modules/auth/guards/adminAuth.guard';
import { RestId } from 'src/common/decorators/rest-id.decorator'; import { RestId } from 'src/common/decorators/rest-id.decorator';
@UseGuards(AdminAuthGuard) @ApiTags('schedules')
@ApiBearerAuth() @Controller()
@ApiTags('admin/schedules')
@Controller('admin/schedules')
export class ScheduleController { export class ScheduleController {
constructor(private readonly scheduleService: ScheduleService) {} 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' }) @ApiOperation({ summary: 'Create a new schedule' })
@ApiBody({ type: CreateScheduleDto }) @ApiBody({ type: CreateScheduleDto })
@ApiCreatedResponse({ description: 'Schedule created successfully', type: Schedule }) @ApiCreatedResponse({ description: 'Schedule created successfully', type: Schedule })
@@ -33,7 +41,9 @@ export class ScheduleController {
return this.scheduleService.create(restId, createScheduleDto); return this.scheduleService.create(restId, createScheduleDto);
} }
@Get() @UseGuards(AdminAuthGuard)
@ApiBearerAuth()
@Get('admin/schedules')
@ApiOperation({ summary: 'Get all schedules' }) @ApiOperation({ summary: 'Get all schedules' })
@ApiQuery({ @ApiQuery({
name: 'weekDay', name: 'weekDay',
@@ -49,7 +59,9 @@ export class ScheduleController {
return this.scheduleService.findAll(restId, query); return this.scheduleService.findAll(restId, query);
} }
@Get(':id') @UseGuards(AdminAuthGuard)
@ApiBearerAuth()
@Get('admin/schedules/:id')
@ApiOperation({ summary: 'Get a schedule by ID' }) @ApiOperation({ summary: 'Get a schedule by ID' })
@ApiParam({ name: 'id', description: 'Schedule ID' }) @ApiParam({ name: 'id', description: 'Schedule ID' })
@ApiOkResponse({ description: 'Schedule details', type: Schedule }) @ApiOkResponse({ description: 'Schedule details', type: Schedule })
@@ -58,7 +70,9 @@ export class ScheduleController {
return this.scheduleService.findOne(id, restId); return this.scheduleService.findOne(id, restId);
} }
@Patch(':id') @UseGuards(AdminAuthGuard)
@ApiBearerAuth()
@Patch('admin/schedules/:id')
@ApiOperation({ summary: 'Update a schedule' }) @ApiOperation({ summary: 'Update a schedule' })
@ApiParam({ name: 'id', description: 'Schedule ID' }) @ApiParam({ name: 'id', description: 'Schedule ID' })
@ApiBody({ type: UpdateScheduleDto }) @ApiBody({ type: UpdateScheduleDto })
@@ -68,7 +82,9 @@ export class ScheduleController {
return this.scheduleService.update(id, restId, updateScheduleDto); return this.scheduleService.update(id, restId, updateScheduleDto);
} }
@Delete(':id') @UseGuards(AdminAuthGuard)
@ApiBearerAuth()
@Delete('admin/schedules/:id')
@ApiOperation({ summary: 'Delete a schedule' }) @ApiOperation({ summary: 'Delete a schedule' })
@ApiParam({ name: 'id', description: 'Schedule ID' }) @ApiParam({ name: 'id', description: 'Schedule ID' })
@ApiOkResponse({ description: 'Schedule deleted successfully' }) @ApiOkResponse({ description: 'Schedule deleted successfully' })
@@ -7,6 +7,8 @@ import { CreateScheduleDto } from '../dto/create-schedule.dto';
import { UpdateScheduleDto } from '../dto/update-schedule.dto'; import { UpdateScheduleDto } from '../dto/update-schedule.dto';
import { FindSchedulesDto } from '../dto/find-schedules.dto'; import { FindSchedulesDto } from '../dto/find-schedules.dto';
import { RestRepository } from '../repositories/rest.repository'; 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'; // import { RestMessage } from 'src/common/enums/message.enum';
@Injectable() @Injectable()
@@ -46,12 +48,16 @@ export class ScheduleService {
return this.scheduleRepository.find(where, { orderBy: { weekDay: 'asc' } }); 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 today = new Date();
const weekDay = today.getDay(); // 0 = Sunday, 6 = Saturday const weekDay = today.getDay(); // 0 = Sunday, 6 = Saturday
const where: FilterQuery<Schedule> = { const where: FilterQuery<Schedule> = {
restId, restId: restaurant.id.toString(),
weekDay, weekDay,
isActive: true, isActive: true,
}; };
@@ -1,7 +1,6 @@
import { Module, forwardRef } from '@nestjs/common'; import { Module, forwardRef } from '@nestjs/common';
import { RestaurantsService } from './providers/restaurants.service'; import { RestaurantsService } from './providers/restaurants.service';
import { RestaurantsController } from './controllers/restaurants.controller'; import { RestaurantsController } from './controllers/restaurants.controller';
import { PublicRestaurantController } from './controllers/public-restaurant.controller';
import { MikroOrmModule } from '@mikro-orm/nestjs'; import { MikroOrmModule } from '@mikro-orm/nestjs';
import { Restaurant } from './entities/restaurant.entity'; import { Restaurant } from './entities/restaurant.entity';
import { RestRepository } from './repositories/rest.repository'; import { RestRepository } from './repositories/rest.repository';
@@ -9,12 +8,11 @@ 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, PublicScheduleController], controllers: [RestaurantsController, ScheduleController],
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],