From d92e0538bda18643723290b46ae5d85d3b7d3dff Mon Sep 17 00:00:00 2001 From: Kailasdevdas Date: Mon, 18 May 2026 10:58:14 +0530 Subject: [PATCH] fix: make category slug optional --- .../20260518051754_make_slug_optional/migration.sql | 2 ++ backend/prisma/schema.prisma | 2 +- backend/src/controllers/healthCheck.controller.js | 4 +++- 3 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 backend/prisma/migrations/20260518051754_make_slug_optional/migration.sql diff --git a/backend/prisma/migrations/20260518051754_make_slug_optional/migration.sql b/backend/prisma/migrations/20260518051754_make_slug_optional/migration.sql new file mode 100644 index 0000000..b41cd76 --- /dev/null +++ b/backend/prisma/migrations/20260518051754_make_slug_optional/migration.sql @@ -0,0 +1,2 @@ +-- AlterTable +ALTER TABLE "HealthCheckCategory" ALTER COLUMN "slug" DROP NOT NULL; diff --git a/backend/prisma/schema.prisma b/backend/prisma/schema.prisma index d35b4ec..482000e 100644 --- a/backend/prisma/schema.prisma +++ b/backend/prisma/schema.prisma @@ -224,7 +224,7 @@ model NewsImage { model HealthCheckCategory { id Int @id @default(autoincrement()) name String @unique - slug String @unique + slug String? @unique description String? isActive Boolean @default(true) sortOrder Int @default(1000) diff --git a/backend/src/controllers/healthCheck.controller.js b/backend/src/controllers/healthCheck.controller.js index 6803063..b039d80 100644 --- a/backend/src/controllers/healthCheck.controller.js +++ b/backend/src/controllers/healthCheck.controller.js @@ -28,7 +28,7 @@ export const createCategory = async (req, res) => { const category = await prisma.healthCheckCategory.create({ data: { name, - slug, + slug: slug || null, description, isActive: isActive ?? true, sortOrder: sortOrder ? Number(sortOrder) : 1000, @@ -58,6 +58,8 @@ export const updateCategory = async (req, res) => { if (data.sortOrder !== undefined) data.sortOrder = Number(data.sortOrder); + if (data.slug === "") data.slug = null; + const updatedCategory = await prisma.$transaction(async (tx) => { const category = await tx.healthCheckCategory.update({ where: { id: Number(id) },