feat: add optional slug field to UpdateSectionDto and update service to support manual slug overrides

This commit is contained in:
pradeepkumar
2026-04-11 23:05:56 +05:30
parent bebff19052
commit 91336e5ead
2 changed files with 28 additions and 9 deletions

View File

@@ -108,22 +108,27 @@ export class ProfileSectionsService {
const data: any = { ...updateSectionDto };
// If name is being updated, update the slug too
if (updateSectionDto.name) {
const newSlug = this.generateSlug(updateSectionDto.name);
// 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);
}
// Check if new slug conflicts with another section
if (effectiveSlug) {
// Check if slug conflicts with another section
const existing = await this.prisma.profileSection.findFirst({
where: {
AND: [{ id: { not: id } }, { slug: newSlug }],
AND: [{ id: { not: id } }, { slug: effectiveSlug }],
},
});
if (existing) {
throw new ConflictException('A section with this name already exists');
throw new ConflictException('A section with this slug already exists');
}
data.slug = newSlug;
data.slug = effectiveSlug;
}
return this.prisma.profileSection.update({