summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2025-10-18 09:14:34 +0200
committerRory& <root@rory.gay>2025-10-18 09:14:34 +0200
commit4b5db1c2f455eb0bb8c9bbad3dafe7bd4b942766 (patch)
treea6815f24fee62c3ae527e471d0f3069e008faf72 /src
parentIdentifiers: drop @format (diff)
downloadserver-ts-4b5db1c2f455eb0bb8c9bbad3dafe7bd4b942766.tar.xz
Partial usersetting update schema
Diffstat (limited to 'src')
-rw-r--r--src/api/routes/users/@me/settings.ts9
-rw-r--r--src/schemas/api/users/UserSettings.ts (renamed from src/schemas/uncategorised/UserSettingsSchema.ts)6
-rw-r--r--src/schemas/api/users/index.ts1
-rw-r--r--src/schemas/uncategorised/index.ts1
4 files changed, 10 insertions, 7 deletions
diff --git a/src/api/routes/users/@me/settings.ts b/src/api/routes/users/@me/settings.ts

index 82ca5add..beef662b 100644 --- a/src/api/routes/users/@me/settings.ts +++ b/src/api/routes/users/@me/settings.ts
@@ -19,7 +19,7 @@ import { route } from "@spacebar/api"; import { User, UserSettings } from "@spacebar/util"; import { Request, Response, Router } from "express"; -import { UserSettingsSchema } from "@spacebar/schemas" +import { UserSettingsUpdateSchema, UserSettingsSchema } from "@spacebar/schemas" const router = Router({ mergeParams: true }); @@ -44,7 +44,7 @@ router.get( router.patch( "/", route({ - requestBody: "UserSettingsSchema", + requestBody: "UserSettingsUpdateSchema", responses: { 200: { body: "UserSettings", @@ -58,7 +58,8 @@ router.patch( }, }), async (req: Request, res: Response) => { - const body = req.body as UserSettingsSchema; + const body = req.body as UserSettingsUpdateSchema; + if (!body) return res.status(400).json({ code: 400, message: "Invalid request body" }); if (body.locale === "en") body.locale = "en-US"; // fix discord client crash on unknown locale const user = await User.findOneOrFail({ @@ -67,7 +68,7 @@ router.patch( }); if (!user.settings) - user.settings = UserSettings.create(body as Partial<UserSettings>); + user.settings = UserSettings.create(body as UserSettingsUpdateSchema); else user.settings.assign(body); diff --git a/src/schemas/uncategorised/UserSettingsSchema.ts b/src/schemas/api/users/UserSettings.ts
index b9d0ec8a..410c35df 100644 --- a/src/schemas/uncategorised/UserSettingsSchema.ts +++ b/src/schemas/api/users/UserSettings.ts
@@ -16,6 +16,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>. */ +export type UserSettingsUpdateSchema = Partial<UserSettingsSchema>; + export interface UserSettingsSchema { afk_timeout: number; allow_accessibility_detection: boolean; @@ -49,7 +51,7 @@ export interface UserSettingsSchema { stream_notifications_enabled: boolean; theme: "dark" | "light"; // dark timezone_offset: number; // e.g -60 - view_nsfw_guilds: boolean + view_nsfw_guilds: boolean; } export interface CustomStatus { @@ -68,4 +70,4 @@ export interface GuildFolder { export interface FriendSourceFlags { all: boolean; -} \ No newline at end of file +} diff --git a/src/schemas/api/users/index.ts b/src/schemas/api/users/index.ts
index abc763e4..a95a3282 100644 --- a/src/schemas/api/users/index.ts +++ b/src/schemas/api/users/index.ts
@@ -18,3 +18,4 @@ export * from "./ConnectedAccount"; export * from "./Member"; export * from "./User"; +export * from "./UserSettings"; \ No newline at end of file diff --git a/src/schemas/uncategorised/index.ts b/src/schemas/uncategorised/index.ts
index c0ebde0d..8a23b16a 100644 --- a/src/schemas/uncategorised/index.ts +++ b/src/schemas/uncategorised/index.ts
@@ -82,7 +82,6 @@ export * from "./UserGuildSettingsSchema"; export * from "./UserModifySchema"; export * from "./UserNoteUpdateSchema"; export * from "./UserProfileModifySchema"; -export * from "./UserSettingsSchema"; export * from "./VanityUrlSchema"; export * from "./VerifyEmailSchema"; export * from "./VoiceStateUpdateSchema";