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
|
import { Schema, Document, Types } from "mongoose";
import { transpileModule } from "typescript";
import db from "../util/Database";
import { ChannelModel } from "./Channel";
import { GuildModel } from "./Guild";
export interface Webhook {}
export enum WebhookType {
Incoming = 1,
ChannelFollower = 2,
}
export interface WebhookDocument extends Document, Webhook {
id: String;
type: number;
guild_id?: string;
channel_id: string;
name?: string;
avatar?: string;
token?: string;
application_id?: string;
user_id?: string;
source_guild_id: string;
}
export const WebhookSchema = new Schema({
id: { type: String, required: true },
type: { type: Number, required: true },
guild_id: String,
channel_id: String,
name: String,
avatar: String,
token: String,
application_id: String,
user_id: String,
source_guild_id: String,
source_channel_id: String,
});
WebhookSchema.virtual("source_guild", {
ref: GuildModel,
localField: "id",
foreignField: "source_guild_id",
justOne: true,
autopopulate: {
select: {
icon: true,
id: true,
name: true,
},
},
});
WebhookSchema.virtual("source_channel", {
ref: ChannelModel,
localField: "id",
foreignField: "source_channel_id",
justOne: true,
autopopulate: {
select: {
id: true,
name: true,
},
},
});
WebhookSchema.virtual("source_channel", {
ref: ChannelModel,
localField: "id",
foreignField: "source_channel_id",
justOne: true,
autopopulate: {
select: {
id: true,
name: true,
},
},
});
WebhookSchema.set("removeResponse", ["source_channel_id", "source_guild_id"]);
export const WebhookModel = db.model<WebhookDocument>("Webhook", WebhookSchema, "webhooks");
|