36
loading...
This website collects cookies to deliver better user experience
model Teacher {
id String @id @default(dbgenerated("uuid_generate_v4()")) @db.Uuid
idNumber String @unique
name String
gender String
phoneNumber String @unique
email String @unique
passwordHash String
age Int
jobTitle String
departmentId String @db.Uuid
department Department @relation(fields: [departmentId], references: [id])
courses Course[]
enrolledAt DateTime
createdAt DateTime @default(dbgenerated("now()"))
updatedAt DateTime @default(dbgenerated("now()")) @updatedAt
deletedAt DateTime?
courseClass CourseClass[]
@@index([idNumber])
@@index([name])
@@index([email])
@@index([phoneNumber])
}
model Student {
id String @id @default(dbgenerated("uuid_generate_v4()")) @db.Uuid
idNumber String @unique
name String
gender String
phoneNumber String @unique
email String @unique
passwordHash String
age Int
departmentId String @db.Uuid
department Department @relation(fields: [departmentId], references: [id])
courseClasses StudentCourseClass[]
subjects StudentSubject[]
enrolledAt DateTime
createdAt DateTime @default(dbgenerated("now()"))
updatedAt DateTime @default(dbgenerated("now()")) @updatedAt
deletedAt DateTime?
@@index([idNumber])
@@index([name])
@@index([email])
@@index([phoneNumber])
}
model Department {
id String @id @default(dbgenerated("uuid_generate_v4()")) @db.Uuid
name String @unique
students Student[]
teachers Teacher[]
createdAt DateTime @default(dbgenerated("now()"))
updatedAt DateTime @default(dbgenerated("now()")) @updatedAt
deletedAt DateTime?
}
model Course {
id String @id @default(dbgenerated("uuid_generate_v4()")) @db.Uuid
name String
credit Int
courseClasses CourseClass[]
courseCategories CourseCategory[]
type CourseType @default(PUBLIC)
selectableSubjects Subject[]
createdAt DateTime @default(dbgenerated("now()"))
updatedAt DateTime @default(dbgenerated("now()")) @updatedAt
deletedAt DateTime?
@@index([name])
}
enum CourseType {
PUBLIC
MAJOR_LIMITED
}
model CourseCategory {
id String @id @default(dbgenerated("uuid_generate_v4()")) @db.Uuid
name String
courses Course[]
createdAt DateTime @default(dbgenerated("now()"))
updatedAt DateTime @default(dbgenerated("now()")) @updatedAt
deletedAt DateTime?
@@index([name])
}
model Subject {
id String @id @default(dbgenerated("uuid_generate_v4()")) @db.Uuid
name String @unique
courses Course[]
students StudentSubject[]
departments Department[]
teachers Teacher[]
createdAt DateTime @default(dbgenerated("now()"))
updatedAt DateTime @default(dbgenerated("now()")) @updatedAt
deletedAt DateTime?
}
model StudentSubject {
studentId String @db.Uuid
subjectId String @db.Uuid
student Student @relation(fields: [studentId], references: [id])
subject Subject @relation(fields: [subjectId], references: [id])
isMajor Boolean @default(true)
@@id([studentId, subjectId])
}
isMajor
column in relation table StudentSubject
.model CourseClass {
id String @id @default(dbgenerated("uuid_generate_v4()")) @db.Uuid
name String
course Course @relation(fields: [courseId], references: [id])
courseId String @db.Uuid
capacity Int
time String
location String
status CourseClassStatus @default(NEW)
teacher Teacher @relation(fields: [teacherId], references: [id])
teacherId String @db.Uuid
students StudentCourseClass[]
createdAt DateTime @default(dbgenerated("now()"))
updatedAt DateTime @default(dbgenerated("now()")) @updatedAt
deletedAt DateTime?
@@index([name])
}
enum CourseClassStatus {
NEW
OPEN
CONFIRMED
CANCELED
}
capacity
and it should have four statuses:model StudentCourseClass {
student Student @relation(fields: [studentId], references: [id])
studentId String @db.Uuid
courseClass CourseClass @relation(fields: [courseClassId], references: [id])
courseClassId String @db.Uuid
status SelectionStatus @default(SELECTED)
selectedAt DateTime @default(dbgenerated("now()"))
@@id([studentId, courseClassId])
}
enum SelectionStatus {
SELECTED
CANCELED
}
SELECTED
and CANCELED
, if student have more than 3 classes canceled at the same day, we might pose some punishment for this particular student.name
, location
, time
, capacities
of the class, also assign the teacher of this class.SELECTED
, and capacity would go up by 1.CANCEL
button.bull
for timed background jobs.studentCouseClassBegin
and studentCouseClassEnd
keys with value of start end time into Redis. We then use bull
to create a new queue named CoureSelectionQueue
, add a task to remove the key from Redis at end time.studentCouseClassBegin
and studentCouseClassEnd
, depending on the result, we can have 4 type of response.Course selection not available
.studentCouseClassBegin
, return xxx mintues before course selection begins
, admin can call cancel option, which would remove both keys from Redis and remove the task from bull
queue.studentCouseClassBegin
< Current time < studentCouseClassEnd
, we return xxx minutes before course selection ends
.studentCouseClassEnd
, we return Couse selection have ended
.redis-semaphore
to generate a distributed semaphore, the key of semaphore is generated token and value is the capacity for a certain course class.StudentCourseClass
information, with key of couseClass Id
+ studentId
value is the selection status.redis-semaphore
.acquire()
function to try to reduce the capacity of this course class.36