Skip to content

Commit

Permalink
fix: Add type safety for order item update fields
Browse files Browse the repository at this point in the history
thomas-advantitge committed Feb 15, 2021
1 parent fe5184f commit 42bf55a
Showing 3 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion packages/core/src/entity/order-item/order-item.entity.ts
Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@ export class OrderItem extends VendureEntity {
line: OrderLine;

@EntityId()
lineId: ID;
lineId: ID; // TypeORM requires this ID field on the entity explicitly in order to save the foreign key via `.insert`

/**
* @description
Original file line number Diff line number Diff line change
@@ -158,7 +158,7 @@ export class OrderModifier {
listPriceIncludesTax: orderLine.productVariant.priceIncludesTax,
adjustments: [],
taxLines: [],
line: orderLine,
lineId: orderLine.id,
}),
);
}
16 changes: 8 additions & 8 deletions packages/core/src/service/services/order.service.ts
Original file line number Diff line number Diff line change
@@ -1328,21 +1328,21 @@ export class OrderService {
promotions,
updatedOrderLine ? [updatedOrderLine] : [],
);
// await this.connection.getRepository(ctx, OrderItem).save(updatedItems, { reload: false });
const updateFields: Array<keyof OrderItem> = [
'initialListPrice',
'listPrice',
'listPriceIncludesTax',
'adjustments',
'taxLines',
];
await this.connection
.getRepository(ctx, OrderItem)
.createQueryBuilder()
.insert()
.values(updatedItems)
.orUpdate({
conflict_target: ['id'],
overwrite: [
'initialListPrice',
'listPrice',
'listPriceIncludesTax',
'adjustments',
'taxLines',
],
overwrite: updateFields,
})
.updateEntity(false)
.execute();

0 comments on commit 42bf55a

Please sign in to comment.