Browse Source

fix(core): Fix error when calling assignToChannels on an Order

Fixes #1391
Michael Bromley 3 years ago
parent
commit
5dbca2d76c
1 changed files with 10 additions and 1 deletions
  1. 10 1
      packages/core/src/service/services/channel.service.ts

+ 10 - 1
packages/core/src/service/services/channel.service.ts

@@ -23,6 +23,7 @@ import { ConfigService } from '../../config/config.service';
 import { TransactionalConnection } from '../../connection/transactional-connection';
 import { TransactionalConnection } from '../../connection/transactional-connection';
 import { VendureEntity } from '../../entity/base/base.entity';
 import { VendureEntity } from '../../entity/base/base.entity';
 import { Channel } from '../../entity/channel/channel.entity';
 import { Channel } from '../../entity/channel/channel.entity';
+import { Order } from '../../entity/order/order.entity';
 import { ProductVariantPrice } from '../../entity/product-variant/product-variant-price.entity';
 import { ProductVariantPrice } from '../../entity/product-variant/product-variant-price.entity';
 import { Session } from '../../entity/session/session.entity';
 import { Session } from '../../entity/session/session.entity';
 import { Zone } from '../../entity/zone/zone.entity';
 import { Zone } from '../../entity/zone/zone.entity';
@@ -102,8 +103,16 @@ export class ChannelService {
         entityId: ID,
         entityId: ID,
         channelIds: ID[],
         channelIds: ID[],
     ): Promise<T> {
     ): Promise<T> {
+        const relations = ['channels'];
+        // This is a work-around for https://github.com/vendure-ecommerce/vendure/issues/1391
+        // A better API would be to allow the consumer of this method to supply an entity instance
+        // so that this join could be done prior to invoking this method.
+        // TODO: overload the assignToChannels method to allow it to take an entity instance
+        if (entityType === (Order as any)) {
+            relations.push('lines', 'shippingLines');
+        }
         const entity = await this.connection.getEntityOrThrow(ctx, entityType, entityId, {
         const entity = await this.connection.getEntityOrThrow(ctx, entityType, entityId, {
-            relations: ['channels'],
+            relations,
         });
         });
         for (const id of channelIds) {
         for (const id of channelIds) {
             const channel = await this.connection.getEntityOrThrow(ctx, Channel, id);
             const channel = await this.connection.getEntityOrThrow(ctx, Channel, id);