From a92c6637cea0ce595c712c3d445b57a1184e833e Mon Sep 17 00:00:00 2001 From: Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> Date: Thu, 12 Aug 2021 20:33:42 +0200 Subject: :sparkles: rtc --- rtc/src/models/Webhook.ts | 84 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 rtc/src/models/Webhook.ts (limited to 'rtc/src/models/Webhook.ts') diff --git a/rtc/src/models/Webhook.ts b/rtc/src/models/Webhook.ts new file mode 100644 index 00000000..7379e98f --- /dev/null +++ b/rtc/src/models/Webhook.ts @@ -0,0 +1,84 @@ +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"]); + +// @ts-ignore +export const WebhookModel = db.model("Webhook", WebhookSchema, "webhooks"); -- cgit 1.5.1