From a5c500dbb395d85ef85efbea4bdc506266640902 Mon Sep 17 00:00:00 2001 From: Schalli Date: Tue, 7 Jul 2026 09:57:24 +0200 Subject: [PATCH] fix(ldap): remove DTO default initializers that clobbered partial updates CreateLdapConfigDto's optional fields (searchFilter, syncIntervalMin, isActive, groupFilterDns) had class-field default initializers. NestJS's ValidationPipe instantiates DTOs via plainToInstance, which applies those defaults even when the field is absent from the request body -- so any partial PATCH not including a given field silently reset it to the hardcoded default instead of leaving it untouched. Caught by testing the new groupFilterDns-only PATCH: saving the group filter alone reset searchFilter back to "(objectClass=person)", clobbering the configured Active Directory filter. The service layer already has its own `?? default` fallback for create, so the DTO initializers were redundant and unsafe. Removing them makes updateConfig's existing "only set if dto.field !== undefined" pattern behave correctly for every optional field, not just the ones sent together in one request. Co-Authored-By: Claude Sonnet 5 --- apps/api/src/ldap/dto/ldap-config.dto.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/apps/api/src/ldap/dto/ldap-config.dto.ts b/apps/api/src/ldap/dto/ldap-config.dto.ts index e8d3892..286b44e 100644 --- a/apps/api/src/ldap/dto/ldap-config.dto.ts +++ b/apps/api/src/ldap/dto/ldap-config.dto.ts @@ -31,21 +31,21 @@ export class CreateLdapConfigDto { @IsString() @IsOptional() - searchFilter?: string = '(objectClass=person)'; + searchFilter?: string; @IsInt() @IsOptional() @Min(0) - syncIntervalMin?: number = 60; + syncIntervalMin?: number; @IsBoolean() @IsOptional() - isActive?: boolean = true; + isActive?: boolean; @IsArray() @IsString({ each: true }) @IsOptional() - groupFilterDns?: string[] = []; + groupFilterDns?: string[]; } /**