feat: exam actions and data safety fixes
This commit is contained in:
@@ -16,8 +16,18 @@ async function reset() {
|
||||
`)
|
||||
|
||||
// Drop each table
|
||||
for (const row of (tables[0] as unknown as any[])) {
|
||||
const tableName = row.TABLE_NAME || row.table_name
|
||||
const rows = (tables as unknown as [unknown])[0]
|
||||
if (!Array.isArray(rows)) return
|
||||
|
||||
for (const row of rows) {
|
||||
const record = row as Record<string, unknown>
|
||||
const tableName =
|
||||
typeof record.TABLE_NAME === "string"
|
||||
? record.TABLE_NAME
|
||||
: typeof record.table_name === "string"
|
||||
? record.table_name
|
||||
: null
|
||||
if (!tableName) continue
|
||||
console.log(`Dropping table: ${tableName}`)
|
||||
await db.execute(sql.raw(`DROP TABLE IF EXISTS \`${tableName}\`;`))
|
||||
}
|
||||
|
||||
@@ -80,7 +80,12 @@ async function seed() {
|
||||
const qId = createId()
|
||||
questionIds.push(qId)
|
||||
|
||||
const type = faker.helpers.arrayElement(["single_choice", "multiple_choice", "text", "judgment"])
|
||||
const type = faker.helpers.arrayElement([
|
||||
"single_choice",
|
||||
"multiple_choice",
|
||||
"text",
|
||||
"judgment",
|
||||
] as const)
|
||||
|
||||
await db.insert(questions).values({
|
||||
id: qId,
|
||||
@@ -93,7 +98,7 @@ async function seed() {
|
||||
{ id: "D", text: faker.lorem.sentence(), isCorrect: false },
|
||||
] : undefined
|
||||
},
|
||||
type: type as any,
|
||||
type,
|
||||
difficulty: faker.helpers.arrayElement(DIFFICULTY),
|
||||
authorId: teacherId,
|
||||
})
|
||||
@@ -105,7 +110,7 @@ async function seed() {
|
||||
const examId = createId()
|
||||
const subject = faker.helpers.arrayElement(SUBJECTS)
|
||||
const grade = faker.helpers.arrayElement(GRADES)
|
||||
const status = faker.helpers.arrayElement(["draft", "published", "archived"])
|
||||
const status = faker.helpers.arrayElement(["draft", "published", "archived"] as const)
|
||||
|
||||
const scheduledAt = faker.date.soon({ days: 30 })
|
||||
|
||||
@@ -126,7 +131,7 @@ async function seed() {
|
||||
description: JSON.stringify(meta),
|
||||
creatorId: teacherId,
|
||||
startTime: scheduledAt,
|
||||
status: status as any,
|
||||
status,
|
||||
})
|
||||
|
||||
// Link some questions to this exam (random 5 questions)
|
||||
|
||||
Reference in New Issue
Block a user