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