x
This commit is contained in:
1 parent
ac387185e0
commit
6a35dcf955
6 files changed
+437
-67
No files matched your search
@@ -160,13 +160,27 @@ function resolveCatName(cat, lang) {
|
||||
return trans?.name ?? cat.name;
|
||||
}
|
||||
export const pagesRoute = new Elysia({ prefix: "/pages" })
|
||||
.get("/", async () => {
|
||||
return await prisma.page.findMany({
|
||||
include: {
|
||||
sections: {
|
||||
orderBy: { order: "asc" }
|
||||
.get("/", async ({ query }) => {
|
||||
const view = String(query?.view || "summary").toLowerCase();
|
||||
if (view === "full") {
|
||||
return await prisma.page.findMany({
|
||||
include: {
|
||||
sections: {
|
||||
orderBy: { order: "asc" }
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
return await prisma.page.findMany({
|
||||
select: {
|
||||
id: true,
|
||||
slug: true,
|
||||
title: true,
|
||||
isPublished: true,
|
||||
createdAt: true,
|
||||
updatedAt: true
|
||||
},
|
||||
orderBy: { updatedAt: "desc" }
|
||||
});
|
||||
})
|
||||
.get("/:slug", async ({ params: { slug }, query, set }) => {
|
||||
@@ -407,12 +421,57 @@ export const pagesRoute = new Elysia({ prefix: "/pages" })
|
||||
diagnostic: "The requested slug is reserved and cannot be used for dynamic pages."
|
||||
};
|
||||
}
|
||||
let finalIsPublished = true;
|
||||
if (status !== undefined) {
|
||||
finalIsPublished = status === "published";
|
||||
if (metadata !== undefined) {
|
||||
set.status = 400;
|
||||
return {
|
||||
success: false,
|
||||
operation,
|
||||
pageId: id ? Number(id) : null,
|
||||
slug,
|
||||
title,
|
||||
error: "Unsupported field",
|
||||
diagnostic: "Page metadata is not supported by the current Page model. Remove 'metadata' from the request."
|
||||
};
|
||||
}
|
||||
else if (isPublished !== undefined) {
|
||||
finalIsPublished = isPublished;
|
||||
if (status !== undefined) {
|
||||
set.status = 400;
|
||||
return {
|
||||
success: false,
|
||||
operation,
|
||||
pageId: id ? Number(id) : null,
|
||||
slug,
|
||||
title,
|
||||
error: "Unsupported publish field",
|
||||
diagnostic: "Use 'isPublished' only. The legacy 'status' field is no longer accepted."
|
||||
};
|
||||
}
|
||||
let finalIsPublished = isPublished;
|
||||
let publishBehavior = "request";
|
||||
if (finalIsPublished === undefined) {
|
||||
if (id) {
|
||||
const existingPage = await prisma.page.findUnique({
|
||||
where: { id: Number(id) },
|
||||
select: { isPublished: true }
|
||||
});
|
||||
if (!existingPage) {
|
||||
set.status = 404;
|
||||
return {
|
||||
success: false,
|
||||
operation,
|
||||
pageId: Number(id),
|
||||
slug,
|
||||
title,
|
||||
error: "Page not found",
|
||||
diagnostic: "The requested page ID does not exist."
|
||||
};
|
||||
}
|
||||
finalIsPublished = existingPage.isPublished;
|
||||
publishBehavior = "preserve-existing";
|
||||
}
|
||||
else {
|
||||
finalIsPublished = false;
|
||||
publishBehavior = "default-create-false";
|
||||
}
|
||||
}
|
||||
const page = id
|
||||
? await prisma.page.update({
|
||||
@@ -429,10 +488,15 @@ export const pagesRoute = new Elysia({ prefix: "/pages" })
|
||||
slug: page.slug,
|
||||
title: page.title,
|
||||
isPublished: page.isPublished,
|
||||
publishBehavior,
|
||||
page,
|
||||
diagnostic: operation === "create"
|
||||
? "Page created successfully."
|
||||
: "Page updated successfully."
|
||||
? publishBehavior === "default-create-false"
|
||||
? "Page created successfully. Defaulted to isPublished=false because the field was omitted."
|
||||
: "Page created successfully."
|
||||
: publishBehavior === "preserve-existing"
|
||||
? "Page updated successfully. Existing publish state was preserved because isPublished was omitted."
|
||||
: "Page updated successfully."
|
||||
};
|
||||
}
|
||||
catch (err) {
|
||||
@@ -453,9 +517,7 @@ export const pagesRoute = new Elysia({ prefix: "/pages" })
|
||||
id: t.Optional(t.Number()),
|
||||
slug: t.String(),
|
||||
title: t.String(),
|
||||
isPublished: t.Optional(t.Boolean()),
|
||||
status: t.Optional(t.String()),
|
||||
metadata: t.Optional(t.Any())
|
||||
isPublished: t.Optional(t.Boolean())
|
||||
})
|
||||
})
|
||||
.delete("/:slug", async ({ params: { slug }, set }) => {
|
||||
@@ -736,4 +798,4 @@ function validateSectionPayload(type, payload) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
//# sourceMappingURL=pages.js.map
|
||||
//# sourceMappingURL=pages.js.map
|
||||
Reference in new issue
Block a user