Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/order/entities/order.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ export class OrderDetail extends UUIDModel {
@Column({ type: 'int', name: 'quantity' })
quantity: number;

@Column({ type: 'int', name: 'price' })
price: number;

@Column({ type: 'int', name: 'subtotal' })
subtotal: number;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

export class AddPriceOrderDetailMigration1747172177914
implements MigrationInterface
{
name = 'AddPriceOrderDetailMigration1747172177914';

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "order_detail" ADD "price" integer NOT NULL`,
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "order_detail" DROP COLUMN "price"`);
}
}
8 changes: 3 additions & 5 deletions src/order/order.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ export class OrderService {
);
}
}

let totalPrice = productsWithQuantity.reduce((acc, product) => {
const price = product.promo
? product.price - (product.price * product.promo.discount) / 100
Expand Down Expand Up @@ -132,11 +133,8 @@ export class OrderService {
order,
productPresentation: product,
quantity: product.quantity,
subtotal: product.promo
? Math.round(
product.price - (product.price * product.promo.discount) / 100,
) * product.quantity
: product.price * product.quantity,
price: product.price,
subtotal: product.price * product.quantity,
});
});
await this.orderDetailRepository.save(orderDetails);
Expand Down
Loading