summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/api/routes/users/@me/settings.ts4
-rw-r--r--src/util/entities/User.ts23
-rw-r--r--src/util/schemas/UserModifySchema.ts4
-rw-r--r--src/util/schemas/UserSettingsSchema.ts2
4 files changed, 15 insertions, 18 deletions
diff --git a/src/api/routes/users/@me/settings.ts b/src/api/routes/users/@me/settings.ts
index c883bb30..cfcedec1 100644
--- a/src/api/routes/users/@me/settings.ts
+++ b/src/api/routes/users/@me/settings.ts
@@ -44,9 +44,9 @@ router.patch(
 
 		user.settings.assign(body);
 
-		user.settings.save();
+		await user.settings.save();
 
-		res.json(user.settings);
+		res.json({ ...user.settings, index: undefined });
 	},
 );
 
diff --git a/src/util/entities/User.ts b/src/util/entities/User.ts
index fa8c7aa7..7b67c2ac 100644
--- a/src/util/entities/User.ts
+++ b/src/util/entities/User.ts
@@ -246,27 +246,20 @@ export class User extends BaseClass {
 
 		if (this.discriminator) {
 			const discrim = Number(this.discriminator);
-			if (this.discriminator.length > 4)
-				throw FieldErrors({
-					discriminator: {
-						message: "Discriminator cannot be more than 4 digits.",
-						code: "DISCRIMINATOR_INVALID",
-					},
-				});
-			if (isNaN(discrim))
-				throw FieldErrors({
-					discriminator: {
-						message: "Discriminator must be a number.",
-						code: "DISCRIMINATOR_INVALID",
-					},
-				});
-			if (discrim <= 0 || discrim >= 10000)
+			if (
+				isNaN(discrim) ||
+				!(typeof discrim == "number") ||
+				!Number.isInteger(discrim) ||
+				discrim <= 0 ||
+				discrim >= 10000
+			)
 				throw FieldErrors({
 					discriminator: {
 						message: "Discriminator must be a number.",
 						code: "DISCRIMINATOR_INVALID",
 					},
 				});
+
 			this.discriminator = discrim.toString().padStart(4, "0");
 		}
 	}
diff --git a/src/util/schemas/UserModifySchema.ts b/src/util/schemas/UserModifySchema.ts
index 2316477e..7851ec22 100644
--- a/src/util/schemas/UserModifySchema.ts
+++ b/src/util/schemas/UserModifySchema.ts
@@ -33,5 +33,9 @@ export interface UserModifySchema {
 	new_password?: string;
 	code?: string;
 	email?: string;
+	/**
+	 * @minLength 4
+	 * @maxLength 4
+	 */
 	discriminator?: string;
 }
diff --git a/src/util/schemas/UserSettingsSchema.ts b/src/util/schemas/UserSettingsSchema.ts
index 5a590b02..f315892e 100644
--- a/src/util/schemas/UserSettingsSchema.ts
+++ b/src/util/schemas/UserSettingsSchema.ts
@@ -18,4 +18,4 @@
 
 import { UserSettings } from "@fosscord/util";
 
-export type UserSettingsSchema = Partial<UserSettings>;
+export type UserSettingsSchema = Omit<Partial<UserSettings>, "index">;