remove rest id from creating
This commit is contained in:
@@ -8,7 +8,6 @@ export interface AdminDetailResponse {
|
||||
role: {
|
||||
id: string;
|
||||
name: string;
|
||||
title: string;
|
||||
};
|
||||
permissions: string[];
|
||||
restaurant?: {
|
||||
@@ -37,7 +36,6 @@ export class AdminDetailTransformer {
|
||||
role: {
|
||||
id: role.id,
|
||||
name: role.name,
|
||||
title: role.title,
|
||||
},
|
||||
permissions: role.permissions.getItems().map(p => p.name) || [],
|
||||
restaurant: {
|
||||
|
||||
@@ -2,6 +2,7 @@ import { Controller, Get, Post, Body, Patch, Param, Delete, Query, UseGuards } f
|
||||
import { RestaurantPaymentMethodService } from '../services/restaurant-payment-method.service';
|
||||
import { CreateRestaurantPaymentMethodDto } from '../dto/create-restaurant-payment-method.dto';
|
||||
import { UpdateRestaurantPaymentMethodDto } from '../dto/update-restaurant-payment-method.dto';
|
||||
import { RestId } from 'src/common/decorators/rest-id.decorator';
|
||||
import {
|
||||
ApiTags,
|
||||
ApiOperation,
|
||||
@@ -27,8 +28,8 @@ export class RestaurantPaymentMethodController {
|
||||
@ApiOperation({ summary: 'Create a new restaurant payment method' })
|
||||
@ApiBody({ type: CreateRestaurantPaymentMethodDto })
|
||||
@ApiCreatedResponse({ description: 'Restaurant payment method created successfully' })
|
||||
create(@Body() createRestaurantPaymentMethodDto: CreateRestaurantPaymentMethodDto) {
|
||||
return this.restaurantPaymentMethodService.create(createRestaurantPaymentMethodDto);
|
||||
create(@RestId() restId: string, @Body() createRestaurantPaymentMethodDto: CreateRestaurantPaymentMethodDto) {
|
||||
return this.restaurantPaymentMethodService.create(restId, createRestaurantPaymentMethodDto);
|
||||
}
|
||||
|
||||
@Get()
|
||||
|
||||
@@ -2,10 +2,6 @@ import { IsString, IsOptional, IsBoolean } from 'class-validator';
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
|
||||
export class CreateRestaurantPaymentMethodDto {
|
||||
@ApiProperty({ description: 'Restaurant ID' })
|
||||
@IsString()
|
||||
restaurantId!: string;
|
||||
|
||||
@ApiProperty({ description: 'Payment method ID' })
|
||||
@IsString()
|
||||
paymentMethodId!: string;
|
||||
@@ -20,4 +16,3 @@ export class CreateRestaurantPaymentMethodDto {
|
||||
@IsBoolean()
|
||||
isActive?: boolean;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,16 @@
|
||||
import { PartialType } from '@nestjs/mapped-types';
|
||||
import { CreateRestaurantPaymentMethodDto } from './create-restaurant-payment-method.dto';
|
||||
import { IsString } from 'class-validator';
|
||||
import { IsString, IsOptional } from 'class-validator';
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
|
||||
export class UpdateRestaurantPaymentMethodDto extends PartialType(CreateRestaurantPaymentMethodDto) {
|
||||
@ApiProperty({ description: 'Restaurant payment method ID' })
|
||||
@IsString()
|
||||
id!: string;
|
||||
|
||||
@ApiProperty({ description: 'Restaurant ID', required: false })
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
restaurantId?: string;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,23 +16,28 @@ export class RestaurantPaymentMethodService {
|
||||
) {}
|
||||
|
||||
async create(
|
||||
restId: string,
|
||||
createRestaurantPaymentMethodDto: CreateRestaurantPaymentMethodDto,
|
||||
): Promise<RestaurantPaymentMethod> {
|
||||
// Check if restaurant exists
|
||||
const restaurant = await this.em.findOne(Restaurant, { id: createRestaurantPaymentMethodDto.restaurantId });
|
||||
const restaurant = await this.em.findOne(Restaurant, { id: restId });
|
||||
if (!restaurant) {
|
||||
throw new NotFoundException(`Restaurant with ID ${createRestaurantPaymentMethodDto.restaurantId} not found`);
|
||||
throw new NotFoundException(`Restaurant with ID ${restId} not found`);
|
||||
}
|
||||
|
||||
// Check if payment method exists
|
||||
const paymentMethod = await this.em.findOne(PaymentMethod, { id: createRestaurantPaymentMethodDto.paymentMethodId });
|
||||
const paymentMethod = await this.em.findOne(PaymentMethod, {
|
||||
id: createRestaurantPaymentMethodDto.paymentMethodId,
|
||||
});
|
||||
if (!paymentMethod) {
|
||||
throw new NotFoundException(`PaymentMethod with ID ${createRestaurantPaymentMethodDto.paymentMethodId} not found`);
|
||||
throw new NotFoundException(
|
||||
`PaymentMethod with ID ${createRestaurantPaymentMethodDto.paymentMethodId} not found`,
|
||||
);
|
||||
}
|
||||
|
||||
// Check if the relationship already exists
|
||||
const existing = await this.restaurantPaymentMethodRepository.findOne({
|
||||
restaurant: { id: createRestaurantPaymentMethodDto.restaurantId },
|
||||
restaurant: { id: restId },
|
||||
paymentMethod: { id: createRestaurantPaymentMethodDto.paymentMethodId },
|
||||
});
|
||||
|
||||
@@ -95,9 +100,13 @@ export class RestaurantPaymentMethodService {
|
||||
}
|
||||
|
||||
if (updateRestaurantPaymentMethodDto.paymentMethodId) {
|
||||
const paymentMethod = await this.em.findOne(PaymentMethod, { id: updateRestaurantPaymentMethodDto.paymentMethodId });
|
||||
const paymentMethod = await this.em.findOne(PaymentMethod, {
|
||||
id: updateRestaurantPaymentMethodDto.paymentMethodId,
|
||||
});
|
||||
if (!paymentMethod) {
|
||||
throw new NotFoundException(`PaymentMethod with ID ${updateRestaurantPaymentMethodDto.paymentMethodId} not found`);
|
||||
throw new NotFoundException(
|
||||
`PaymentMethod with ID ${updateRestaurantPaymentMethodDto.paymentMethodId} not found`,
|
||||
);
|
||||
}
|
||||
|
||||
// Check if the new relationship already exists
|
||||
|
||||
Reference in New Issue
Block a user