summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-04-23 00:47:28 +0200
committerFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-04-23 00:47:28 +0200
commit51dfeca70d5b1ab40c51dce7a7001dc158e8c0b5 (patch)
tree8701b6f59cff85248fe0235cb33d71ef9dea29f6 /src
parent:sparkles: throw missing permission (diff)
downloadserver-51dfeca70d5b1ab40c51dce7a7001dc158e8c0b5.tar.xz
:sparkles: Webhook Model
Diffstat (limited to 'src')
-rw-r--r--src/models/Member.ts8
-rw-r--r--src/models/Webhook.ts83
2 files changed, 91 insertions, 0 deletions
diff --git a/src/models/Member.ts b/src/models/Member.ts

index 52151235..1a775629 100644 --- a/src/models/Member.ts +++ b/src/models/Member.ts
@@ -97,6 +97,14 @@ MemberSchema.virtual("user", { }, }); +MemberSchema.virtual("roles", { + ref: UserModel, + localField: "id", + foreignField: "id", + justOne: true, + autopopulate: true, +}); + // @ts-ignore export const MemberModel = db.model<MemberDocument>("Member", MemberSchema, "members"); diff --git a/src/models/Webhook.ts b/src/models/Webhook.ts new file mode 100644
index 00000000..4660686d --- /dev/null +++ b/src/models/Webhook.ts
@@ -0,0 +1,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");