Skip to content

Commit

Permalink
Merge pull request #216 from Roger13579/fix/create-order-plan
Browse files Browse the repository at this point in the history
fix: calculate total price error and float handling
  • Loading branch information
Roger13579 authored Jun 13, 2024
2 parents 3b42406 + 7f6e1dc commit 633e616
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/dto/order/createOrderDto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export class CreateOrderDto {
this._items = Object.values(groupBy(items, 'productId')).map((group) => ({
productId: group[0].productId,
amount: sumBy(group, 'amount'),
plan: group[0].plan,
}));
this.paymentMethod = paymentMethod;
this.paymentStatus = PaymentStatus.pending;
Expand Down
6 changes: 5 additions & 1 deletion src/service/orderService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,12 @@ export class OrderService {
const subTotal = sumBy(
products,
({ price, amount, plan }) =>
price * amount * (plan ? plan.headCount * plan.discount : 1),
Math.round(
price * amount * (plan ? plan.headCount * plan.discount : 1) * 100,
) / 100,
);
logger.info('totalPrice = ' + totalPrice);
logger.info('subTotal = ' + subTotal);
return totalPrice === subTotal;
};

Expand Down

0 comments on commit 633e616

Please sign in to comment.