Almost MVP
This commit is contained in:
+13
-4
@@ -4,8 +4,8 @@
|
||||
|
||||
export type MetadataProps = 'id' | 'createdAt'
|
||||
|
||||
type Opaque<T, K, L extends string = 'opaque'> = T & { _: K; __: L }
|
||||
type Id<T> = Opaque<string, T, 'id'>
|
||||
export type Opaque<T, K, L extends string = 'opaque'> = T & { _: K; __: L }
|
||||
export type Id<T> = Opaque<string, T, 'id'>
|
||||
|
||||
//
|
||||
// Users
|
||||
@@ -20,6 +20,7 @@ export type UserId = Id<User>
|
||||
|
||||
export type User = {
|
||||
id: UserId
|
||||
|
||||
role: UserRole
|
||||
}
|
||||
|
||||
@@ -39,9 +40,10 @@ export type ProblemId = Id<Problem>
|
||||
|
||||
export type Problem = {
|
||||
id: ProblemId
|
||||
createdAt: string
|
||||
|
||||
content: string
|
||||
createdBy: UserId
|
||||
createdAt: string
|
||||
}
|
||||
|
||||
//
|
||||
@@ -50,12 +52,19 @@ export type Problem = {
|
||||
|
||||
export type SolutionStatus = 'pending' | 'correct' | 'wrong'
|
||||
|
||||
export type SolutionId = string
|
||||
export type SolutionId = Id<Solution>
|
||||
|
||||
export type Solution = {
|
||||
id: SolutionId
|
||||
createdAt: string
|
||||
|
||||
sentBy: UserId
|
||||
forProblem: ProblemId
|
||||
content: string
|
||||
status: SolutionStatus
|
||||
|
||||
/**
|
||||
* The _visibility status_ only applies when `status` is not "pending"
|
||||
*/
|
||||
visible: boolean
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
export function validateObjectKeys<K extends string>(obj: any, keys: K[]): boolean {
|
||||
const keySet = new Set(keys)
|
||||
|
||||
// @ts-ignore
|
||||
return Object.keys(obj).every(key => keySet.has(key))
|
||||
}
|
||||
Reference in New Issue
Block a user