Skip to content

Commit 1633446

Browse files
authored
fix(core): Persist customFields in updateGlobalSettings mutation (vendurehq#4343)
1 parent b3d1903 commit 1633446

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

packages/core/e2e/custom-field-relations.e2e-spec.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,44 @@ describe('Custom field relations', () => {
710710
`);
711711
assertCustomFieldIds(updateGlobalSettings.customFields, 'T_2', ['T_3', 'T_4']);
712712
});
713+
714+
it('updating scalar custom fields persists alongside relational ones', async () => {
715+
await adminClient.query(gql`
716+
mutation {
717+
updateGlobalSettings(
718+
input: {
719+
customFields: {
720+
primitive: "updated_value"
721+
singleId: "T_2"
722+
multiIds: ["T_3", "T_4"]
723+
}
724+
}
725+
) {
726+
... on GlobalSettings {
727+
id
728+
}
729+
}
730+
}
731+
`);
732+
733+
const { updateGlobalSettings } = await adminClient.query(gql`
734+
mutation {
735+
updateGlobalSettings(
736+
input: {
737+
customFields: { singleId: "T_3" }
738+
}
739+
) {
740+
... on GlobalSettings {
741+
id
742+
${customFieldsSelection}
743+
}
744+
}
745+
}
746+
`);
747+
748+
expect(updateGlobalSettings.customFields.single).toEqual({ id: 'T_3' });
749+
expect(updateGlobalSettings.customFields.primitive).toBe('updated_value');
750+
});
713751
});
714752

715753
describe('Order entity', () => {

packages/core/src/service/services/global-settings.service.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,10 @@ export class GlobalSettingsService {
7676

7777
async updateSettings(ctx: RequestContext, input: UpdateGlobalSettingsInput): Promise<GlobalSettings> {
7878
const settings = await this.getSettings(ctx);
79-
await this.eventBus.publish(new GlobalSettingsEvent(ctx, settings, input));
8079
patchEntity(settings, input);
80+
await this.eventBus.publish(new GlobalSettingsEvent(ctx, settings, input));
81+
await this.connection.getRepository(ctx, GlobalSettings).save(settings);
8182
await this.customFieldRelationService.updateRelations(ctx, GlobalSettings, input, settings);
82-
return this.connection.getRepository(ctx, GlobalSettings).save(settings);
83+
return settings;
8384
}
8485
}

0 commit comments

Comments
 (0)