fix bug in create rest

This commit is contained in:
2025-12-26 22:34:40 +03:30
parent 9a938bf8cd
commit 21da5d52f8
3 changed files with 15 additions and 3 deletions
@@ -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 { UpdateRestaurantDto } from '../dto/update-restaurant.dto';
import { Restaurant } from '../entities/restaurant.entity';
@@ -17,6 +17,14 @@ export class RestaurantsService {
) { }
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, {
name: dto.name,
slug: dto.slug,