summary refs log tree commit diff
path: root/src/models/Message.ts
diff options
context:
space:
mode:
authorFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-04-07 03:02:13 +0200
committerFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-04-07 03:02:13 +0200
commitf48127f8a4881afc6dfb9b066b4eb357f1ef6c63 (patch)
tree2fcd6f0d13b54ceb9490902767beab6d013cd480 /src/models/Message.ts
parentremove dist (diff)
downloadserver-f48127f8a4881afc6dfb9b066b4eb357f1ef6c63.tar.xz
:bug: fix lean not working with virtuals
Diffstat (limited to 'src/models/Message.ts')
-rw-r--r--src/models/Message.ts86
1 files changed, 42 insertions, 44 deletions
diff --git a/src/models/Message.ts b/src/models/Message.ts

index 15f00cf4..ee038f97 100644 --- a/src/models/Message.ts +++ b/src/models/Message.ts
@@ -1,8 +1,9 @@ import { Schema, Types, Document } from "mongoose"; import db from "../util/Database"; -import { UserModel } from "./User"; -import { MemberModel } from "./Member"; -import { RoleModel } from "./Role"; +import { PublicUser, UserModel } from "./User"; +import { MemberModel, PublicMember } from "./Member"; +import { Role, RoleModel } from "./Role"; +import { Channel } from "./Channel"; export interface Message { id: string; @@ -36,6 +37,12 @@ export interface Message { channel_id?: string; guild_id?: string; }; + // mongoose virtuals: + author?: PublicUser; + member?: PublicMember; + mentions?: PublicUser[]; + mention_roles?: Role[]; + mention_channels?: Channel[]; } export interface MessageDocument extends Document, Message { @@ -190,50 +197,39 @@ export const Embed = { ], }; -export const MessageSchema = new Schema( - { - id: String, +export const MessageSchema = new Schema({ + id: String, + channel_id: String, + author_id: String, + webhook_id: String, + guild_id: String, + application_id: String, + content: String, + timestamp: Date, + edited_timestamp: Date, + tts: Boolean, + mention_everyone: Boolean, + mention_user_ids: [String], + mention_role_ids: [String], + mention_channel_ids: [String], + attachments: [Attachment], + embeds: [Embed], + reactions: [Reaction], + nonce: Schema.Types.Mixed, // can be a long or a string + pinned: Boolean, + type: { type: Number }, + activity: { + type: Number, + party_id: String, + }, + flags: Types.Long, + stickers: [], + message_reference: { + message_id: String, channel_id: String, - author_id: String, - webhook_id: String, guild_id: String, - application_id: String, - content: String, - timestamp: Date, - edited_timestamp: Date, - tts: Boolean, - mention_everyone: Boolean, - mention_user_ids: [String], - mention_role_ids: [String], - mention_channel_ids: [String], - attachments: [Attachment], - embeds: [Embed], - reactions: [Reaction], - nonce: Schema.Types.Mixed, // can be a long or a string - pinned: Boolean, - type: { type: Number }, - activity: { - type: Number, - party_id: String, - }, - flags: Types.Long, - stickers: [], - message_reference: { - message_id: String, - channel_id: String, - guild_id: String, - }, }, - { - toJSON: { - transform: function (doc, ret) { - delete ret.mention_channel_ids; - delete ret.mention_user_ids; - delete ret.mention_role_ids; - }, - }, - } -); +}); MessageSchema.virtual("author", { ref: UserModel, @@ -270,6 +266,8 @@ MessageSchema.virtual("mention_channels", { justOne: false, }); +MessageSchema.set("removeResponse", ["mention_channel_ids", "mention_role_ids", "mention_user_ids", "author_id"]); + // TODO: missing Application Model // MessageSchema.virtual("application", { // ref: Application,