aboutsummaryrefslogtreecommitdiff
path: root/src/db/model/UserGroup.ts
blob: 46945de6775339a89cc3f5c0a4b2fb6d6b862462 (plain) (blame)
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
import { AllowNull, BelongsToMany, Column, DataType, Model, Table,
	Unique } from 'sequelize-typescript';
import { default as User } from './User';
import { default as UserHasPrivilege } from './UserHasPrivilege';

export interface UserPrivilege {
	privilege: string;
	description: string;
	internal: boolean;
}

@Table
export default class UserGroup extends Model<UserGroup> {
	@AllowNull
	@Unique
	@Column(DataType.TEXT)
	public name!: string | null;

	@BelongsToMany(() => User, () => UserHasPrivilege)
	public users?: User[];

	@Column
	public canCreateUsers!: boolean;

	@Column
	public canDeleteUsers!: boolean;

	@Column
	public canEditUsers!: boolean;

	@Column
	public canCreateProjects!: boolean;

	@Column
	public canDeleteProjects!: boolean;

	@Column
	public canEditProjects!: boolean;

	@Column
	public isInternal!: boolean;

	@AllowNull
	@Column(DataType.TEXT)
	public description!: string | null;

	public getPrivilege(): UserPrivilege {
		return {
			privilege : `${this.name}`,
			description : `${this.description}`,
			internal : this.isInternal
		};
	}
}