x
This commit is contained in:
1 parent
e9f6e7201a
commit
7abbcfebd2
8 files changed
+405
-42
No files matched your search
@@ -0,0 +1,2 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "Category" ADD COLUMN IF NOT EXISTS "layoutType" TEXT NOT NULL DEFAULT 'split_showcase';
|
||||
@@ -34,6 +34,7 @@ model Category {
|
||||
id Int @id @default(autoincrement())
|
||||
name String @unique
|
||||
imageUrl String?
|
||||
layoutType String @default("split_showcase")
|
||||
products Product[]
|
||||
attributes AttributeDefinition[]
|
||||
translations CategoryTranslation[]
|
||||
|
||||
@@ -71,6 +71,7 @@ export const categoriesRoute = new Elysia({ prefix: "/categories" })
|
||||
const updateData: any = {};
|
||||
if (imageUrl !== undefined) updateData.imageUrl = imageUrl;
|
||||
if (item.name) updateData.name = item.name;
|
||||
if (item.layoutType) updateData.layoutType = item.layoutType;
|
||||
|
||||
if (Object.keys(updateData).length > 0) {
|
||||
category = await prisma.category.update({
|
||||
@@ -85,6 +86,7 @@ export const categoriesRoute = new Elysia({ prefix: "/categories" })
|
||||
data: {
|
||||
name: baseName,
|
||||
imageUrl,
|
||||
layoutType: item.layoutType || 'split_showcase',
|
||||
},
|
||||
});
|
||||
createdCount++;
|
||||
@@ -199,6 +201,7 @@ export const categoriesRoute = new Elysia({ prefix: "/categories" })
|
||||
id: category.id,
|
||||
name: resolveCatName(category, lang),
|
||||
imageUrl: category.imageUrl,
|
||||
layoutType: category.layoutType || 'split_showcase',
|
||||
_count: category._count,
|
||||
},
|
||||
data: category.products.map((p: any) => {
|
||||
@@ -318,6 +321,7 @@ export const categoriesRoute = new Elysia({ prefix: "/categories" })
|
||||
data: {
|
||||
name: body.name,
|
||||
imageUrl: body.imageUrl,
|
||||
layoutType: body.layoutType || 'split_showcase',
|
||||
// Auto-seed Thai translation
|
||||
translations: { create: { langCode: 'th', name: body.name } },
|
||||
},
|
||||
@@ -333,6 +337,7 @@ export const categoriesRoute = new Elysia({ prefix: "/categories" })
|
||||
body: t.Object({
|
||||
name: t.String(),
|
||||
imageUrl: t.Optional(t.Union([t.String(), t.Null()])),
|
||||
layoutType: t.Optional(t.String()),
|
||||
})
|
||||
})
|
||||
.put("/:id", async ({ params, body, status }) => {
|
||||
@@ -340,12 +345,14 @@ export const categoriesRoute = new Elysia({ prefix: "/categories" })
|
||||
if (isNaN(id)) return status(400, { message: "Invalid category ID" });
|
||||
|
||||
try {
|
||||
const updateData: any = {};
|
||||
if (body.name !== undefined) updateData.name = body.name;
|
||||
if (body.imageUrl !== undefined) updateData.imageUrl = body.imageUrl;
|
||||
if (body.layoutType !== undefined) updateData.layoutType = body.layoutType;
|
||||
|
||||
const category = await prisma.category.update({
|
||||
where: { id, deletedAt: null },
|
||||
data: {
|
||||
name: body.name,
|
||||
imageUrl: body.imageUrl,
|
||||
},
|
||||
data: updateData,
|
||||
});
|
||||
return category;
|
||||
} catch (err: any) {
|
||||
@@ -362,6 +369,7 @@ export const categoriesRoute = new Elysia({ prefix: "/categories" })
|
||||
body: t.Object({
|
||||
name: t.Optional(t.String()),
|
||||
imageUrl: t.Optional(t.Union([t.String(), t.Null()])),
|
||||
layoutType: t.Optional(t.String()),
|
||||
})
|
||||
})
|
||||
.delete("/:id", async ({ params, status }) => {
|
||||
|
||||
Reference in new issue
Block a user