summary refs log tree commit diff
path: root/src/api/routes/users/@me/settings.ts
diff options
context:
space:
mode:
authorMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2022-08-22 22:08:22 +1000
committerMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2022-08-22 22:08:22 +1000
commit975c414434ee08622126bdeb4060532029413c18 (patch)
treea46b7f33a150963f6b8d3515225574610325713f /src/api/routes/users/@me/settings.ts
parentMerge branch 'master' into fix/claim_accounts (diff)
parentMerge remote-tracking branch 'Puyodead1/patch/prettier-config' into staging (diff)
downloadserver-975c414434ee08622126bdeb4060532029413c18.tar.xz
Merge remote-tracking branch 'upstream/staging' into fix/claim_accounts
Diffstat (limited to 'src/api/routes/users/@me/settings.ts')
-rw-r--r--src/api/routes/users/@me/settings.ts18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/api/routes/users/@me/settings.ts b/src/api/routes/users/@me/settings.ts
new file mode 100644
index 00000000..7578d36e
--- /dev/null
+++ b/src/api/routes/users/@me/settings.ts
@@ -0,0 +1,18 @@
+import { Router, Response, Request } from "express";
+import { User, UserSettings } from "@fosscord/util";
+import { route } from "@fosscord/api";
+
+const router = Router();
+
+router.patch("/", route({ body: "UserSettingsSchema" }), async (req: Request, res: Response) => {
+	const body = req.body as UserSettings;
+	if (body.locale === "en") body.locale = "en-US"; // fix discord client crash on unkown locale
+
+	const user = await User.findOneOrFail({ where: { id: req.user_id, bot: false }, relations: ["settings"] });
+	user.settings = { ...user.settings, ...body } as UserSettings;
+	await user.save();
+
+	res.sendStatus(204);
+});
+
+export default router;