-
-
Notifications
You must be signed in to change notification settings - Fork 768
/
Copy pathgroup.ts
105 lines (84 loc) · 2.02 KB
/
group.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
import Joi, { ValidationError } from 'joi';
import type { IUser } from './user';
import { SYSTEM_USER_AUDIT } from './core';
export interface IGroup {
id: number;
name: string;
description?: string;
mappingsSSO?: string[];
rootRole?: number;
createdAt?: Date;
userCount?: number;
createdBy?: string;
scimId?: string;
}
export interface IGroupUser {
groupId: number;
userId: number;
joinedAt: Date;
rootRoleId?: number;
seenAt?: Date;
createdBy?: string;
}
export interface IGroupRole {
name: string;
groupId: number;
roleId: number;
createdAt: Date;
}
export interface IGroupModel extends IGroup {
users: IGroupUserModel[];
projects?: string[];
}
export interface ICreateGroupModel extends Omit<IGroup, 'id'> {
users?: ICreateGroupUserModel[];
}
export interface IGroupProject {
groupId: number;
project: string;
}
export interface IGroupUserModel {
user: IUser;
joinedAt?: Date;
createdBy?: string;
}
export interface ICreateGroupUserModel {
user: Pick<IUser, 'id'>;
}
export interface IGroupModelWithAddedAt extends IGroupModel {
addedAt: Date;
}
export default class Group implements IGroup {
type: string;
createdAt?: Date;
createdBy: string;
id: number;
name: string;
rootRole?: number;
description: string;
mappingsSSO: string[];
scimId?: string;
constructor({
id,
name,
description,
mappingsSSO,
rootRole,
createdBy,
createdAt,
scimId,
}: IGroup) {
if (!id) {
throw new ValidationError('Id is required', [], undefined);
}
Joi.assert(name, Joi.string(), 'Name');
this.id = id;
this.name = name;
this.rootRole = rootRole;
this.description = description || '';
this.mappingsSSO = mappingsSSO || [];
this.createdBy = createdBy || SYSTEM_USER_AUDIT.username;
this.createdAt = createdAt;
this.scimId = scimId;
}
}