diff --git a/assets/openapi.json b/assets/openapi.json index 726022e3..953b2133 100644 Binary files a/assets/openapi.json and b/assets/openapi.json differ diff --git a/assets/schemas.json b/assets/schemas.json index 495adfb1..85c7c9c6 100644 Binary files a/assets/schemas.json and b/assets/schemas.json differ 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); + 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 similarity index 95% rename from src/schemas/uncategorised/UserSettingsSchema.ts rename to 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 . */ +export type UserSettingsUpdateSchema = Partial; + 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";