From bb40bc9929d9b14d600fcc7314e879763d70743b Mon Sep 17 00:00:00 2001 From: Weiko Date: Fri, 4 Apr 2025 10:58:53 +0200 Subject: [PATCH] Fix update field default value (#11386) Fixes https://github.com/twentyhq/twenty/issues/11379 --- .../hooks/before-update-one-field.hook.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/twenty-server/src/engine/metadata-modules/field-metadata/hooks/before-update-one-field.hook.ts b/packages/twenty-server/src/engine/metadata-modules/field-metadata/hooks/before-update-one-field.hook.ts index 03cc95a51..5eca92327 100644 --- a/packages/twenty-server/src/engine/metadata-modules/field-metadata/hooks/before-update-one-field.hook.ts +++ b/packages/twenty-server/src/engine/metadata-modules/field-metadata/hooks/before-update-one-field.hook.ts @@ -80,6 +80,7 @@ export class BeforeUpdateOneField 'isLabelSyncedWithName', 'options', 'settings', + 'defaultValue', ]; const overridableFields = ['label', 'icon', 'description']; @@ -102,7 +103,7 @@ export class BeforeUpdateOneField if (nonUpdatableFields.length > 0) { throw new BadRequestException( - `Only isActive, isLabelSyncedWithName, label, icon and description fields can be updated for standard fields. Invalid fields: ${nonUpdatableFields.join(', ')}`, + `Only isActive, isLabelSyncedWithName, label, icon, description and defaultValue fields can be updated for standard fields. Invalid fields: ${nonUpdatableFields.join(', ')}`, ); } @@ -116,6 +117,7 @@ export class BeforeUpdateOneField this.handleStandardOverrides(instance, fieldMetadata, update, locale); this.handleOptionsField(instance, update); this.handleSettingsField(instance, update); + this.handleDefaultValueField(instance, update); return { id: instance.id, @@ -123,6 +125,17 @@ export class BeforeUpdateOneField }; } + private handleDefaultValueField( + instance: UpdateOneInputType, + update: StandardFieldUpdate, + ): void { + if (!isDefined(instance.update.defaultValue)) { + return; + } + + update.defaultValue = instance.update.defaultValue; + } + private handleOptionsField( instance: UpdateOneInputType, update: StandardFieldUpdate,