Browse Source

refactor(core): Optimize db calls when adjusting order lines

Michael Bromley 6 years ago
parent
commit
554357f958
1 changed files with 6 additions and 3 deletions
  1. 6 3
      packages/core/src/service/services/order.service.ts

+ 6 - 3
packages/core/src/service/services/order.service.ts

@@ -232,17 +232,20 @@ export class OrderService {
             order.lines.push(orderLine);
             await this.connection.getRepository(Order).save(order);
         }
-        return this.adjustOrderLine(ctx, orderId, orderLine.id, orderLine.quantity + quantity);
+        return this.adjustOrderLine(ctx, order, orderLine.id, orderLine.quantity + quantity);
     }
 
     async adjustOrderLine(
         ctx: RequestContext,
-        orderId: ID,
+        orderIdOrOrder: ID | Order,
         orderLineId: ID,
         quantity?: number | null,
         customFields?: { [key: string]: any },
     ): Promise<Order> {
-        const order = await this.getOrderOrThrow(ctx, orderId);
+        const order =
+            orderIdOrOrder instanceof Order
+                ? orderIdOrOrder
+                : await this.getOrderOrThrow(ctx, orderIdOrOrder);
         const orderLine = this.getOrderLineOrThrow(order, orderLineId);
         this.assertAddingItemsState(order);
         if (quantity != null) {