From 92a6c981ce12f4484509d0388cb1fba2a52b55c4 Mon Sep 17 00:00:00 2001 From: Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> Date: Mon, 22 Feb 2021 21:30:38 +0100 Subject: :sparkles: MemberModel add virtual user field --- src/models/Guild.ts | 2 ++ src/models/Member.ts | 12 ++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/models/Guild.ts b/src/models/Guild.ts index 8eb7533f..effc20ee 100644 --- a/src/models/Guild.ts +++ b/src/models/Guild.ts @@ -87,5 +87,7 @@ export const GuildSchema = new Schema({ widget_enabled: Boolean, }); +// GuildSchema.virtual + // @ts-ignore export const GuildModel = db.model("Guild", GuildSchema, "guilds"); diff --git a/src/models/Member.ts b/src/models/Member.ts index a377f54e..c177c6c9 100644 --- a/src/models/Member.ts +++ b/src/models/Member.ts @@ -1,5 +1,5 @@ -import { PublicUser } from "./User"; -import { Schema, model, Types, Document } from "mongoose"; +import { PublicUser, User, UserModel } from "./User"; +import { Schema, Types, Document } from "mongoose"; import db from "../util/Database"; export interface Member { @@ -13,6 +13,7 @@ export interface Member { mute: boolean; pending: boolean; settings: UserGuildSettings; + user?: User; } export interface MemberDocument extends Member, Document { @@ -74,9 +75,16 @@ export const MemberSchema = new Schema({ }, }); +MemberSchema.virtual("user", { + model: UserModel, + localField: "user", + foreignField: "id", +}); + // @ts-ignore export const MemberModel = db.model("Member", MemberSchema, "members"); +// @ts-ignore export interface PublicMember extends Omit { user: PublicUser; } -- cgit 1.4.1