summary refs log tree commit diff
path: root/src/models/Invite.ts
blob: 01f12003ddf9fe6ffddc09ec869c6272d19ee626 (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
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
import { Schema, Document, Types } from "mongoose";
import db from "../util/Database";
import { ChannelModel } from "./Channel";
import { PublicUserProjection, UserModel } from "./User";
import { GuildModel } from "./Guild";

export interface Invite {
	code: string;
	temporary: boolean;
	uses: number;
	max_uses: number;
	max_age: number;
	created_at: Date;
	expires_at: Date;
	guild_id: string;
	channel_id: string;
	inviter_id: string;

	// ? What is this?
	target_user_id?: string;
	target_user_type?: number;
}

export interface InviteDocument extends Invite, Document {}

export const InviteSchema = new Schema({
	code: String,
	temporary: Boolean,
	uses: Number,
	max_uses: Number,
	max_age: Number,
	created_at: Date,
	expires_at: Date,
	guild_id: String,
	channel_id: String,
	inviter_id: String,

	// ? What is this?
	target_user_id: String,
	target_user_type: Number,
});

InviteSchema.virtual("channel", {
	ref: ChannelModel,
	localField: "channel_id",
	foreignField: "id",
	justOne: true,
	autopopulate: {
		select: {
			id: true,
			name: true,
			type: true,
		},
	},
});

InviteSchema.virtual("inviter", {
	ref: UserModel,
	localField: "inviter_id",
	foreignField: "id",
	justOne: true,
	autopopulate: {
		select: PublicUserProjection,
	},
});

InviteSchema.virtual("guild", {
	ref: GuildModel,
	localField: "guild_id",
	foreignField: "id",
	justOne: true,
	autopopulate: {
		select: {
			id: true,
			name: true,
			splash: true,
			banner: true,
			description: true,
			icon: true,
			features: true,
			verification_level: true,
			vanity_url_code: true,
			welcome_screen: true,
			nsfw: true,

			// TODO: hide the following entries:
			// channels: false,
			// roles: false,
			// emojis: false,
		},
	},
});

// @ts-ignore
export const InviteModel = db.model<InviteDocument>("Invite", InviteSchema, "invites");