up
This commit is contained in:
@@ -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`;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user