x
This commit is contained in:
1 parent
4536db6741
commit
c23a4723ed
2 files changed
+20
-8
No files matched your search
@@ -117,6 +117,10 @@ export const categoriesRoute = new Elysia({ prefix: "/categories" })
|
||||
const id = parseInt(params.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 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({
|
||||
where: { id },
|
||||
include: { translations: true, _count: { select: { products: true } } },
|
||||
});
|
||||
|
||||
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 }) => {
|
||||
try {
|
||||
|
||||
@@ -200,7 +200,7 @@ export const pagesRoute = new Elysia({ prefix: "/pages" })
|
||||
category: {
|
||||
include: { translations: true },
|
||||
},
|
||||
scent: true,
|
||||
brand: true,
|
||||
translations: true,
|
||||
variants: {
|
||||
include: {
|
||||
@@ -219,9 +219,9 @@ export const pagesRoute = new Elysia({ prefix: "/pages" })
|
||||
include: productInclude,
|
||||
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({
|
||||
where: { scentId: Number(payload.scentId) },
|
||||
where: { brandId: Number(payload.brandId || payload.scentId) },
|
||||
include: productInclude,
|
||||
take: limit
|
||||
});
|
||||
@@ -247,7 +247,7 @@ export const pagesRoute = new Elysia({ prefix: "/pages" })
|
||||
return { ...p, name: nameObj, description: descObj, details: detailsObj };
|
||||
} else {
|
||||
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)) {
|
||||
@@ -258,7 +258,7 @@ export const pagesRoute = new Elysia({ prefix: "/pages" })
|
||||
category: {
|
||||
include: { translations: true },
|
||||
},
|
||||
scent: true,
|
||||
brand: true,
|
||||
translations: true,
|
||||
variants: {
|
||||
include: {
|
||||
@@ -277,9 +277,9 @@ export const pagesRoute = new Elysia({ prefix: "/pages" })
|
||||
include: productInclude,
|
||||
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({
|
||||
where: { scentId: Number(payload.scentId) },
|
||||
where: { brandId: Number(payload.brandId || payload.scentId) },
|
||||
include: productInclude,
|
||||
take: limit
|
||||
});
|
||||
@@ -310,7 +310,7 @@ export const pagesRoute = new Elysia({ prefix: "/pages" })
|
||||
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];
|
||||
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') {
|
||||
let categories: any[] = [];
|
||||
|
||||
Reference in new issue
Block a user