fix bug in create rest
This commit is contained in:
@@ -77,6 +77,7 @@ export class RestaurantsController {
|
|||||||
@ApiOperation({ summary: 'Create a new restaurant' })
|
@ApiOperation({ summary: 'Create a new restaurant' })
|
||||||
@Post('super-admin/restaurants')
|
@Post('super-admin/restaurants')
|
||||||
createRestaurant(@Body() createRestaurantDto: CreateRestaurantDto) {
|
createRestaurant(@Body() createRestaurantDto: CreateRestaurantDto) {
|
||||||
|
console.log('create rest')
|
||||||
return this.restaurantsService.create(createRestaurantDto);
|
return this.restaurantsService.create(createRestaurantDto);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
||||||
import { IsString, IsOptional, IsNumber, IsDate } from 'class-validator';
|
import { IsString, IsOptional, IsNumber, IsDate } from 'class-validator';
|
||||||
|
import { Type } from 'class-transformer';
|
||||||
|
|
||||||
export class CreateRestaurantDto {
|
export class CreateRestaurantDto {
|
||||||
@ApiProperty({ example: 'کافه ژیوان', description: 'نام رستوران' })
|
@ApiProperty({ example: 'کافه ژیوان', description: 'نام رستوران' })
|
||||||
@@ -13,22 +14,24 @@ export class CreateRestaurantDto {
|
|||||||
@ApiPropertyOptional({ example: 2020, description: 'سال تأسیس' })
|
@ApiPropertyOptional({ example: 2020, description: 'سال تأسیس' })
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsNumber()
|
@IsNumber()
|
||||||
establishedYear?: number;
|
establishedYear: number;
|
||||||
|
|
||||||
@ApiPropertyOptional({ example: '09123456789', description: 'شماره تلفن' })
|
@ApiPropertyOptional({ example: '09123456789', description: 'شماره تلفن' })
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsString()
|
@IsString()
|
||||||
phone?: string;
|
phone: string;
|
||||||
|
|
||||||
@ApiProperty({ example: 'sub_1234567890', description: 'شناسه اشتراک' })
|
@ApiProperty({ example: 'sub_1234567890', description: 'شناسه اشتراک' })
|
||||||
@IsString()
|
@IsString()
|
||||||
subscriptionId!: string;
|
subscriptionId!: string;
|
||||||
|
|
||||||
@ApiProperty({ example: '2025-12-26', description: 'تاریخ انقضای اشتراک' })
|
@ApiProperty({ example: '2025-12-26', description: 'تاریخ انقضای اشتراک' })
|
||||||
|
@Type(() => Date)
|
||||||
@IsDate()
|
@IsDate()
|
||||||
subscriptionEndDate!: Date;
|
subscriptionEndDate!: Date;
|
||||||
|
|
||||||
@ApiProperty({ example: '2025-12-26', description: 'تاریخ شروع اشتراک' })
|
@ApiProperty({ example: '2025-12-26', description: 'تاریخ شروع اشتراک' })
|
||||||
|
@Type(() => Date)
|
||||||
@IsDate()
|
@IsDate()
|
||||||
subscriptionStartDate!: Date;
|
subscriptionStartDate!: Date;
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
import { BadRequestException, Injectable, NotFoundException } from '@nestjs/common';
|
||||||
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 { Restaurant } from '../entities/restaurant.entity';
|
import { Restaurant } from '../entities/restaurant.entity';
|
||||||
@@ -17,6 +17,14 @@ export class RestaurantsService {
|
|||||||
) { }
|
) { }
|
||||||
|
|
||||||
async create(dto: CreateRestaurantDto): Promise<Restaurant> {
|
async create(dto: CreateRestaurantDto): Promise<Restaurant> {
|
||||||
|
const validateSlug = await this.em.findOne(Restaurant, { slug: dto.slug })
|
||||||
|
if (validateSlug) {
|
||||||
|
throw new BadRequestException("Duplicate slug: " + dto.slug)
|
||||||
|
}
|
||||||
|
const validateSubscriptionId = await this.em.findOne(Restaurant, { subscriptionId: dto.subscriptionId })
|
||||||
|
if (validateSubscriptionId) {
|
||||||
|
throw new BadRequestException("Duplicate subscriptionId: " + dto.subscriptionId)
|
||||||
|
}
|
||||||
const restaurant = this.em.create(Restaurant, {
|
const restaurant = this.em.create(Restaurant, {
|
||||||
name: dto.name,
|
name: dto.name,
|
||||||
slug: dto.slug,
|
slug: dto.slug,
|
||||||
|
|||||||
Reference in New Issue
Block a user