sync-docs-and-fixes
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
"use server";
|
||||
|
||||
import { revalidatePath } from "next/cache"
|
||||
import { and, eq, sql, or, inArray } from "drizzle-orm"
|
||||
import { and, eq, sql, or } from "drizzle-orm"
|
||||
import { auth } from "@/auth"
|
||||
|
||||
import { db } from "@/shared/db"
|
||||
@@ -16,6 +16,7 @@ import {
|
||||
deleteTeacherClass,
|
||||
enrollStudentByEmail,
|
||||
enrollStudentByInvitationCode,
|
||||
enrollTeacherByInvitationCode,
|
||||
ensureClassInvitationCode,
|
||||
regenerateClassInvitationCode,
|
||||
setClassSubjectTeachers,
|
||||
@@ -371,8 +372,18 @@ export async function joinClassByInvitationCodeAction(
|
||||
return { success: false, message: "Unauthorized" }
|
||||
}
|
||||
|
||||
const subjectValue = formData.get("subject")
|
||||
const subject = role === "teacher" && typeof subjectValue === "string" ? subjectValue.trim() : null
|
||||
|
||||
if (role === "teacher" && (!subject || subject.length === 0)) {
|
||||
return { success: false, message: "Subject is required" }
|
||||
}
|
||||
|
||||
try {
|
||||
const classId = await enrollStudentByInvitationCode(session.user.id, code)
|
||||
const classId =
|
||||
role === "teacher"
|
||||
? await enrollTeacherByInvitationCode(session.user.id, code, subject)
|
||||
: await enrollStudentByInvitationCode(session.user.id, code)
|
||||
if (role === "student") {
|
||||
revalidatePath("/student/learning/courses")
|
||||
revalidatePath("/student/schedule")
|
||||
|
||||
Reference in New Issue
Block a user