This commit is contained in:
2025-11-10 23:23:44 +03:30
parent 6a25bf9116
commit 4c274c3118
7 changed files with 257 additions and 0 deletions
@@ -0,0 +1,42 @@
import { 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';
import { EntityManager } from '@mikro-orm/postgresql';
@Injectable()
export class RestaurantsService {
constructor(private readonly em: EntityManager) {}
async create(dto: CreateRestaurantDto): Promise<Restaurant> {
const restaurant = this.em.create(Restaurant, {
...dto,
isActive: true,
});
await this.em.persistAndFlush(restaurant);
return restaurant;
}
findAll() {
return `This action returns all restaurants`;
}
async findBySlug(slug: string): Promise<Restaurant> {
const restaurant = await this.em.findOne(Restaurant, { slug });
if (!restaurant) {
throw new NotFoundException(`Restaurant with slug "${slug}" not found`);
}
return restaurant;
}
update(id: number, updateRestaurantDto: UpdateRestaurantDto) {
return `This action updates a #${id} restaurant`;
}
remove(id: number) {
return `This action removes a #${id} restaurant`;
}
}