Skip to content

Commit 068176c

Browse files
authored
feat(core): Throw error on taxSummary if surcharges relation is not loaded (#3569)
1 parent f248719 commit 068176c

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

packages/core/e2e/entity-serialization.e2e-spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ describe('Entity serialization', () => {
218218
const ctx = await createCtx();
219219
const order = await server.app
220220
.get(OrderService)
221-
.findOne(ctx, 1, ['lines', 'shippingLines.shippingMethod']);
221+
.findOne(ctx, 1, ['lines', 'surcharges', 'shippingLines.shippingMethod']);
222222

223223
expect(order).not.toBeNull();
224224
expect(order instanceof Order).toBe(true);

packages/core/src/entity/order/order.entity.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,9 +291,10 @@ export class Order extends VendureEntity implements ChannelAware, HasCustomField
291291
* @description
292292
* A summary of the taxes being applied to this Order.
293293
*/
294-
@Calculated({ relations: ['lines'] })
294+
@Calculated({ relations: ['lines', 'surcharges'] })
295295
get taxSummary(): OrderTaxSummary[] {
296296
this.throwIfLinesNotJoined('taxSummary');
297+
this.throwIfSurchargesNotJoined('taxSummary');
297298
const taxRateMap = new Map<
298299
string,
299300
{ rate: number; base: number; tax: number; description: string }
@@ -352,6 +353,16 @@ export class Order extends VendureEntity implements ChannelAware, HasCustomField
352353
"This can be done with the EntityHydratorService: `await entityHydratorService.hydrate(ctx, order, { relations: ['lines'] })`",
353354
];
354355

356+
throw new InternalServerError(errorMessage.join('\n'));
357+
}
358+
}
359+
private throwIfSurchargesNotJoined(propertyName: keyof Order) {
360+
if (this.surcharges == null) {
361+
const errorMessage = [
362+
`The property "${propertyName}" on the Order entity requires the Order.surcharges relation to be joined.`,
363+
"This can be done with the EntityHydratorService: `await entityHydratorService.hydrate(ctx, order, { relations: ['surcharges'] })`",
364+
];
365+
355366
throw new InternalServerError(errorMessage.join('\n'));
356367
}
357368
}

0 commit comments

Comments
 (0)