mirror of
https://github.com/ZeroCatDev/ClassworksKV.git
synced 2025-07-02 04:39:23 +00:00
1
This commit is contained in:
parent
24f64553fe
commit
2d055f6400
@ -5,7 +5,9 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node ./bin/www",
|
"start": "node ./bin/www",
|
||||||
"prisma": "prisma generate",
|
"prisma": "prisma generate",
|
||||||
"prisma:pull": "prisma db pull"
|
"prisma:pull": "prisma db pull",
|
||||||
|
"dev": "NODE_ENV=development nodemon node .bin/www"
|
||||||
|
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@prisma/client": "6.4.1",
|
"@prisma/client": "6.4.1",
|
||||||
|
@ -18,9 +18,6 @@ model homework {
|
|||||||
}
|
}
|
||||||
|
|
||||||
model config {
|
model config {
|
||||||
id Int @default(autoincrement())
|
class String @id @db.VarChar(45)
|
||||||
class String @db.VarChar(45)
|
value Json?
|
||||||
student String @db.MediumText
|
|
||||||
|
|
||||||
@@id([id, class])
|
|
||||||
}
|
}
|
||||||
|
@ -57,11 +57,7 @@ router.get("/:classId/homework", async (req, res) => {
|
|||||||
throw new Error("该日期未上传数据");
|
throw new Error("该日期未上传数据");
|
||||||
}
|
}
|
||||||
|
|
||||||
res.json({
|
res.json(homework.data);
|
||||||
status: true,
|
|
||||||
msg: "获取成功",
|
|
||||||
...homework.data,
|
|
||||||
});
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Download error:", error);
|
console.error("Download error:", error);
|
||||||
res.json({
|
res.json({
|
||||||
@ -71,31 +67,22 @@ router.get("/:classId/homework", async (req, res) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// 获取班级配置信息
|
// 获取班级配置
|
||||||
router.get("/:classId/config", async (req, res) => {
|
router.get("/:classId/config", async (req, res) => {
|
||||||
const className = req.params.classId;
|
|
||||||
var studentList = [];
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const config = await prisma.config.findFirst({
|
const className = req.params.classId;
|
||||||
|
|
||||||
|
const config = await prisma.config.findUnique({
|
||||||
where: {
|
where: {
|
||||||
id: 1,
|
|
||||||
class: className
|
class: className
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (config) {
|
if (!config) {
|
||||||
studentList = config.student.split(",");
|
throw new Error("未找到配置信息");
|
||||||
}
|
}
|
||||||
|
|
||||||
res.json({
|
res.json(config.value);
|
||||||
studentList: studentList,
|
|
||||||
homeworkArrange: [
|
|
||||||
["语文", "数学", "英语"],
|
|
||||||
["物理", "化学", "生物"],
|
|
||||||
["政治", "历史", "地理"],
|
|
||||||
],
|
|
||||||
});
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Config error:", error);
|
console.error("Config error:", error);
|
||||||
res.json({
|
res.json({
|
||||||
@ -105,27 +92,23 @@ router.get("/:classId/config", async (req, res) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// 更新班级学生列表
|
// 更新班级配置
|
||||||
router.put("/:classId/students", async (req, res) => {
|
router.put("/:classId/config", async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const className = req.params.classId;
|
const className = req.params.classId;
|
||||||
const studentList = req.body.studentList.join(",");
|
const configValue = req.body;
|
||||||
|
|
||||||
await prisma.config.upsert({
|
await prisma.config.upsert({
|
||||||
where: {
|
where: {
|
||||||
id_class: {
|
class: className
|
||||||
id: req.body.id,
|
|
||||||
class: className
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
update: {
|
update: {
|
||||||
student: studentList,
|
value: configValue
|
||||||
},
|
},
|
||||||
create: {
|
create: {
|
||||||
id: req.body.id,
|
|
||||||
class: className,
|
class: className,
|
||||||
student: studentList,
|
value: configValue
|
||||||
},
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
res.json({
|
res.json({
|
||||||
@ -133,7 +116,7 @@ router.put("/:classId/students", async (req, res) => {
|
|||||||
msg: "更新成功"
|
msg: "更新成功"
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("SetStudentList error:", error);
|
console.error("Config update error:", error);
|
||||||
res.json({
|
res.json({
|
||||||
status: false,
|
status: false,
|
||||||
msg: "更新失败:" + error.message,
|
msg: "更新失败:" + error.message,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user