Browse Source

fix(core): Join eager relations on OrderService.findOne method

Michael Bromley 4 years ago
parent
commit
5e181ea44c
1 changed files with 8 additions and 3 deletions
  1. 8 3
      packages/core/src/service/services/order.service.ts

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

@@ -37,6 +37,7 @@ import {
 import { ID, PaginatedList } from '@vendure/common/lib/shared-types';
 import { ID, PaginatedList } from '@vendure/common/lib/shared-types';
 import { summate } from '@vendure/common/lib/shared-utils';
 import { summate } from '@vendure/common/lib/shared-utils';
 import { unique } from '@vendure/common/lib/unique';
 import { unique } from '@vendure/common/lib/unique';
+import { FindOptionsUtils } from 'typeorm/find-options/FindOptionsUtils';
 
 
 import { RequestContext } from '../../api/common/request-context';
 import { RequestContext } from '../../api/common/request-context';
 import { ErrorResultUnion, isGraphQlErrorResult } from '../../common/error/error-result';
 import { ErrorResultUnion, isGraphQlErrorResult } from '../../common/error/error-result';
@@ -183,7 +184,7 @@ export class OrderService {
     }
     }
 
 
     async findOne(ctx: RequestContext, orderId: ID): Promise<Order | undefined> {
     async findOne(ctx: RequestContext, orderId: ID): Promise<Order | undefined> {
-        const order = await this.connection
+        const qb = this.connection
             .getRepository(ctx, Order)
             .getRepository(ctx, Order)
             .createQueryBuilder('order')
             .createQueryBuilder('order')
             .leftJoin('order.channels', 'channel')
             .leftJoin('order.channels', 'channel')
@@ -203,8 +204,12 @@ export class OrderService {
             .where('order.id = :orderId', { orderId })
             .where('order.id = :orderId', { orderId })
             .andWhere('channel.id = :channelId', { channelId: ctx.channelId })
             .andWhere('channel.id = :channelId', { channelId: ctx.channelId })
             .addOrderBy('lines.createdAt', 'ASC')
             .addOrderBy('lines.createdAt', 'ASC')
-            .addOrderBy('items.createdAt', 'ASC')
-            .getOne();
+            .addOrderBy('items.createdAt', 'ASC');
+
+        // tslint:disable-next-line:no-non-null-assertion
+        FindOptionsUtils.joinEagerRelations(qb, qb.alias, qb.expressionMap.mainAlias!.metadata);
+
+        const order = await qb.getOne();
         if (order) {
         if (order) {
             for (const line of order.lines) {
             for (const line of order.lines) {
                 line.productVariant = translateDeep(
                 line.productVariant = translateDeep(