Merge pull request 'fix: resolve Prisma relation error in health package creation/update' (#55) from fix/healthpackage-bug into dev

Reviewed-on: #55
This commit was merged in pull request #55.
This commit is contained in:
2026-07-14 11:46:40 +00:00
@@ -147,7 +147,9 @@ export const createPackage = async (req, res) => {
image, image,
discountedPrice, discountedPrice,
inclusions, inclusions,
categoryId: Number(categoryId), category: {
connect: { id: Number(categoryId) },
},
isActive: isActive ?? true, isActive: isActive ?? true,
isFeatured: isFeatured ?? false, isFeatured: isFeatured ?? false,
sortOrder: sortOrder ? Number(sortOrder) : 1000, sortOrder: sortOrder ? Number(sortOrder) : 1000,
@@ -184,15 +186,23 @@ export const updatePackage = async (req, res) => {
try { try {
const { id } = req.params; const { id } = req.params;
const data = { ...req.body }; const data = { ...req.body };
delete data.id; delete data.id;
delete data.category; delete data.category;
delete data.createdAt; delete data.createdAt;
delete data.updatedAt; delete data.updatedAt;
delete data.seoId; delete data.seoId;
if (data.categoryId) data.categoryId = Number(data.categoryId); if (data.categoryId) {
data.category = { connect: { id: Number(data.categoryId) } };
delete data.categoryId;
}
if (data.sortOrder) data.sortOrder = Number(data.sortOrder); if (data.sortOrder) data.sortOrder = Number(data.sortOrder);
const seoData = data.seo;
delete data.seo;
const existingPackage = await prisma.healthPackage.findUnique({ const existingPackage = await prisma.healthPackage.findUnique({
where: { id: Number(id) }, where: { id: Number(id) },
select: { slug: true }, select: { slug: true },
@@ -205,29 +215,29 @@ export const updatePackage = async (req, res) => {
data: { data: {
...data, ...data,
seo: data.seo seo: seoData
? { ? {
upsert: { upsert: {
create: { create: {
seoTitle: data.seo.seoTitle, seoTitle: seoData.seoTitle,
metaDescription: data.seo.metaDescription, metaDescription: seoData.metaDescription,
focusKeyphrase: data.seo.focusKeyphrase, focusKeyphrase: seoData.focusKeyphrase,
slug: seoSlug, slug: seoSlug,
tags: data.seo.tags || [], tags: seoData.tags || [],
ogTitle: data.seo.ogTitle, ogTitle: seoData.ogTitle,
ogDescription: data.seo.ogDescription, ogDescription: seoData.ogDescription,
ogImage: data.seo.ogImage, ogImage: seoData.ogImage,
}, },
update: { update: {
seoTitle: data.seo.seoTitle, seoTitle: seoData.seoTitle,
metaDescription: data.seo.metaDescription, metaDescription: seoData.metaDescription,
focusKeyphrase: data.seo.focusKeyphrase, focusKeyphrase: seoData.focusKeyphrase,
slug: seoSlug, slug: seoSlug,
tags: data.seo.tags || [], tags: seoData.tags || [],
ogTitle: data.seo.ogTitle, ogTitle: seoData.ogTitle,
ogDescription: data.seo.ogDescription, ogDescription: seoData.ogDescription,
ogImage: data.seo.ogImage, ogImage: seoData.ogImage,
}, },
}, },
} }