1
0
Эх сурвалжийг харах

feat(core): Throw error on taxSummary if surcharges relation is not loaded (#3569)

Alexander Berger 7 сар өмнө
parent
commit
068176cee4

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

@@ -218,7 +218,7 @@ describe('Entity serialization', () => {
         const ctx = await createCtx();
         const order = await server.app
             .get(OrderService)
-            .findOne(ctx, 1, ['lines', 'shippingLines.shippingMethod']);
+            .findOne(ctx, 1, ['lines', 'surcharges', 'shippingLines.shippingMethod']);
 
         expect(order).not.toBeNull();
         expect(order instanceof Order).toBe(true);

+ 12 - 1
packages/core/src/entity/order/order.entity.ts

@@ -291,9 +291,10 @@ export class Order extends VendureEntity implements ChannelAware, HasCustomField
      * @description
      * A summary of the taxes being applied to this Order.
      */
-    @Calculated({ relations: ['lines'] })
+    @Calculated({ relations: ['lines', 'surcharges'] })
     get taxSummary(): OrderTaxSummary[] {
         this.throwIfLinesNotJoined('taxSummary');
+        this.throwIfSurchargesNotJoined('taxSummary');
         const taxRateMap = new Map<
             string,
             { rate: number; base: number; tax: number; description: string }
@@ -352,6 +353,16 @@ export class Order extends VendureEntity implements ChannelAware, HasCustomField
                 "This can be done with the EntityHydratorService: `await entityHydratorService.hydrate(ctx, order, { relations: ['lines'] })`",
             ];
 
+            throw new InternalServerError(errorMessage.join('\n'));
+        }
+    }
+    private throwIfSurchargesNotJoined(propertyName: keyof Order) {
+        if (this.surcharges == null) {
+            const errorMessage = [
+                `The property "${propertyName}" on the Order entity requires the Order.surcharges relation to be joined.`,
+                "This can be done with the EntityHydratorService: `await entityHydratorService.hydrate(ctx, order, { relations: ['surcharges'] })`",
+            ];
+
             throw new InternalServerError(errorMessage.join('\n'));
         }
     }