refactor: disable automatic slug regeneration on field and section name updates to ensure stable references
This commit is contained in:
@@ -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({
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user