summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-04-06 22:06:53 +0200
committerFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-04-06 22:06:53 +0200
commit7d9cc0efbf536bcf9bf596360bd8a12652d85b95 (patch)
treec94b9cb0f8ec402ad5f1ee80d9889d1e315155dd /src
parent:bug: fix Message Model (diff)
downloadserver-7d9cc0efbf536bcf9bf596360bd8a12652d85b95.tar.xz
:art: remove _id and __v from response
Diffstat (limited to 'src')
-rw-r--r--src/index.ts25
-rw-r--r--src/models/Message.ts71
-rw-r--r--src/models/index.ts28
-rw-r--r--src/util/index.ts7
4 files changed, 78 insertions, 53 deletions
diff --git a/src/index.ts b/src/index.ts
index 8484565a..914431d8 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -1,29 +1,8 @@
 export * from "./util/checkToken";
 
 export * as Constants from "./util/Constants";
-export * from "./models/Ban";
-export * from "./models/Channel";
-export * from "./models/Emoji";
-export * from "./models/Guild";
-export * from "./models/Invite";
-export * from "./models/Member";
-export * from "./models/Role";
-export * from "./models/User";
-export * from "./models/Activity";
-export * from "./models/Application";
-export * from "./models/Interaction";
-export * from "./models/Message";
-export * from "./models/Status";
-export * from "./models/VoiceState";
-
-export * from "./util/String";
-export * from "./util/BitField";
-export * from "./util/Intents";
-export * from "./util/MessageFlags";
-export * from "./util/Permissions";
-export * from "./util/Snowflake";
-export * from "./util/UserFlags";
-export * from "./models/Event";
+export * from "./models/index";
+export * from "./util/index";
 
 import Config, { DefaultOptions } from "./util/Config";
 import db, { MongooseCache } from "./util/Database";
diff --git a/src/models/Message.ts b/src/models/Message.ts
index bb3c2d5b..15f00cf4 100644
--- a/src/models/Message.ts
+++ b/src/models/Message.ts
@@ -190,39 +190,50 @@ export const Embed = {
 	],
 };
 
-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,
+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,
+			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,
diff --git a/src/models/index.ts b/src/models/index.ts
new file mode 100644
index 00000000..bb6024fe
--- /dev/null
+++ b/src/models/index.ts
@@ -0,0 +1,28 @@
+import mongoose from "mongoose";
+
+export * from "./Ban";
+export * from "./Channel";
+export * from "./Emoji";
+export * from "./Guild";
+export * from "./Invite";
+export * from "./Member";
+export * from "./Role";
+export * from "./User";
+export * from "./Activity";
+export * from "./Application";
+export * from "./Interaction";
+export * from "./Message";
+export * from "./Status";
+export * from "./VoiceState";
+export * from "./Event";
+
+mongoose.plugin((schema: any) => {
+	schema.options.toJSON = {
+		virtuals: true,
+		versionKey: false,
+		transform(doc: any, ret: any) {
+			delete ret._id;
+			delete ret.__v;
+		},
+	};
+});
diff --git a/src/util/index.ts b/src/util/index.ts
new file mode 100644
index 00000000..b0c7fe62
--- /dev/null
+++ b/src/util/index.ts
@@ -0,0 +1,7 @@
+export * from "./String";
+export * from "./BitField";
+export * from "./Intents";
+export * from "./MessageFlags";
+export * from "./Permissions";
+export * from "./Snowflake";
+export * from "./UserFlags";