add packing fee
This commit is contained in:
@@ -83,6 +83,7 @@ export class OrdersService {
|
||||
subTotal: cart.subTotal || 0,
|
||||
tax: cart.tax || 0,
|
||||
deliveryFee: cart.deliveryFee || 0,
|
||||
packingFee: 0,
|
||||
total: cart.total || 0,
|
||||
totalItems: cart.totalItems || 0,
|
||||
description: cart.description,
|
||||
@@ -169,13 +170,14 @@ export class OrdersService {
|
||||
const subTotal = orderItemsData.reduce((sum, item) => sum + item.unitPrice * item.quantity, 0);
|
||||
const itemsDiscount = orderItemsData.reduce((sum, item) => sum + item.discount * item.quantity, 0);
|
||||
const deliveryFee = delivery.deliveryFeeType === DeliveryFeeTypeEnum.FIXED ? Number(delivery.deliveryFee) : 0;
|
||||
const packingFee = dto.packingFee ?? 0;
|
||||
const adminDiscount = dto.discountAmount ?? 0;
|
||||
const maxDiscount = subTotal - itemsDiscount;
|
||||
if (adminDiscount > maxDiscount) {
|
||||
throw new BadRequestException(OrderMessage.DISCOUNT_AMOUNT_EXCEEDS_ORDER_TOTAL);
|
||||
}
|
||||
const totalDiscount = itemsDiscount + adminDiscount;
|
||||
const total = subTotal - totalDiscount + deliveryFee;
|
||||
const total = subTotal - totalDiscount + deliveryFee + packingFee;
|
||||
const totalItems = orderItemsData.reduce((sum, item) => sum + item.quantity, 0);
|
||||
|
||||
const order = await this.em.transactional(async em => {
|
||||
@@ -193,6 +195,7 @@ export class OrdersService {
|
||||
subTotal,
|
||||
tax: 0,
|
||||
deliveryFee,
|
||||
packingFee,
|
||||
total,
|
||||
totalItems,
|
||||
description: dto.description,
|
||||
|
||||
Reference in New Issue
Block a user