summary refs log tree commit diff
path: root/util/src/entities/Invite.ts
blob: afad9c029d62ced42c090af316e164b53364f0bc (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
55
56
57
58
59
60
61
62
63
64
65
66
import { Column, Entity, JoinColumn, ManyToOne, PrimaryColumn, RelationId } from "typeorm";
import { BaseClass } from "./BaseClass";
import { Channel } from "./Channel";
import { Guild } from "./Guild";
import { User } from "./User";

export const PublicInviteRelation = ["inviter", "guild", "channel"];

@Entity("invites")
export class Invite extends BaseClass {
	@PrimaryColumn()
	code: string;

	@Column()
	temporary: boolean;

	@Column()
	uses: number;

	@Column()
	max_uses: number;

	@Column()
	max_age: number;

	@Column()
	created_at: Date;

	@Column()
	expires_at: Date;

	@Column({ nullable: true })
	@RelationId((invite: Invite) => invite.guild)
	guild_id: string;

	@JoinColumn({ name: "guild_id" })
	@ManyToOne(() => Guild)
	guild: Guild;

	@Column({ nullable: true })
	@RelationId((invite: Invite) => invite.channel)
	channel_id: string;

	@JoinColumn({ name: "channel_id" })
	@ManyToOne(() => Channel)
	channel: Channel;

	@Column({ nullable: true })
	@RelationId((invite: Invite) => invite.inviter)
	inviter_id: string;

	@JoinColumn({ name: "inviter_id" })
	@ManyToOne(() => User)
	inviter: User;

	@Column({ nullable: true })
	@RelationId((invite: Invite) => invite.target_user)
	target_user_id: string;

	@JoinColumn({ name: "target_user_id" })
	@ManyToOne(() => User)
	target_user?: string; // could be used for "User specific invites" https://github.com/fosscord/fosscord/issues/62

	@Column({ nullable: true })
	target_user_type?: number;
}