增加系统设置表

This commit is contained in:
sijinhui
2024-04-25 00:51:05 +08:00
parent 8c5bbf1cf0
commit a9bab9f93a
3 changed files with 176 additions and 8 deletions

View File

@@ -12,9 +12,45 @@ async function handle(
// console.log('----', pathname, searchParams, params.path)
if (method === "GET" && !params.path) {
const all_setting = await prisma.setting.findMany();
console.log("all_setting,", all_setting);
// console.log("all_setting,", all_setting);
return NextResponse.json({ result: all_setting });
}
if (method === "POST" && !params.path) {
try {
const setting_instance = await prisma.setting.create({
data: await req.json(),
});
// console.log('-------', setting_instance)
return NextResponse.json({ result: setting_instance });
} catch (e) {
console.log("[insert setting] error,", e);
}
}
if (method === "PUT" && params.path) {
try {
const setting_key = params.path[0];
const setting_instance = await prisma.setting.update({
where: {
key: setting_key,
},
data: await req.json(),
});
return NextResponse.json({ result: setting_instance });
} catch {}
}
if (method === "DELETE" && params.path) {
try {
const setting_key = params.path[0];
const setting_instance = await prisma.setting.delete({
where: {
key: setting_key,
},
});
return NextResponse.json({ result: setting_instance });
} catch {}
}
return NextResponse.json({ error: "当前方法不支持" }, { status: 405 });
}