-
-
Notifications
You must be signed in to change notification settings - Fork 768
/
Copy pathuser.ts
115 lines (92 loc) · 2.26 KB
/
user.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import { ValidationError } from 'joi';
import { generateImageUrl } from '../util/generateImageUrl';
export const AccountTypes = ['User', 'Service Account'] as const;
type AccountType = (typeof AccountTypes)[number];
export interface UserData {
id: number;
name?: string;
username?: string;
email?: string;
imageUrl?: string;
seenAt?: Date;
loginAttempts?: number;
createdAt?: Date;
isService?: boolean;
scimId?: string;
}
export interface IUser {
id: number;
name?: string;
username?: string;
email?: string;
inviteLink?: string;
seenAt?: Date;
createdAt?: Date;
permissions: string[];
loginAttempts?: number;
isAPI: boolean;
imageUrl?: string;
accountType?: AccountType;
scimId?: string;
deletedSessions?: number;
activeSessions?: number;
}
export type MinimalUser = Pick<
IUser,
'id' | 'name' | 'username' | 'email' | 'imageUrl'
>;
export interface IProjectUser extends IUser {
addedAt: Date;
}
export interface IAuditUser {
id: number;
username: string;
ip: string;
}
export default class User implements IUser {
isAPI: boolean = false;
id: number;
name: string;
username: string;
email: string;
permissions: string[];
imageUrl: string;
seenAt?: Date;
loginAttempts?: number;
createdAt?: Date;
accountType?: AccountType = 'User';
scimId?: string;
constructor({
id,
name,
email,
username,
imageUrl,
seenAt,
loginAttempts,
createdAt,
isService,
scimId,
}: UserData) {
if (!id) {
throw new ValidationError('Id is required', [], undefined);
}
this.id = id;
this.name = name!;
this.username = username!;
this.email = email!;
this.imageUrl = imageUrl || this.generateImageUrl();
this.seenAt = seenAt;
this.loginAttempts = loginAttempts;
this.createdAt = createdAt;
this.accountType = isService ? 'Service Account' : 'User';
this.scimId = scimId;
}
generateImageUrl(): string {
return generateImageUrl(this);
}
}
export interface IUserWithRootRole extends IUser {
rootRole: number;
}
module.exports = User;