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