1
0
mirror of https://github.com/spacebarchat/server.git synced 2024-11-22 18:32:29 +01:00

Member settings route

This commit is contained in:
Madeline 2022-09-21 14:28:05 +10:00
parent 4020422822
commit 975a87232f
No known key found for this signature in database
GPG Key ID: 1958E017C36F2E47
2 changed files with 33 additions and 0 deletions

View File

@ -1136,6 +1136,11 @@
],
"$schema": "http://json-schema.org/draft-07/schema#"
},
"UserGuildSettingsSchema": {
"type": "object",
"additionalProperties": false,
"$schema": "http://json-schema.org/draft-07/schema#"
},
"UserModifySchema": {
"type": "object",
"properties": {

View File

@ -0,0 +1,28 @@
import { Router, Response, Request } from "express";
import { Member, UserGuildSettings } from "@fosscord/util";
import { route } from "@fosscord/api";
const router = Router();
export interface UserGuildSettingsSchema extends Partial<UserGuildSettings> { }
// GET doesn't exist on discord.com
router.get("/", route({}), async (req: Request, res: Response) => {
const user = await Member.findOneOrFail({
where: { id: req.user_id },
select: ["settings"]
});
return res.json(user.settings);
});
router.patch("/", route({ body: "UserSettingsSchema" }), async (req: Request, res: Response) => {
const body = req.body as UserGuildSettings;
const user = await Member.findOneOrFail({ where: { id: req.user_id } });
user.settings = { ...user.settings, ...body };
await user.save();
res.json(user.settings);
});
export default router;