update rest
This commit is contained in:
@@ -24,7 +24,7 @@ export class RestaurantsController {
|
||||
|
||||
@Patch(':id')
|
||||
update(@Param('id') id: string, @Body() updateRestaurantDto: UpdateRestaurantDto) {
|
||||
return this.restaurantsService.update(+id, updateRestaurantDto);
|
||||
return this.restaurantsService.update(id, updateRestaurantDto);
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
|
||||
@@ -4,13 +4,12 @@ import { UpdateRestaurantDto } from './dto/update-restaurant.dto';
|
||||
import { Restaurant } from './entities/restaurant.entity';
|
||||
import { EntityManager } from '@mikro-orm/postgresql';
|
||||
import { RestRepository } from './repositories/rest.repository';
|
||||
import { InjectRepository } from '@mikro-orm/nestjs';
|
||||
import { RestMessage } from 'src/common/enums/message.enum';
|
||||
|
||||
@Injectable()
|
||||
export class RestaurantsService {
|
||||
constructor(
|
||||
private readonly em: EntityManager,
|
||||
@InjectRepository(Restaurant)
|
||||
private readonly restRepository: RestRepository,
|
||||
) {}
|
||||
|
||||
@@ -38,8 +37,18 @@ export class RestaurantsService {
|
||||
return restaurant;
|
||||
}
|
||||
|
||||
update(id: number, updateRestaurantDto: UpdateRestaurantDto) {
|
||||
return `This action updates a #${id} restaurant`;
|
||||
async update(id: string, dto: UpdateRestaurantDto): Promise<Restaurant> {
|
||||
const restaurant = await this.restRepository.findOne({ id });
|
||||
|
||||
if (!restaurant) {
|
||||
throw new NotFoundException(RestMessage.NOT_FOUND);
|
||||
}
|
||||
|
||||
this.restRepository.assign(restaurant, dto);
|
||||
|
||||
await this.em.persistAndFlush(restaurant);
|
||||
|
||||
return restaurant;
|
||||
}
|
||||
|
||||
remove(id: number) {
|
||||
|
||||
Reference in New Issue
Block a user