diff --git a/src/order/dto/order.ts b/src/order/dto/order.ts index eb5eb5e..aaee166 100644 --- a/src/order/dto/order.ts +++ b/src/order/dto/order.ts @@ -20,6 +20,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' }) @@ -115,9 +116,24 @@ 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; + + @Expose() + @ApiProperty({ + description: 'Payment confirmation data (if any)', + type: ResponsePaymentConfirmationDTO, + required: false, + }) + @Type(() => ResponsePaymentConfirmationDTO) + paymentConfirmation?: ResponsePaymentConfirmationDTO; } export class ResponseOrderDTO extends BaseDTO { 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"`, + ); + } +}