x
This commit is contained in:
1 parent
70877882b0
commit
ce2f4cf0c8
93 files changed
+4200
-67
No files matched your search
@@ -1,6 +1,6 @@
|
||||
import { Elysia, t } from "elysia";
|
||||
import prisma from "../lib/prisma";
|
||||
import { adminOnly } from "../middleware/auth";
|
||||
import prisma from "../lib/prisma.js";
|
||||
import { adminOnly } from "../middleware/auth.js";
|
||||
|
||||
export const menusRoute = new Elysia({ prefix: "/menus" })
|
||||
.get("/", async () => {
|
||||
@@ -29,27 +29,30 @@ export const menusRoute = new Elysia({ prefix: "/menus" })
|
||||
return menu;
|
||||
})
|
||||
.use(adminOnly)
|
||||
.post("/", async ({ body, set }) => {
|
||||
.post("/", async ({ body, set }: { body: any; set: any }) => {
|
||||
try {
|
||||
const { name, rootImage, items } = body as {
|
||||
name: string;
|
||||
rootImage?: string | null;
|
||||
items?: { label: string; url: string; order: number; columnImage?: string | null; hoverImage?: string | null }[]
|
||||
};
|
||||
const data: any = {
|
||||
name,
|
||||
rootImage,
|
||||
};
|
||||
if (items) {
|
||||
data.items = {
|
||||
create: items.map(item => ({
|
||||
label: item.label,
|
||||
url: item.url,
|
||||
order: item.order,
|
||||
columnImage: item.columnImage,
|
||||
hoverImage: item.hoverImage
|
||||
}))
|
||||
};
|
||||
}
|
||||
const menu = await prisma.menu.create({
|
||||
data: {
|
||||
name,
|
||||
rootImage,
|
||||
items: items ? {
|
||||
create: items.map(item => ({
|
||||
label: item.label,
|
||||
url: item.url,
|
||||
order: item.order,
|
||||
columnImage: item.columnImage,
|
||||
hoverImage: item.hoverImage
|
||||
}))
|
||||
} : undefined
|
||||
},
|
||||
data,
|
||||
include: { items: true }
|
||||
});
|
||||
return menu;
|
||||
@@ -71,7 +74,7 @@ export const menusRoute = new Elysia({ prefix: "/menus" })
|
||||
})))
|
||||
})
|
||||
})
|
||||
.put("/:name", async ({ params: { name }, body, set }) => {
|
||||
.put("/:name", async ({ params: { name }, body, set }: { params: { name: string }; body: any; set: any }) => {
|
||||
try {
|
||||
const { items, payload, isActive, rootImage } = body as {
|
||||
payload?: any;
|
||||
|
||||
Reference in new issue
Block a user