mirror of
https://github.com/massbug/judge4c.git
synced 2026-05-20 13:18:52 +00:00
chore(seed): update local seed users and language server config
This commit is contained in:
parent
3d7fc0161d
commit
662e223042
@ -1,4 +1,5 @@
|
|||||||
import { PrismaClient, Prisma } from "@/generated/client";
|
import { PrismaClient, Prisma } from "@/generated/client";
|
||||||
|
import bcrypt from "bcryptjs";
|
||||||
|
|
||||||
const prisma = new PrismaClient();
|
const prisma = new PrismaClient();
|
||||||
|
|
||||||
@ -24,14 +25,16 @@ const dockerConfigData: Prisma.DockerConfigCreateInput[] = [
|
|||||||
const languageServerConfigData: Prisma.LanguageServerConfigCreateInput[] = [
|
const languageServerConfigData: Prisma.LanguageServerConfigCreateInput[] = [
|
||||||
{
|
{
|
||||||
language: "c",
|
language: "c",
|
||||||
protocol: "wss",
|
protocol: "ws",
|
||||||
hostname: "lsp-c.litchi.icu",
|
hostname: "localhost",
|
||||||
|
port: 4594,
|
||||||
path: "/clangd",
|
path: "/clangd",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
language: "cpp",
|
language: "cpp",
|
||||||
protocol: "wss",
|
protocol: "ws",
|
||||||
hostname: "lsp-cpp.litchi.icu",
|
hostname: "localhost",
|
||||||
|
port: 4595,
|
||||||
path: "/clangd",
|
path: "/clangd",
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
@ -2980,36 +2983,70 @@ export async function main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Seed demo users for course/assignment MVP
|
// Seed demo users for course/assignment MVP
|
||||||
const teacher = await prisma.user.upsert({
|
const teacherPasswordHash = await bcrypt.hash("teacher123456#", 10);
|
||||||
where: { email: "teacher@judge4c.local" },
|
const studentPasswordHash = await bcrypt.hash("student123456#", 10);
|
||||||
|
const adminPasswordHash = await bcrypt.hash("admin123456#", 10);
|
||||||
|
|
||||||
|
const teachers = await Promise.all(
|
||||||
|
[
|
||||||
|
"teacher1@example.com",
|
||||||
|
"teacher2@example.com",
|
||||||
|
"teacher3@example.com",
|
||||||
|
].map((email, index) =>
|
||||||
|
prisma.user.upsert({
|
||||||
|
where: { email },
|
||||||
update: {
|
update: {
|
||||||
name: "课程教师",
|
name: `课程教师${index + 1}`,
|
||||||
role: "TEACHER",
|
role: "TEACHER",
|
||||||
|
password: teacherPasswordHash,
|
||||||
},
|
},
|
||||||
create: {
|
create: {
|
||||||
name: "课程教师",
|
name: `课程教师${index + 1}`,
|
||||||
email: "teacher@judge4c.local",
|
email,
|
||||||
role: "TEACHER",
|
role: "TEACHER",
|
||||||
|
password: teacherPasswordHash,
|
||||||
},
|
},
|
||||||
});
|
})
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
const students = await Promise.all(
|
const students = await Promise.all(
|
||||||
["student1@judge4c.local", "student2@judge4c.local"].map((email, index) =>
|
Array.from({ length: 9 }, (_, index) => `student${index + 1}@example.com`).map(
|
||||||
|
(email, index) =>
|
||||||
prisma.user.upsert({
|
prisma.user.upsert({
|
||||||
where: { email },
|
where: { email },
|
||||||
update: {
|
update: {
|
||||||
name: `学生${index + 1}`,
|
name: `学生${index + 1}`,
|
||||||
role: "STUDENT",
|
role: "STUDENT",
|
||||||
|
password: studentPasswordHash,
|
||||||
},
|
},
|
||||||
create: {
|
create: {
|
||||||
name: `学生${index + 1}`,
|
name: `学生${index + 1}`,
|
||||||
email,
|
email,
|
||||||
role: "STUDENT",
|
role: "STUDENT",
|
||||||
|
password: studentPasswordHash,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
await prisma.user.upsert({
|
||||||
|
where: { email: "admin@example.com" },
|
||||||
|
update: {
|
||||||
|
name: "系统管理员",
|
||||||
|
role: "ADMIN",
|
||||||
|
password: adminPasswordHash,
|
||||||
|
},
|
||||||
|
create: {
|
||||||
|
name: "系统管理员",
|
||||||
|
email: "admin@example.com",
|
||||||
|
role: "ADMIN",
|
||||||
|
password: adminPasswordHash,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const teacher = teachers[0];
|
||||||
|
|
||||||
const selectedProblems = await prisma.problem.findMany({
|
const selectedProblems = await prisma.problem.findMany({
|
||||||
orderBy: { displayId: "asc" },
|
orderBy: { displayId: "asc" },
|
||||||
take: 2,
|
take: 2,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user