diff --git a/src/modules/dmenu/DTO/create-restaurant.dto.ts b/src/modules/dmenu/DTO/create-restaurant.dto.ts new file mode 100644 index 0000000..060ce50 --- /dev/null +++ b/src/modules/dmenu/DTO/create-restaurant.dto.ts @@ -0,0 +1,23 @@ +import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'; +import { IsString, IsOptional, IsNumber } from 'class-validator'; + +export class CreateRestaurantDto { + @ApiProperty({ example: 'کافه ژیوان', description: 'نام رستوران' }) + @IsString() + name!: string; + + @ApiProperty({ example: 'zhivan', description: 'شناسه (slug) رستوران، لاتین و بدون فاصله' }) + @IsString() + slug!: string; + + @ApiPropertyOptional({ example: 2020, description: 'سال تأسیس' }) + @IsOptional() + @IsNumber() + establishedYear?: number; + + @ApiPropertyOptional({ example: '09123456789', description: 'شماره تلفن' }) + @IsOptional() + @IsString() + phone?: string; + +} diff --git a/src/modules/dmenu/dmenu.controller.ts b/src/modules/dmenu/dmenu.controller.ts index eb2cad0..09fcbb0 100644 --- a/src/modules/dmenu/dmenu.controller.ts +++ b/src/modules/dmenu/dmenu.controller.ts @@ -9,6 +9,7 @@ import { UpdateIconDto } from "./DTO/update-icon.dto"; import { CreateGroupDto } from "./DTO/create-group.dto"; import { UpdateGroupDto } from "./DTO/update-group.dto"; import { FindRestaurantsDto } from "./DTO/find-restaurants.dto"; +import { CreateRestaurantDto } from "./DTO/create-restaurant.dto"; import { AuthGuards } from "../../common/decorators/auth-guard.decorator"; import { PermissionsDec } from "../../common/decorators/permission.decorator"; import { PermissionEnum } from "../users/enums/permission.enum"; @@ -23,7 +24,7 @@ export class DmenuController { private readonly iconsService: IconsService, private readonly contactService: ContactService, private readonly restaurantService: RestaurantService, - ) {} + ) { } // Icon endpoints @Post('icons') @@ -102,9 +103,16 @@ export class DmenuController { return this.contactService.findOne(+id); } + // restaurant @Get('restaurants') @ApiOperation({ summary: "Get all restaurants" }) findAllRestaurant(@Query() queryDto: FindRestaurantsDto) { return this.restaurantService.findAll(queryDto); } + + @Post('restaurants') + @ApiOperation({ summary: "Create restaurant" }) + createRestaurant(@Body() dto: CreateRestaurantDto) { + return this.restaurantService.createRestaurant(dto); + } } diff --git a/src/modules/dmenu/providers/restaurant.service.ts b/src/modules/dmenu/providers/restaurant.service.ts index 6b58fe0..5ab58a0 100644 --- a/src/modules/dmenu/providers/restaurant.service.ts +++ b/src/modules/dmenu/providers/restaurant.service.ts @@ -7,6 +7,7 @@ import { catchError, firstValueFrom, throwError } from "rxjs"; import { IDmenuConfig } from "../../../configs/icons.config"; import { DMENU_CONFIG } from "../constants"; import { FindRestaurantsDto } from "../DTO/find-restaurants.dto"; +import { CreateRestaurantDto } from "../DTO/create-restaurant.dto"; @Injectable() export class RestaurantService { @@ -65,5 +66,26 @@ export class RestaurantService { throw error; } } + + async createRestaurant(dto: CreateRestaurantDto) { + try { + const { data } = await firstValueFrom( + this.httpService + .post(`${this.config.baseUrl}/super-admin/restaurants`, dto, { + headers: this.getHeaders(), + }) + .pipe( + catchError((err: AxiosError) => { + this.logger.error(`Failed to create restaurant: ${err.message}`, err.stack); + return throwError(() => err); + }), + ), + ); + return data; + } catch (error: unknown) { + this.logger.error(`Error creating restaurant: ${error instanceof Error ? error.message : "Unknown error"}`); + throw error; + } + } }