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:
parent
e23459f774
commit
6459393153
@ -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": {
|
||||
|
28
api/src/routes/users/@me/guilds/settings.ts
Normal file
28
api/src/routes/users/@me/guilds/settings.ts
Normal 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;
|
Loading…
Reference in New Issue
Block a user