Parcourir la source

fix(core): Fix updating channel currencyCode

Fixes #2114
Michael Bromley il y a 2 ans
Parent
commit
7e01ecf1de

+ 16 - 3
packages/core/e2e/channel.e2e-spec.ts

@@ -11,17 +11,16 @@ import path from 'path';
 import { afterAll, beforeAll, describe, expect, it } from 'vitest';
 
 import { initialData } from '../../../e2e-common/e2e-initial-data';
-import { testConfig, TEST_SETUP_TIMEOUT_MS } from '../../../e2e-common/test-config';
+import { TEST_SETUP_TIMEOUT_MS, testConfig } from '../../../e2e-common/test-config';
 
+import * as Codegen from './graphql/generated-e2e-admin-types';
 import {
-    ChannelFragment,
     CurrencyCode,
     DeletionResult,
     ErrorCode,
     LanguageCode,
     Permission,
 } from './graphql/generated-e2e-admin-types';
-import * as Codegen from './graphql/generated-e2e-admin-types';
 import {
     ASSIGN_PRODUCT_TO_CHANNEL,
     CREATE_ADMINISTRATOR,
@@ -123,6 +122,20 @@ describe('Channels', () => {
         });
     });
 
+    it('update currencyCode', async () => {
+        const { updateChannel } = await adminClient.query<
+            Codegen.UpdateChannelMutation,
+            Codegen.UpdateChannelMutationVariables
+        >(UPDATE_CHANNEL, {
+            input: {
+                id: 'T_1',
+                currencyCode: CurrencyCode.MYR,
+            },
+        });
+        channelGuard.assertSuccess(updateChannel);
+        expect(updateChannel.currencyCode).toBe('MYR');
+    });
+
     it('superadmin has all permissions on new channel', async () => {
         const { me } = await adminClient.query<Codegen.MeQuery>(ME);
 

+ 3 - 0
packages/core/src/service/services/channel.service.ts

@@ -290,6 +290,9 @@ export class ChannelService {
             const seller = await this.connection.getEntityOrThrow(ctx, Seller, input.sellerId);
             updatedChannel.seller = seller;
         }
+        if (input.currencyCode) {
+            updatedChannel.defaultCurrencyCode = input.currencyCode;
+        }
         await this.connection.getRepository(ctx, Channel).save(updatedChannel, { reload: false });
         await this.customFieldRelationService.updateRelations(ctx, Channel, input, updatedChannel);
         await this.allChannels.refresh(ctx);