diff --git a/src/profile-fields/profile-fields.service.ts b/src/profile-fields/profile-fields.service.ts index 38ccf3c..66ab726 100644 --- a/src/profile-fields/profile-fields.service.ts +++ b/src/profile-fields/profile-fields.service.ts @@ -134,7 +134,8 @@ export class ProfileFieldsService { const data: any = { ...updateFieldDto }; - // If slug is explicitly provided, use it; otherwise auto-generate from name + // Slug only changes when the admin explicitly edits it — renaming the field never + // regenerates the slug, so field value references stay stable. if (updateFieldDto.slug) { const newSlug = updateFieldDto.slug; const existing = await this.prisma.profileField.findFirst({ @@ -150,21 +151,6 @@ export class ProfileFieldsService { throw new ConflictException('A field with this slug already exists in this section'); } data.slug = newSlug; - } else if (updateFieldDto.name) { - const newSlug = this.generateSlug(updateFieldDto.name); - const existing = await this.prisma.profileField.findFirst({ - where: { - AND: [ - { id: { not: id } }, - { sectionId: field.sectionId }, - { slug: newSlug }, - ], - }, - }); - if (existing) { - throw new ConflictException('A field with this name already exists in this section'); - } - data.slug = newSlug; } return this.prisma.profileField.update({ diff --git a/src/profile-fields/profile-sections.service.ts b/src/profile-fields/profile-sections.service.ts index bcc8d78..c40fa8d 100644 --- a/src/profile-fields/profile-sections.service.ts +++ b/src/profile-fields/profile-sections.service.ts @@ -108,13 +108,9 @@ export class ProfileSectionsService { const data: any = { ...updateSectionDto }; - // Resolve effective slug: explicit slug from DTO wins; otherwise regenerate from name if name changed - let effectiveSlug: string | undefined; - if (updateSectionDto.slug) { - effectiveSlug = updateSectionDto.slug; - } else if (updateSectionDto.name) { - effectiveSlug = this.generateSlug(updateSectionDto.name); - } + // Slug only changes when admin explicitly sends one — renaming the section never + // regenerates it, so field/section references stay stable. + const effectiveSlug: string | undefined = updateSectionDto.slug; if (effectiveSlug) { // Check if slug conflicts with another section