payment method
This commit is contained in:
@@ -318,7 +318,7 @@ export class CartService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cart.paymentMethodId = setPaymentMethodDto.paymentMethodId;
|
cart.paymentMethodId = setPaymentMethodDto.paymentMethodId;
|
||||||
cart.paymentMethodFee = Number(restaurantPaymentMethod.price) || 0;
|
// cart.paymentMethodFee = Number(restaurantPaymentMethod.price) || 0;
|
||||||
|
|
||||||
// Recalculate cart totals to include payment method fee
|
// Recalculate cart totals to include payment method fee
|
||||||
await this.recalculateCartTotals(cart);
|
await this.recalculateCartTotals(cart);
|
||||||
@@ -374,15 +374,16 @@ export class CartService {
|
|||||||
|
|
||||||
// Get payment method fee if payment method is set
|
// Get payment method fee if payment method is set
|
||||||
let paymentMethodFee = 0;
|
let paymentMethodFee = 0;
|
||||||
if (cart.paymentMethodId) {
|
// if (cart.paymentMethodId) {
|
||||||
const restaurantPaymentMethod = await this.em.findOne(RestaurantPaymentMethod, {
|
// const restaurantPaymentMethod = await this.em.findOne(RestaurantPaymentMethod, {
|
||||||
restaurant: { id: cart.restaurantId },
|
// restaurant: { id: cart.restaurantId },
|
||||||
paymentMethod: { id: cart.paymentMethodId },
|
// paymentMethod: { id: cart.paymentMethodId },
|
||||||
});
|
// });
|
||||||
if (restaurantPaymentMethod) {
|
// if (restaurantPaymentMethod) {
|
||||||
paymentMethodFee = Number(restaurantPaymentMethod.price) || 0;
|
// paymentMethodFee = Number(restaurantPaymentMethod.price) || 0;
|
||||||
}
|
// paymentMethodFee = 1;
|
||||||
}
|
// }
|
||||||
|
// }
|
||||||
cart.paymentMethodFee = paymentMethodFee;
|
cart.paymentMethodFee = paymentMethodFee;
|
||||||
|
|
||||||
// Final price includes items, discounts, VAT, and payment method fee
|
// Final price includes items, discounts, VAT, and payment method fee
|
||||||
|
|||||||
@@ -30,38 +30,41 @@ export class RestaurantPaymentMethodController {
|
|||||||
return this.restaurantPaymentMethodService.create(restId, createRestaurantPaymentMethodDto);
|
return this.restaurantPaymentMethodService.create(restId, createRestaurantPaymentMethodDto);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get(':paymentMethodId')
|
@Get(':restaurantPaymentMethodId')
|
||||||
@ApiOperation({ summary: 'Get restaurant payment methods by payment method ID' })
|
@ApiOperation({ summary: 'Get restaurant payment method by payment method ID' })
|
||||||
@ApiParam({ name: 'paymentMethodId', type: 'string', description: 'Payment method ID' })
|
@ApiParam({ name: 'restaurantPaymentMethodId', type: 'string', description: 'restaurantPaymentMethodId method ID' })
|
||||||
@ApiOkResponse({ description: 'List of restaurant payment methods for the payment method' })
|
@ApiOkResponse({ description: 'List of restaurant payment methods for the payment method' })
|
||||||
findByPaymentMethod(@Param('paymentMethodId') paymentMethodId: string) {
|
findByPaymentMethod(@Param('restaurantPaymentMethodId') restaurantPaymentMethodId: string) {
|
||||||
return this.restaurantPaymentMethodService.findByPaymentMethod(paymentMethodId);
|
return this.restaurantPaymentMethodService.findByPaymentMethod(restaurantPaymentMethodId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get()
|
@Get()
|
||||||
@ApiOperation({ summary: 'Get a restaurant payment method by ID' })
|
@ApiOperation({ summary: 'Get restaurant all payment methods ' })
|
||||||
@ApiOkResponse({ description: 'Restaurant payment method found' })
|
@ApiOkResponse({ description: 'Restaurant payment method found' })
|
||||||
@ApiNotFoundResponse({ description: 'Restaurant payment method not found' })
|
@ApiNotFoundResponse({ description: 'Restaurant payment method not found' })
|
||||||
findByRestaurant(@RestId() restId: string) {
|
findByRestaurant(@RestId() restId: string) {
|
||||||
return this.restaurantPaymentMethodService.findByRestaurant(restId);
|
return this.restaurantPaymentMethodService.findByRestaurant(restId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Patch(':id')
|
@Patch(':restaurantPaymentMethodId')
|
||||||
@ApiOperation({ summary: 'Update a restaurant payment method' })
|
@ApiOperation({ summary: 'Update a restaurant payment method' })
|
||||||
@ApiParam({ name: 'id', type: 'string', description: 'Restaurant payment method ID' })
|
@ApiParam({ name: 'restaurantPaymentMethodId', type: 'string', description: 'Restaurant payment method ID' })
|
||||||
@ApiBody({ type: UpdateRestaurantPaymentMethodDto })
|
@ApiBody({ type: UpdateRestaurantPaymentMethodDto })
|
||||||
@ApiOkResponse({ description: 'Restaurant payment method updated successfully' })
|
@ApiOkResponse({ description: 'Restaurant payment method updated successfully' })
|
||||||
@ApiNotFoundResponse({ description: 'Restaurant payment method not found' })
|
@ApiNotFoundResponse({ description: 'Restaurant payment method not found' })
|
||||||
update(@Param('id') id: string, @Body() updateRestaurantPaymentMethodDto: UpdateRestaurantPaymentMethodDto) {
|
update(
|
||||||
return this.restaurantPaymentMethodService.update(id, updateRestaurantPaymentMethodDto);
|
@Param('restaurantPaymentMethodId') restaurantPaymentMethodId: string,
|
||||||
|
@Body() updateRestaurantPaymentMethodDto: UpdateRestaurantPaymentMethodDto,
|
||||||
|
) {
|
||||||
|
return this.restaurantPaymentMethodService.update(restaurantPaymentMethodId, updateRestaurantPaymentMethodDto);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Delete(':id')
|
@Delete(':restaurantPaymentMethodId')
|
||||||
@ApiOperation({ summary: 'Delete a restaurant payment method' })
|
@ApiOperation({ summary: 'Delete a restaurant payment method' })
|
||||||
@ApiParam({ name: 'id', type: 'string', description: 'Restaurant payment method ID' })
|
@ApiParam({ name: 'restaurantPaymentMethodId', type: 'string', description: 'Restaurant payment method ID' })
|
||||||
@ApiOkResponse({ description: 'Restaurant payment method deleted successfully' })
|
@ApiOkResponse({ description: 'Restaurant payment method deleted successfully' })
|
||||||
@ApiNotFoundResponse({ description: 'Restaurant payment method not found' })
|
@ApiNotFoundResponse({ description: 'Restaurant payment method not found' })
|
||||||
remove(@Param('id') id: string) {
|
remove(@Param('restaurantPaymentMethodId') restaurantPaymentMethodId: string) {
|
||||||
return this.restaurantPaymentMethodService.remove(id);
|
return this.restaurantPaymentMethodService.remove(restaurantPaymentMethodId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +1,5 @@
|
|||||||
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, 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
export class UpdateRestaurantPaymentMethodDto extends PartialType(CreateRestaurantPaymentMethodDto) {}
|
||||||
|
|||||||
@@ -16,8 +16,6 @@ export class RestaurantPaymentMethod extends BaseEntity {
|
|||||||
@Property({ nullable: true })
|
@Property({ nullable: true })
|
||||||
merchantId?: string;
|
merchantId?: string;
|
||||||
|
|
||||||
@Property({ type: 'decimal', precision: 10, scale: 2, default: 0 })
|
|
||||||
price: number = 0;
|
|
||||||
|
|
||||||
@Property({ type: 'boolean', default: true })
|
@Property({ type: 'boolean', default: true })
|
||||||
isActive: boolean = true;
|
isActive: boolean = true;
|
||||||
|
|||||||
@@ -67,9 +67,9 @@ export class RestaurantPaymentMethodService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async findByPaymentMethod(paymentMethodId: string): Promise<RestaurantPaymentMethod[]> {
|
async findByPaymentMethod(restPaymentMethodId: string): Promise<RestaurantPaymentMethod[]> {
|
||||||
return this.restaurantPaymentMethodRepository.find(
|
return this.restaurantPaymentMethodRepository.find(
|
||||||
{ paymentMethod: { id: paymentMethodId } },
|
{ id: restPaymentMethodId },
|
||||||
{ populate: ['restaurant', 'paymentMethod'] },
|
{ populate: ['restaurant', 'paymentMethod'] },
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -91,14 +91,6 @@ export class RestaurantPaymentMethodService {
|
|||||||
): Promise<RestaurantPaymentMethod> {
|
): Promise<RestaurantPaymentMethod> {
|
||||||
const restaurantPaymentMethod = await this.findOne(id);
|
const restaurantPaymentMethod = await this.findOne(id);
|
||||||
|
|
||||||
if (updateRestaurantPaymentMethodDto.restaurantId) {
|
|
||||||
const restaurant = await this.em.findOne(Restaurant, { id: updateRestaurantPaymentMethodDto.restaurantId });
|
|
||||||
if (!restaurant) {
|
|
||||||
throw new NotFoundException(`Restaurant with ID ${updateRestaurantPaymentMethodDto.restaurantId} not found`);
|
|
||||||
}
|
|
||||||
restaurantPaymentMethod.restaurant = restaurant;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (updateRestaurantPaymentMethodDto.paymentMethodId) {
|
if (updateRestaurantPaymentMethodDto.paymentMethodId) {
|
||||||
const paymentMethod = await this.em.findOne(PaymentMethod, {
|
const paymentMethod = await this.em.findOne(PaymentMethod, {
|
||||||
id: updateRestaurantPaymentMethodDto.paymentMethodId,
|
id: updateRestaurantPaymentMethodDto.paymentMethodId,
|
||||||
|
|||||||
@@ -225,7 +225,6 @@ export class DatabaseSeeder extends Seeder {
|
|||||||
restaurant,
|
restaurant,
|
||||||
paymentMethod,
|
paymentMethod,
|
||||||
isActive: true,
|
isActive: true,
|
||||||
price: 100_000,
|
|
||||||
});
|
});
|
||||||
em.persist(restaurantPaymentMethod);
|
em.persist(restaurantPaymentMethod);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user