This commit is contained in:
Your Name committed 2026-06-24 19:44:52 -04:00
1 parent 4536db6741
commit c23a4723ed
2 files changed
+20 -8

No files matched your search

+12
View File
@@ -117,6 +117,10 @@ export const categoriesRoute = new Elysia({ prefix: "/categories" })
const id = parseInt(params.id); const id = parseInt(params.id);
if (isNaN(id)) return status(400, { message: "Invalid category ID" }); if (isNaN(id)) return status(400, { message: "Invalid category ID" });
try {
const categoryExists = await prisma.category.findUnique({ where: { id } });
if (!categoryExists) return status(404, { message: "Category not found" });
const payload = body as any; const payload = body as any;
const results: any[] = []; const results: any[] = [];
@@ -145,12 +149,20 @@ export const categoriesRoute = new Elysia({ prefix: "/categories" })
} }
} }
if (results.length === 0) {
return status(400, { message: "No valid translations provided" });
}
const updated = await prisma.category.findUnique({ const updated = await prisma.category.findUnique({
where: { id }, where: { id },
include: { translations: true, _count: { select: { products: true } } }, include: { translations: true, _count: { select: { products: true } } },
}); });
return { success: true, translations: results, category: updated }; return { success: true, translations: results, category: updated };
} catch (err: any) {
console.error("Update category translations error:", err);
return status(500, { message: err?.message || "Failed to update translations" });
}
}) })
.post("/", async ({ body, status }) => { .post("/", async ({ body, status }) => {
try { try {
+8 -8
View File
@@ -200,7 +200,7 @@ export const pagesRoute = new Elysia({ prefix: "/pages" })
category: { category: {
include: { translations: true }, include: { translations: true },
}, },
scent: true, brand: true,
translations: true, translations: true,
variants: { variants: {
include: { include: {
@@ -219,9 +219,9 @@ export const pagesRoute = new Elysia({ prefix: "/pages" })
include: productInclude, include: productInclude,
take: limit take: limit
}); });
} else if (payload.type === 'scent' && payload.scentId) { } else if ((payload.type === 'scent' || payload.type === 'brand') && (payload.scentId || payload.brandId)) {
products = await prisma.product.findMany({ products = await prisma.product.findMany({
where: { scentId: Number(payload.scentId) }, where: { brandId: Number(payload.brandId || payload.scentId) },
include: productInclude, include: productInclude,
take: limit take: limit
}); });
@@ -247,7 +247,7 @@ export const pagesRoute = new Elysia({ prefix: "/pages" })
return { ...p, name: nameObj, description: descObj, details: detailsObj }; return { ...p, name: nameObj, description: descObj, details: detailsObj };
} else { } else {
const trans = p.translations?.find((t: any) => t.langCode === lang) || p.translations?.find((t: any) => t.langCode === 'th') || p.translations?.[0]; const trans = p.translations?.find((t: any) => t.langCode === lang) || p.translations?.find((t: any) => t.langCode === 'th') || p.translations?.[0];
return { ...p, name: trans?.name || p.scent?.name || '', description: trans?.description, details: trans?.details }; return { ...p, name: trans?.name || p.brand?.name || '', description: trans?.description, details: trans?.details };
} }
}); });
} else if (section.type === 'PRODUCT_CAROUSEL' && !Array.isArray(populatedPayload.products)) { } else if (section.type === 'PRODUCT_CAROUSEL' && !Array.isArray(populatedPayload.products)) {
@@ -258,7 +258,7 @@ export const pagesRoute = new Elysia({ prefix: "/pages" })
category: { category: {
include: { translations: true }, include: { translations: true },
}, },
scent: true, brand: true,
translations: true, translations: true,
variants: { variants: {
include: { include: {
@@ -277,9 +277,9 @@ export const pagesRoute = new Elysia({ prefix: "/pages" })
include: productInclude, include: productInclude,
take: limit take: limit
}); });
} else if (payload.type === 'scent' && payload.scentId) { } else if ((payload.type === 'scent' || payload.type === 'brand') && (payload.scentId || payload.brandId)) {
products = await prisma.product.findMany({ products = await prisma.product.findMany({
where: { scentId: Number(payload.scentId) }, where: { brandId: Number(payload.brandId || payload.scentId) },
include: productInclude, include: productInclude,
take: limit take: limit
}); });
@@ -310,7 +310,7 @@ export const pagesRoute = new Elysia({ prefix: "/pages" })
return { ...p, name: nameObj, description: descObj, details: detailsObj }; return { ...p, name: nameObj, description: descObj, details: detailsObj };
} }
const trans = p.translations?.find((t: any) => t.langCode === lang) || p.translations?.find((t: any) => t.langCode === 'th') || p.translations?.[0]; const trans = p.translations?.find((t: any) => t.langCode === lang) || p.translations?.find((t: any) => t.langCode === 'th') || p.translations?.[0];
return { ...p, name: trans?.name || p.scent?.name || '', description: trans?.description, details: trans?.details }; return { ...p, name: trans?.name || p.brand?.name || '', description: trans?.description, details: trans?.details };
}); });
} else if (section.type === 'CATEGORIES') { } else if (section.type === 'CATEGORIES') {
let categories: any[] = []; let categories: any[] = [];