diff --git a/src/order/entities/order.entity.ts b/src/order/entities/order.entity.ts index 47a05b0..d46698e 100644 --- a/src/order/entities/order.entity.ts +++ b/src/order/entities/order.entity.ts @@ -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; diff --git a/src/order/migrations/1747172177914-add-price-order-detail-migration.ts b/src/order/migrations/1747172177914-add-price-order-detail-migration.ts new file mode 100644 index 0000000..50128c0 --- /dev/null +++ b/src/order/migrations/1747172177914-add-price-order-detail-migration.ts @@ -0,0 +1,17 @@ +import { MigrationInterface, QueryRunner } from 'typeorm'; + +export class AddPriceOrderDetailMigration1747172177914 + implements MigrationInterface +{ + name = 'AddPriceOrderDetailMigration1747172177914'; + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query( + `ALTER TABLE "order_detail" ADD "price" integer NOT NULL`, + ); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE "order_detail" DROP COLUMN "price"`); + } +} diff --git a/src/order/order.service.ts b/src/order/order.service.ts index da50598..7132143 100644 --- a/src/order/order.service.ts +++ b/src/order/order.service.ts @@ -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 @@ -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);