x
This commit is contained in:
1 parent
138078a398
commit
3e742ac468
5 files changed
+871
-417
No files matched your search
@@ -34,6 +34,28 @@ export const categoriesRoute = new Elysia({ prefix: "/categories" })
|
||||
name: resolveCatName(cat, lang),
|
||||
}));
|
||||
})
|
||||
.get("/:id", async ({ params, query, status }) => {
|
||||
const id = parseInt(params.id);
|
||||
const lang = (query as any).lang || 'all';
|
||||
if (isNaN(id)) return status(400, { message: "Invalid category ID" });
|
||||
|
||||
const category = await prisma.category.findUnique({
|
||||
where: { id, deletedAt: null },
|
||||
include: {
|
||||
translations: true,
|
||||
_count: {
|
||||
select: { products: { where: { isDeleted: false } } },
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
if (!category) return status(404, { message: "Category not found" });
|
||||
|
||||
return {
|
||||
...category,
|
||||
name: resolveCatName(category, lang),
|
||||
};
|
||||
})
|
||||
.get("/:id/products", async ({ params, query, status }) => {
|
||||
const id = parseInt(params.id);
|
||||
const lang = (query as any).lang || 'th';
|
||||
@@ -157,7 +179,7 @@ export const categoriesRoute = new Elysia({ prefix: "/categories" })
|
||||
|
||||
const updated = await prisma.category.findUnique({
|
||||
where: { id },
|
||||
include: { translations: true, _count: { select: { products: true } } },
|
||||
include: { translations: true, _count: { select: { products: { where: { isDeleted: false } } } } },
|
||||
});
|
||||
|
||||
return { success: true, translations: results, category: updated };
|
||||
@@ -249,7 +271,7 @@ export const categoriesRoute = new Elysia({ prefix: "/categories" })
|
||||
try {
|
||||
const category = await prisma.category.findUnique({
|
||||
where: { id, deletedAt: null },
|
||||
include: { _count: { select: { products: true } } }
|
||||
include: { _count: { select: { products: { where: { isDeleted: false } } } } }
|
||||
});
|
||||
|
||||
if (!category) return status(404, { message: "Category not found" });
|
||||
|
||||
@@ -1319,7 +1319,7 @@ export async function hydrateSectionPayload(section: any, lang: string) {
|
||||
include: {
|
||||
translations: true,
|
||||
_count: {
|
||||
select: { products: true },
|
||||
select: { products: { where: { isDeleted: false } } },
|
||||
},
|
||||
},
|
||||
});
|
||||
@@ -1330,7 +1330,7 @@ export async function hydrateSectionPayload(section: any, lang: string) {
|
||||
include: {
|
||||
translations: true,
|
||||
_count: {
|
||||
select: { products: true },
|
||||
select: { products: { where: { isDeleted: false } } },
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user