You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.0 KiB
TypeScript

//
// Common
//
export type MetadataProps = 'id' | 'createdAt'
type Opaque<T, K, L extends string = 'opaque'> = T & { _: K; __: L }
type Id<T> = Opaque<string, T, 'id'>
//
// Users
//
export type AdministratorRole = 'admin' | 'moderator'
export type StudentRole = 'student'
export type UserRole = AdministratorRole | StudentRole
export type UserId = Id<User>
export type User = {
id: UserId
role: UserRole
}
export function isAdministrator(role: UserRole): role is AdministratorRole {
return role !== 'student'
}
export function isStudent(role: UserRole): role is StudentRole {
return role === 'student'
}
//
// Problems
//
export type ProblemId = Id<Problem>
export type Problem = {
id: ProblemId
content: string
createdBy: UserId
createdAt: string
}
//
// Solutions
//
export type SolutionStatus = 'pending' | 'correct' | 'wrong'
export type SolutionId = string
export type Solution = {
id: SolutionId
sentBy: UserId
forProblem: ProblemId
content: string
status: SolutionStatus
}