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

Member settings route

This commit is contained in:
Madeline 2022-09-21 14:28:05 +10:00
parent e23459f774
commit 6459393153
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;