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,
discountedPrice,
inclusions,
categoryId: Number(categoryId),
category: {
connect: { id: Number(categoryId) },
},
isActive: isActive ?? true,
isFeatured: isFeatured ?? false,
sortOrder: sortOrder ? Number(sortOrder) : 1000,
@@ -184,15 +186,23 @@ export const updatePackage = async (req, res) => {
try {
const { id } = req.params;
const data = { ...req.body };
delete data.id;
delete data.category;
delete data.createdAt;
delete data.updatedAt;
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);
const seoData = data.seo;
delete data.seo;
const existingPackage = await prisma.healthPackage.findUnique({
where: { id: Number(id) },
select: { slug: true },
@@ -205,29 +215,29 @@ export const updatePackage = async (req, res) => {
data: {
...data,
seo: data.seo
seo: seoData
? {
upsert: {
create: {
seoTitle: data.seo.seoTitle,
metaDescription: data.seo.metaDescription,
focusKeyphrase: data.seo.focusKeyphrase,
seoTitle: seoData.seoTitle,
metaDescription: seoData.metaDescription,
focusKeyphrase: seoData.focusKeyphrase,
slug: seoSlug,
tags: data.seo.tags || [],
ogTitle: data.seo.ogTitle,
ogDescription: data.seo.ogDescription,
ogImage: data.seo.ogImage,
tags: seoData.tags || [],
ogTitle: seoData.ogTitle,
ogDescription: seoData.ogDescription,
ogImage: seoData.ogImage,
},
update: {
seoTitle: data.seo.seoTitle,
metaDescription: data.seo.metaDescription,
focusKeyphrase: data.seo.focusKeyphrase,
seoTitle: seoData.seoTitle,
metaDescription: seoData.metaDescription,
focusKeyphrase: seoData.focusKeyphrase,
slug: seoSlug,
tags: data.seo.tags || [],
ogTitle: data.seo.ogTitle,
ogDescription: data.seo.ogDescription,
ogImage: data.seo.ogImage,
tags: seoData.tags || [],
ogTitle: seoData.ogTitle,
ogDescription: seoData.ogDescription,
ogImage: seoData.ogImage,
},
},
}