From b9912be67a33a8493127b5483e0db77618ccd82a Mon Sep 17 00:00:00 2001 From: Abraham <1001.28021547.ucla@gmail.com> Date: Fri, 16 May 2025 16:19:53 -0400 Subject: [PATCH 1/3] add paymentConfirmation to orderDetail entity --- src/order/entities/order.entity.ts | 8 ++++++ ...-confirmation-in-order-detail-migration.ts | 25 +++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 src/order/migrations/1747426506331-add-payment-confirmation-in-order-detail-migration.ts diff --git a/src/order/entities/order.entity.ts b/src/order/entities/order.entity.ts index d002a07..799cf46 100644 --- a/src/order/entities/order.entity.ts +++ b/src/order/entities/order.entity.ts @@ -94,4 +94,12 @@ export class OrderDetail extends UUIDModel { (orderDeliveryDetail) => orderDeliveryDetail.orderDetail, ) orderDetailDeliveries: OrderDetailDelivery[]; + + @ManyToOne(() => PaymentConfirmation, { + nullable: true, + eager: true, + onDelete: 'SET NULL', + }) + @JoinColumn({ name: 'payment_confirmation_id' }) + paymentConfirmation: PaymentConfirmation; } diff --git a/src/order/migrations/1747426506331-add-payment-confirmation-in-order-detail-migration.ts b/src/order/migrations/1747426506331-add-payment-confirmation-in-order-detail-migration.ts new file mode 100644 index 0000000..5f1cbba --- /dev/null +++ b/src/order/migrations/1747426506331-add-payment-confirmation-in-order-detail-migration.ts @@ -0,0 +1,25 @@ +import { MigrationInterface, QueryRunner } from 'typeorm'; + +export class AddPaymentConfirmationInOrderDetailMigration1747426506331 + implements MigrationInterface +{ + name = 'AddPaymentConfirmationInOrderDetailMigration1747426506331'; + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query( + `ALTER TABLE "order_detail" ADD "payment_confirmation_id" uuid`, + ); + await queryRunner.query( + `ALTER TABLE "order_detail" ADD CONSTRAINT "FK_2cb24b410baacf4bd387b22757e" FOREIGN KEY ("payment_confirmation_id") REFERENCES "payment_confirmation"("id") ON DELETE SET NULL ON UPDATE NO ACTION`, + ); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query( + `ALTER TABLE "order_detail" DROP CONSTRAINT "FK_2cb24b410baacf4bd387b22757e"`, + ); + await queryRunner.query( + `ALTER TABLE "order_detail" DROP COLUMN "payment_confirmation_id"`, + ); + } +} From 3ea97d0cc2244fd87e8c85a1897b55b3c1866b73 Mon Sep 17 00:00:00 2001 From: Abraham <1001.28021547.ucla@gmail.com> Date: Sat, 17 May 2025 20:24:07 -0400 Subject: [PATCH 2/3] add paymentConfirmation to ResponseOrderDetailDTO --- src/order/dto/order.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/order/dto/order.ts b/src/order/dto/order.ts index 1096e04..38a8c24 100644 --- a/src/order/dto/order.ts +++ b/src/order/dto/order.ts @@ -19,6 +19,7 @@ import { ResponseOrderProductPresentationDetailDTO } from 'src/products/dto/prod import { ResponseBranchDTO } from 'src/branch/dto/branch.dto'; import { OrderDeliveryEmployeeDTO } from './order-delivery.dto'; import { PaymentMethod } from 'src/payments/entities/payment-information.entity'; +import { ResponsePaymentConfirmationDTO } from 'src/payments/dto/payment-confirmation.dto'; export class CreateOrderDetailDTO { @ApiProperty({ description: 'ID of the product presentation' }) @@ -117,6 +118,15 @@ export class ResponseOrderDetailDTO { @Expose() @ApiProperty({ description: 'Subtotal price of the order detail' }) subtotal: number; + + @Expose() + @ApiProperty({ + description: 'Payment confirmation data (if any)', + type: ResponsePaymentConfirmationDTO, + required: false, + }) + @Type(() => ResponsePaymentConfirmationDTO) + paymentConfirmation?: ResponsePaymentConfirmationDTO; } export class ResponseOrderDTO extends BaseDTO { From 218d067873e3c448c6bc01d3e914d57f7f046298 Mon Sep 17 00:00:00 2001 From: Abraham <1001.28021547.ucla@gmail.com> Date: Sat, 17 May 2025 21:08:09 -0400 Subject: [PATCH 3/3] add price to ResponseOrderDetailDTO --- src/order/dto/order.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/order/dto/order.ts b/src/order/dto/order.ts index 57133c3..aaee166 100644 --- a/src/order/dto/order.ts +++ b/src/order/dto/order.ts @@ -116,6 +116,12 @@ export class ResponseOrderDetailDTO { @IsPositive() quantity: number; + @Expose() + @ApiProperty({ description: 'Product price' }) + @IsInt() + @IsPositive() + price: number; + @Expose() @ApiProperty({ description: 'Subtotal price of the order detail' }) subtotal: number;