diff --git a/src/util/Config.ts b/src/util/Config.ts
index a9cbddde..60d83e1a 100644
--- a/src/util/Config.ts
+++ b/src/util/Config.ts
@@ -23,7 +23,7 @@ export interface RateLimit {
export interface DefaultOptions {
general: {
- instance_id: bigint;
+ instance_id: string;
};
permissions: {
user: {
diff --git a/src/util/Event.ts b/src/util/Event.ts
index 43c51d5c..8a24e4bb 100644
--- a/src/util/Event.ts
+++ b/src/util/Event.ts
@@ -5,6 +5,7 @@ export async function emitEvent(payload: Omit<Event, "created_at">) {
created_at: new Date(), // in seconds
...payload,
};
+ // TODO: bigint isn't working
return await new EventModel(obj).save();
}
diff --git a/src/util/Member.ts b/src/util/Member.ts
index 319eab60..4d1b8ac5 100644
--- a/src/util/Member.ts
+++ b/src/util/Member.ts
@@ -25,12 +25,10 @@ export const PublicMemberProjection = {
premium_since: true,
};
-export async function addMember(user_id: bigint, guild_id: bigint, cache?: { guild?: Guild }) {
+export async function addMember(user_id: string, guild_id: string, cache?: { guild?: Guild }) {
const user = await getPublicUser(user_id, { guilds: true });
const guildSize = user.guilds.length;
- // @ts-ignore
- user.guilds = undefined;
const { maxGuilds } = Config.get().limits.user;
if (guildSize >= maxGuilds) {
@@ -77,6 +75,7 @@ export async function addMember(user_id: bigint, guild_id: bigint, cache?: { gui
},
guild_id: guild_id,
} as GuildMemberAddEvent),
+
emitEvent({
event: "GUILD_CREATE",
data: guild,
@@ -85,7 +84,7 @@ export async function addMember(user_id: bigint, guild_id: bigint, cache?: { gui
]);
}
-export async function removeMember(user_id: bigint, guild_id: bigint) {
+export async function removeMember(user_id: string, guild_id: string) {
const user = await getPublicUser(user_id);
const guild = await GuildModel.findOne({ id: guild_id }, { owner_id: true }).exec();
diff --git a/src/util/User.ts b/src/util/User.ts
index 1b13e153..05213642 100644
--- a/src/util/User.ts
+++ b/src/util/User.ts
@@ -1,4 +1,4 @@
-import { UserModel } from "fosscord-server-util";
+import { toObject, UserModel } from "fosscord-server-util";
import { HTTPError } from "lambert-server";
export const PublicUserProjection = {
@@ -9,7 +9,7 @@ export const PublicUserProjection = {
avatar: true,
};
-export async function getPublicUser(user_id: bigint, additional_fields?: any) {
+export async function getPublicUser(user_id: string, additional_fields?: any) {
const user = await UserModel.findOne(
{ id: user_id },
{
@@ -18,5 +18,5 @@ export async function getPublicUser(user_id: bigint, additional_fields?: any) {
}
).exec();
if (!user) throw new HTTPError("User not found", 404);
- return user;
+ return toObject(user);
}
diff --git a/src/util/instanceOf.ts b/src/util/instanceOf.ts
index 4f30bd46..b4a231ba 100644
--- a/src/util/instanceOf.ts
+++ b/src/util/instanceOf.ts
@@ -114,8 +114,6 @@ export function instanceOf(
}
if (typeof type === "object") {
- if (typeof value !== "object") throw new FieldError("BASE_TYPE_OBJECT", req.t("common:field.BASE_TYPE_OBJECT"));
-
if (Array.isArray(type)) {
if (!Array.isArray(value)) throw new FieldError("BASE_TYPE_ARRAY", req.t("common:field.BASE_TYPE_ARRAY"));
if (!type.length) return true; // type array didn't specify any type
@@ -123,7 +121,8 @@ export function instanceOf(
return (
value.every((val, i) => {
errors[i] = {};
- return (
+
+ if (
instanceOf(type[0], val, {
path: `${path}[${i}]`,
optional,
@@ -131,7 +130,12 @@ export function instanceOf(
req,
ref: { key: i, obj: value },
}) === true
- );
+ ) {
+ delete errors[i];
+ return true;
+ }
+
+ return false;
}) || errors
);
} else if (type?.constructor?.name != "Object") {
@@ -150,10 +154,15 @@ export function instanceOf(
})
);
}
- if (value instanceof type) return true;
- throw new FieldError("BASE_TYPE_CLASS", req.t("common:field.BASE_TYPE_CLASS", { type }));
+ try {
+ if (value instanceof type) return true;
+ } catch (error) {
+ throw new FieldError("BASE_TYPE_CLASS", req.t("common:field.BASE_TYPE_CLASS", { type }));
+ }
}
+ if (typeof value !== "object") throw new FieldError("BASE_TYPE_OBJECT", req.t("common:field.BASE_TYPE_OBJECT"));
+
const diff = Object.keys(value).missing(
Object.keys(type).map((x) => (x.startsWith(OPTIONAL_PREFIX) ? x.slice(OPTIONAL_PREFIX.length) : x))
);
@@ -167,7 +176,7 @@ export function instanceOf(
if (OPTIONAL) newKey = newKey.slice(OPTIONAL_PREFIX.length);
errors[newKey] = {};
- return (
+ if (
instanceOf(type[key], value[newKey], {
path: `${path}.${newKey}`,
optional: OPTIONAL,
@@ -175,7 +184,12 @@ export function instanceOf(
req,
ref: { key: newKey, obj: value },
}) === true
- );
+ ) {
+ delete errors[newKey];
+ return true;
+ }
+
+ return false;
}) || errors
);
} else if (typeof type === "number" || typeof type === "string" || typeof type === "boolean") {
|