From e3f5d7060bc147abd4cee67d1eb0b55064898cde Mon Sep 17 00:00:00 2001 From: Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> Date: Sat, 22 May 2021 22:54:45 +0200 Subject: [PATCH] :sparkles: BanSchema --- src/models/Ban.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/models/Ban.ts b/src/models/Ban.ts index 27893029..2d1da4f0 100644 --- a/src/models/Ban.ts +++ b/src/models/Ban.ts @@ -1,5 +1,6 @@ import { Schema, model, Types, Document } from "mongoose"; import db from "../util/Database"; +import { PublicUserProjection, UserModel } from "./User"; export interface Ban extends Document { user_id: string; @@ -17,5 +18,13 @@ export const BanSchema = new Schema({ ip: String, // ? Should we store this in here, or in the UserModel? }); +BanSchema.virtual("user", { + ref: UserModel, + localField: "id", + foreignField: "user_id", + justOne: true, + autopopulate: { select: PublicUserProjection }, +}); + // @ts-ignore export const BanModel = db.model("Ban", BanSchema, "bans");