From 31023ffa68d0787d8ffd6a4665fd36fc4552740b Mon Sep 17 00:00:00 2001 From: Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> Date: Fri, 21 May 2021 17:47:53 +0200 Subject: [PATCH] :sparkles: [Message] Model add created_at --- src/models/Message.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/models/Message.ts b/src/models/Message.ts index 636e2575..4a66d76c 100644 --- a/src/models/Message.ts +++ b/src/models/Message.ts @@ -1,9 +1,10 @@ import { Schema, Types, Document } from "mongoose"; import db from "../util/Database"; import { PublicUser, PublicUserProjection, UserModel } from "./User"; -import { MemberModel, PublicMember, PublicMemberProjection } from "./Member"; +import { MemberModel, PublicMember } from "./Member"; import { Role, RoleModel } from "./Role"; import { Channel } from "./Channel"; +import { Snowflake } from "../util"; export interface Message { id: string; @@ -45,6 +46,7 @@ export interface Message { })[]; mention_roles?: Role[]; mention_channels?: Channel[]; + created_at: Date; } export interface MessageDocument extends Document, Message { @@ -280,6 +282,10 @@ MessageSchema.virtual("mention_channels", { autopopulate: { select: { id: true, guild_id: true, type: true, name: true } }, }); +MessageSchema.virtual("created_at").get(function (this: MessageDocument) { + return new Date(Snowflake.deconstruct(this.id).timestamp); +}); + MessageSchema.set("removeResponse", ["mention_channel_ids", "mention_role_ids", "mention_user_ids", "author_id"]); // TODO: missing Application Model