Partial usersetting update schema

This commit is contained in:
Rory& 2025-10-18 09:14:34 +02:00
parent e46ba34a66
commit 4b5db1c2f4
6 changed files with 10 additions and 7 deletions

Binary file not shown.

Binary file not shown.

View File

@ -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);

View File

@ -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;
}
}

View File

@ -18,3 +18,4 @@
export * from "./ConnectedAccount";
export * from "./Member";
export * from "./User";
export * from "./UserSettings";

View File

@ -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";