diff --git a/src/modules/restaurants/controllers/public-restaurant-shipment-method.controller.ts b/src/modules/restaurants/controllers/public-restaurant-shipment-method.controller.ts index f219be9..9278e65 100644 --- a/src/modules/restaurants/controllers/public-restaurant-shipment-method.controller.ts +++ b/src/modules/restaurants/controllers/public-restaurant-shipment-method.controller.ts @@ -19,6 +19,6 @@ export class PublicRestaurantShipmentMethodController { type: [RestaurantShipmentMethod], }) findAll(@RestId() restId: string) { - return this.restaurantShipmentMethodService.findAll(restId); + return this.restaurantShipmentMethodService.findAllForRestaurantId(restId); } } diff --git a/src/modules/restaurants/controllers/restaurant-shipment-method.controller.ts b/src/modules/restaurants/controllers/restaurant-shipment-method.controller.ts index b938ed7..b4622f8 100644 --- a/src/modules/restaurants/controllers/restaurant-shipment-method.controller.ts +++ b/src/modules/restaurants/controllers/restaurant-shipment-method.controller.ts @@ -35,30 +35,30 @@ export class RestaurantShipmentMethodController { } @Get() - @ApiOperation({ summary: 'Get all restaurant shipment methods' }) + @ApiOperation({ summary: 'Get the restaurant shipment methods' }) @ApiOkResponse({ description: 'List of restaurant shipment methods', type: [RestaurantShipmentMethod], }) findAll(@RestId() restId: string) { - return this.restaurantShipmentMethodService.findAll(restId); + return this.restaurantShipmentMethodService.findAllForRestaurantId(restId); } - @Get(':shipmentMethodId') + @Get(':RestaurantShipmentMethodId') @ApiOperation({ summary: 'Get a restaurant shipment method by shipment method ID' }) - @ApiParam({ name: 'shipmentMethodId', description: 'Shipment method ID' }) + @ApiParam({ name: 'RestaurantShipmentMethodId', description: 'RestaurantRestaurantShipmentMethodId method ID' }) @ApiOkResponse({ description: 'Restaurant shipment method details', type: RestaurantShipmentMethod, }) @ApiNotFoundResponse({ description: 'Restaurant shipment method not found' }) - findOne(@Param('shipmentMethodId') shipmentMethodId: string, @RestId() restId: string) { - return this.restaurantShipmentMethodService.findOne(restId, shipmentMethodId); + findOne(@Param('RestaurantShipmentMethodId') RestaurantShipmentMethodId: string, @RestId() restId: string) { + return this.restaurantShipmentMethodService.findOne(restId, RestaurantShipmentMethodId); } - @Patch(':shipmentMethodId') + @Patch(':RestaurantShipmentMethodId') @ApiOperation({ summary: 'Update a restaurant shipment method' }) - @ApiParam({ name: 'shipmentMethodId', description: 'Shipment method ID' }) + @ApiParam({ name: 'RestaurantShipmentMethodId', description: 'Shipment method ID' }) @ApiBody({ type: UpdateRestaurantShipmentMethodDto }) @ApiOkResponse({ description: 'Restaurant shipment method updated successfully', @@ -66,19 +66,19 @@ export class RestaurantShipmentMethodController { }) @ApiNotFoundResponse({ description: 'Restaurant shipment method not found' }) update( - @Param('shipmentMethodId') shipmentMethodId: string, + @Param('RestaurantShipmentMethodId') RestaurantShipmentMethodId: string, @Body() updateDto: UpdateRestaurantShipmentMethodDto, @RestId() restId: string, ) { - return this.restaurantShipmentMethodService.update(restId, shipmentMethodId, updateDto); + return this.restaurantShipmentMethodService.update(restId, RestaurantShipmentMethodId, updateDto); } - @Delete(':shipmentMethodId') + @Delete(':RestaurantShipmentMethodId') @ApiOperation({ summary: 'Delete a restaurant shipment method' }) - @ApiParam({ name: 'shipmentMethodId', description: 'Shipment method ID' }) + @ApiParam({ name: 'RestaurantShipmentMethodId', description: 'Shipment method ID' }) @ApiOkResponse({ description: 'Restaurant shipment method deleted successfully' }) @ApiNotFoundResponse({ description: 'Restaurant shipment method not found' }) - remove(@Param('shipmentMethodId') shipmentMethodId: string, @RestId() restId: string) { - return this.restaurantShipmentMethodService.remove(restId, shipmentMethodId); + remove(@Param('RestaurantShipmentMethodId') RestaurantShipmentMethodId: string, @RestId() restId: string) { + return this.restaurantShipmentMethodService.remove(restId, RestaurantShipmentMethodId); } } diff --git a/src/modules/restaurants/providers/restaurant-shipment-method.service.ts b/src/modules/restaurants/providers/restaurant-shipment-method.service.ts index c68b59b..716171a 100644 --- a/src/modules/restaurants/providers/restaurant-shipment-method.service.ts +++ b/src/modules/restaurants/providers/restaurant-shipment-method.service.ts @@ -49,24 +49,26 @@ export class RestaurantShipmentMethodService { return restaurantShipmentMethod; } - async findAll(restId: string): Promise { + async findAllForRestaurantId(restId: string): Promise { return this.restaurantShipmentMethodRepository.find( { restaurant: { id: restId } }, { populate: ['shipmentMethod'] }, ); } - async findOne(restId: string, shipmentMethodId: string): Promise { + async findOne(restId: string, restaurantShipmentMethodId: string): Promise { const restaurantShipmentMethod = await this.restaurantShipmentMethodRepository.findOne( { + id: restaurantShipmentMethodId, restaurant: { id: restId }, - shipmentMethod: { id: shipmentMethodId }, }, { populate: ['shipmentMethod'] }, ); if (!restaurantShipmentMethod) { - throw new NotFoundException(`روش ارسال با شناسه ${shipmentMethodId} برای رستوران با شناسه ${restId} یافت نشد.`); + throw new NotFoundException( + `Restaurant shipment method with ID ${restaurantShipmentMethodId} not found for restaurant with ID ${restId}`, + ); } return restaurantShipmentMethod; @@ -74,16 +76,18 @@ export class RestaurantShipmentMethodService { async update( restId: string, - shipmentMethodId: string, + restaurantShipmentMethodId: string, updateDto: UpdateRestaurantShipmentMethodDto, ): Promise { const restaurantShipmentMethod = await this.restaurantShipmentMethodRepository.findOne({ restaurant: { id: restId }, - shipmentMethod: { id: shipmentMethodId }, + id: restaurantShipmentMethodId, }); if (!restaurantShipmentMethod) { - throw new NotFoundException(`روش ارسال با شناسه ${shipmentMethodId} برای رستوران با شناسه ${restId} یافت نشد.`); + throw new NotFoundException( + `روش ارسال با شناسه ${restaurantShipmentMethodId} برای رستوران با شناسه ${restId} یافت نشد.`, + ); } const updateData: Partial = {}; @@ -99,7 +103,10 @@ export class RestaurantShipmentMethodService { } // If shipmentMethodId is being updated, we need to check for conflicts - if (updateDto.shipmentMethodId !== undefined && updateDto.shipmentMethodId !== shipmentMethodId) { + if ( + updateDto.shipmentMethodId !== undefined && + updateDto.shipmentMethodId !== restaurantShipmentMethod.shipmentMethod.id + ) { const newShipmentMethod = await this.em.findOne(ShipmentMethod, { id: updateDto.shipmentMethodId }); if (!newShipmentMethod) { throw new NotFoundException(`روش ارسال با شناسه ${updateDto.shipmentMethodId} یافت نشد.`); @@ -108,7 +115,7 @@ export class RestaurantShipmentMethodService { // Check if the new relationship already exists const existing = await this.restaurantShipmentMethodRepository.findOne({ restaurant: { id: restId }, - shipmentMethod: { id: updateDto.shipmentMethodId }, + shipmentMethod: { id: { $ne: restaurantShipmentMethodId } }, }); if (existing) { @@ -127,14 +134,16 @@ export class RestaurantShipmentMethodService { return restaurantShipmentMethod; } - async remove(restId: string, shipmentMethodId: string): Promise { + async remove(restId: string, restaurantShipmentMethodId: string): Promise { const restaurantShipmentMethod = await this.restaurantShipmentMethodRepository.findOne({ restaurant: { id: restId }, - shipmentMethod: { id: shipmentMethodId }, + id: restaurantShipmentMethodId, }); if (!restaurantShipmentMethod) { - throw new NotFoundException(`روش ارسال با شناسه ${shipmentMethodId} برای رستوران با شناسه ${restId} یافت نشد.`); + throw new NotFoundException( + `روش ارسال با شناسه ${restaurantShipmentMethodId} برای رستوران با شناسه ${restId} یافت نشد.`, + ); } await this.em.removeAndFlush(restaurantShipmentMethod); diff --git a/src/modules/restaurants/repositories/restaurant-shipment-method.repository.ts b/src/modules/restaurants/repositories/restaurant-shipment-method.repository.ts index 7db3734..608113d 100644 --- a/src/modules/restaurants/repositories/restaurant-shipment-method.repository.ts +++ b/src/modules/restaurants/repositories/restaurant-shipment-method.repository.ts @@ -8,4 +8,3 @@ export class RestaurantShipmentMethodRepository extends EntityRepository