Skip to content

Commit

Permalink
refactor(core): Optimize db calls when adjusting order lines
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbromley committed Aug 2, 2019
1 parent ca2758f commit 554357f
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions packages/core/src/service/services/order.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 554357f

Please sign in to comment.