-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathuser.ts
157 lines (136 loc) · 3.79 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/**
* SudoSOS back-end API service.
* Copyright (C) 2024 Study association GEWIS
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {
Column, Entity, JoinColumn, OneToMany, OneToOne,
} from 'typeorm';
import BaseEntity from '../base-entity';
import UserFineGroup from '../fine/userFineGroup';
import AssignedRole from '../roles/assigned-role';
export enum TermsOfServiceStatus {
ACCEPTED = 'ACCEPTED',
NOT_ACCEPTED = 'NOT_ACCEPTED',
NOT_REQUIRED = 'NOT_REQUIRED',
}
export enum UserType {
MEMBER = 1,
ORGAN = 2,
VOUCHER = 3,
LOCAL_USER = 4,
LOCAL_ADMIN = 5,
INVOICE = 6,
}
/**
* All user types that should be allowed to have a local password.
*/
export const LocalUserTypes = [
UserType.LOCAL_USER, UserType.LOCAL_ADMIN, UserType.INVOICE,
];
/**
* All users that have required TOS restrictions.
*/
export const TOSRequired = [
UserType.MEMBER, UserType.LOCAL_USER, UserType.LOCAL_ADMIN,
];
/**
* All users that should be notified when in debt.
*/
export const NotifyDebtUserTypes: UserType[] = [
UserType.LOCAL_ADMIN, UserType.LOCAL_USER, UserType.MEMBER,
];
/**
* @typedef {BaseEntity} User
* @property {string} firstName.required - First name of the user.
* @property {string} lastName - Last name of the user.
* @property {string} nickname - Nickname of the user.
* @property {boolean} active - Whether the user has accepted the TOS. Defaults to false.
* @property {boolean} canGoIntoDebt - Whether the user can have a negative balance. Defaults to false
* @property {boolean} ofAge - Whether the user is 18+ or not.
* @property {string} email - The email of the user.
* @property {boolean} deleted - Whether the user was deleted. Defaults to false.
* @property {string} type.required - The type of user.
*/
@Entity()
export default class User extends BaseEntity {
@Column({
length: 64,
})
public firstName: string;
@Column({
length: 64,
default: '',
})
public lastName: string;
@Column({
length: 64,
nullable: true,
})
public nickname: string;
@Column({
default: false,
})
public active: boolean;
/**
* Whether this user can have a negative balance
*/
@Column({
default: false,
})
public canGoIntoDebt: boolean;
@Column({
default: false,
})
public ofAge: boolean;
@Column({
length: 64,
default: '',
})
public email: string;
@Column({
default: false,
})
public deleted: boolean;
@Column({
nullable: false,
})
public type: UserType;
@Column({
nullable: false, default: TermsOfServiceStatus.NOT_ACCEPTED,
})
public acceptedToS: TermsOfServiceStatus;
@Column({
default: false,
})
public extensiveDataProcessing: boolean;
@OneToOne(() => UserFineGroup, {
nullable: true,
onDelete: 'SET NULL',
})
@JoinColumn()
public currentFines?: UserFineGroup | null;
@OneToMany(() => AssignedRole, (role) => role.user)
public roles: AssignedRole[];
public fullName(): string {
let name = this.firstName;
if (this.nickname) name += ` "${this.nickname}"`;
if (this.lastName) name += ` ${this.lastName}`;
return name;
}
public toString(): string {
return `${this.fullName()} (SudoSOS ID: ${this.id})`;
}
}