diff --git a/util/src/models/Application.ts b/util/oldModels/Application.ts
index fae6e8db..fae6e8db 100644
--- a/util/src/models/Application.ts
+++ b/util/oldModels/Application.ts
diff --git a/util/src/models/AuditLog.ts b/util/oldModels/AuditLog.ts
index 02b2c444..02b2c444 100644
--- a/util/src/models/AuditLog.ts
+++ b/util/oldModels/AuditLog.ts
diff --git a/util/src/models/Ban.ts b/util/oldModels/Ban.ts
index f09950ee..f09950ee 100644
--- a/util/src/models/Ban.ts
+++ b/util/oldModels/Ban.ts
diff --git a/util/src/models/Channel.ts b/util/oldModels/Channel.ts
index 2959decd..2959decd 100644
--- a/util/src/models/Channel.ts
+++ b/util/oldModels/Channel.ts
diff --git a/util/src/models/Emoji.ts b/util/oldModels/Emoji.ts
index 3e5cad53..3e5cad53 100644
--- a/util/src/models/Emoji.ts
+++ b/util/oldModels/Emoji.ts
diff --git a/util/src/models/Event.ts b/util/oldModels/Event.ts
index 86d0fd00..904522a8 100644
--- a/util/src/models/Event.ts
+++ b/util/oldModels/Event.ts
@@ -3,7 +3,7 @@ import { DMChannel, Channel } from "./Channel";
import { Guild } from "./Guild";
import { Member, PublicMember, UserGuildSettings } from "./Member";
import { Emoji } from "./Emoji";
-import { Presence } from "./Activity";
+import { Presence } from "../models/Activity";
import { Role } from "./Role";
import { Invite } from "./Invite";
import { Message, PartialEmoji } from "./Message";
diff --git a/util/src/models/Guild.ts b/util/oldModels/Guild.ts
index a5dcd8e3..a5dcd8e3 100644
--- a/util/src/models/Guild.ts
+++ b/util/oldModels/Guild.ts
diff --git a/util/src/models/Interaction.ts b/util/oldModels/Interaction.ts
index 764247a5..764247a5 100644
--- a/util/src/models/Interaction.ts
+++ b/util/oldModels/Interaction.ts
diff --git a/util/src/models/Invite.ts b/util/oldModels/Invite.ts
index 01f12003..01f12003 100644
--- a/util/src/models/Invite.ts
+++ b/util/oldModels/Invite.ts
diff --git a/util/src/models/Member.ts b/util/oldModels/Member.ts
index d1c9ad9b..d1c9ad9b 100644
--- a/util/src/models/Member.ts
+++ b/util/oldModels/Member.ts
diff --git a/util/src/models/Message.ts b/util/oldModels/Message.ts
index 15a6f40d..15a6f40d 100644
--- a/util/src/models/Message.ts
+++ b/util/oldModels/Message.ts
diff --git a/util/src/models/RateLimit.ts b/util/oldModels/RateLimit.ts
index 6a0e1ffd..6a0e1ffd 100644
--- a/util/src/models/RateLimit.ts
+++ b/util/oldModels/RateLimit.ts
diff --git a/util/src/models/ReadState.ts b/util/oldModels/ReadState.ts
index 9c4fb323..9c4fb323 100644
--- a/util/src/models/ReadState.ts
+++ b/util/oldModels/ReadState.ts
diff --git a/util/src/models/Role.ts b/util/oldModels/Role.ts
index c1111c84..c1111c84 100644
--- a/util/src/models/Role.ts
+++ b/util/oldModels/Role.ts
diff --git a/util/src/models/Team.ts b/util/oldModels/Team.ts
index 795c82d2..795c82d2 100644
--- a/util/src/models/Team.ts
+++ b/util/oldModels/Team.ts
diff --git a/util/src/models/Template.ts b/util/oldModels/Template.ts
index ad0f9104..ad0f9104 100644
--- a/util/src/models/Template.ts
+++ b/util/oldModels/Template.ts
diff --git a/util/src/models/VoiceState.ts b/util/oldModels/VoiceState.ts
index c1f90edd..c1f90edd 100644
--- a/util/src/models/VoiceState.ts
+++ b/util/oldModels/VoiceState.ts
diff --git a/util/src/models/Webhook.ts b/util/oldModels/Webhook.ts
index 7379e98f..7379e98f 100644
--- a/util/src/models/Webhook.ts
+++ b/util/oldModels/Webhook.ts
diff --git a/util/oldModels/index.ts b/util/oldModels/index.ts
new file mode 100644
index 00000000..63578a13
--- /dev/null
+++ b/util/oldModels/index.ts
@@ -0,0 +1,93 @@
+// @ts-nocheck
+import mongoose, { Schema, Document } from "mongoose";
+import mongooseAutoPopulate from "mongoose-autopopulate";
+
+type UpdateWithAggregationPipeline = UpdateAggregationStage[];
+type UpdateAggregationStage =
+ | { $addFields: any }
+ | { $set: any }
+ | { $project: any }
+ | { $unset: any }
+ | { $replaceRoot: any }
+ | { $replaceWith: any };
+type EnforceDocument<T, TMethods> = T extends Document ? T : T & Document & TMethods;
+
+declare module "mongoose" {
+ interface SchemaOptions {
+ removeResponse?: string[];
+ }
+ interface Model<T, TQueryHelpers = {}, TMethods = {}> {
+ // removed null -> always return document -> throw error if it doesn't exist
+ findOne(
+ filter?: FilterQuery<T>,
+ projection?: any | null,
+ options?: QueryOptions | null,
+ callback?: (err: CallbackError, doc: EnforceDocument<T, TMethods>) => void
+ ): QueryWithHelpers<EnforceDocument<T, TMethods>, EnforceDocument<T, TMethods>, TQueryHelpers>;
+ findOneAndUpdate(
+ filter?: FilterQuery<T>,
+ update?: UpdateQuery<T> | UpdateWithAggregationPipeline,
+ options?: QueryOptions | null,
+ callback?: (err: any, doc: EnforceDocument<T, TMethods> | null, res: any) => void
+ ): QueryWithHelpers<EnforceDocument<T, TMethods>, EnforceDocument<T, TMethods>, TQueryHelpers>;
+ }
+}
+
+var HTTPError: any;
+
+try {
+ HTTPError = require("lambert-server").HTTPError;
+} catch (e) {
+ HTTPError = Error;
+}
+
+mongoose.plugin(mongooseAutoPopulate);
+
+mongoose.plugin((schema: Schema, opts: any) => {
+ schema.set("toObject", {
+ virtuals: true,
+ versionKey: false,
+ transform(doc: any, ret: any) {
+ delete ret._id;
+ delete ret.__v;
+ const props = schema.get("removeResponse") || [];
+ props.forEach((prop: string) => {
+ delete ret[prop];
+ });
+ },
+ });
+ schema.post("findOne", function (doc, next) {
+ try {
+ // @ts-ignore
+ const isExistsQuery = JSON.stringify(this._userProvidedFields) === JSON.stringify({ _id: 1 });
+ if (!doc && !isExistsQuery) {
+ // @ts-ignore
+ return next(new HTTPError(`${this?.mongooseCollection?.name}.${this?._conditions?.id} not found`, 400));
+ }
+ // @ts-ignore
+ return next();
+ } catch (error) {
+ // @ts-ignore
+ next();
+ }
+ });
+});
+
+export * from "../models/Activity";
+export * from "./Application";
+export * from "./Ban";
+export * from "./Channel";
+export * from "./Emoji";
+export * from "./Event";
+export * from "./Template";
+export * from "./Guild";
+export * from "./Invite";
+export * from "./Interaction";
+export * from "./Member";
+export * from "./Message";
+export * from "../models/Status";
+export * from "./Role";
+export * from "./User";
+export * from "./VoiceState";
+export * from "./ReadState";
+export * from "./RateLimit";
|