-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathteam.ts
More file actions
56 lines (51 loc) · 1.3 KB
/
team.ts
File metadata and controls
56 lines (51 loc) · 1.3 KB
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
import {
Column,
Entity,
PrimaryGeneratedColumn,
OneToMany,
OneToOne,
JoinColumn,
} from "typeorm";
import { Longtext } from "./longtext";
import { User } from "./user";
@Entity()
export class Team {
@PrimaryGeneratedColumn()
public readonly id!: number;
@Column({ length: 1024 })
public title!: string;
// TODO rename teamImg to image
@Column()
public teamImg!: string;
@Longtext()
public description!: string;
// The owner also has to have their user.team property set to this team.
// Beware that this is not eagerly loaded, because it will throw recursion depth
// errors due to user.team being eagerly loaded already. Add it to "relations"
// when doing database queries instead.
@OneToOne(() => User)
@JoinColumn()
public owner!: User;
@OneToMany(() => User, (user) => user.teamRequest)
public requests!: User[];
@OneToMany(() => User, (user) => user.team)
public users!: User[];
/**
* List of user ids that are part of the team.
*/
public userIds(): number[] {
if (!this.users) {
return [];
}
return this.users.map(({ id }) => id);
}
/**
* List of user ids that requested to join the team.
*/
public requestUserIds(): number[] {
if (!this.requests) {
return [];
}
return this.requests.map(({ id }) => id);
}
}