mirror of
https://github.com/spacebarchat/server.git
synced 2024-09-22 10:41:34 +02:00
✨ Webhook Model
This commit is contained in:
parent
6f5fba5c38
commit
51dfeca70d
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@fosscord/server-util",
|
"name": "@fosscord/server-util",
|
||||||
"version": "1.0.3",
|
"version": "1.0.4",
|
||||||
"description": "Utility functions for the all server repositories",
|
"description": "Utility functions for the all server repositories",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"types": "dist/index.d.ts",
|
"types": "dist/index.d.ts",
|
||||||
|
@ -97,6 +97,14 @@ MemberSchema.virtual("user", {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
MemberSchema.virtual("roles", {
|
||||||
|
ref: UserModel,
|
||||||
|
localField: "id",
|
||||||
|
foreignField: "id",
|
||||||
|
justOne: true,
|
||||||
|
autopopulate: true,
|
||||||
|
});
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
export const MemberModel = db.model<MemberDocument>("Member", MemberSchema, "members");
|
export const MemberModel = db.model<MemberDocument>("Member", MemberSchema, "members");
|
||||||
|
|
||||||
|
83
src/models/Webhook.ts
Normal file
83
src/models/Webhook.ts
Normal file
@ -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");
|
Loading…
Reference in New Issue
Block a user