-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuserTypes.ts
47 lines (35 loc) · 1.07 KB
/
userTypes.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
export type Role = "Administrator" | "Facilitator" | "Learner";
export function isRole(role: string): role is Role {
return (
role === "Administrator" || role === "Facilitator" || role === "Learner"
);
}
export type Status = "Invited" | "Active";
export type UserDTO = {
id: string;
firstName: string;
lastName: string;
email: string;
role: Role;
status: Status;
profilePicture?: string;
};
export type CreateUserDTO = Omit<UserDTO, "id"> & { password: string };
export type UpdateUserDTO = Omit<UserDTO, "id" | "email">;
export type SignupUserDTO = Omit<CreateUserDTO, "role">;
export type AdminDTO = UserDTO;
export function isAdministrator(user: UserDTO): user is AdminDTO {
return user.role === "Administrator";
}
export type FacilitatorDTO = UserDTO & {
learners: string[];
};
export function isFacilitator(user: UserDTO): user is FacilitatorDTO {
return user.role === "Facilitator";
}
export type LearnerDTO = UserDTO & {
facilitator: string;
};
export function isLearner(user: UserDTO): user is LearnerDTO {
return user.role === "Learner";
}