mirror of
https://github.com/spacebarchat/server.git
synced 2024-11-10 12:42:44 +01:00
Fix user guild settings
This commit is contained in:
parent
7818e8dd3c
commit
138cad6b8d
@ -1,22 +1,14 @@
|
||||
import { Router, Response, Request } from "express";
|
||||
import {
|
||||
Channel,
|
||||
ChannelOverride,
|
||||
Member,
|
||||
UserGuildSettings,
|
||||
OrmUtils,
|
||||
UserGuildSettingsSchema,
|
||||
} from "@fosscord/util";
|
||||
import { route } from "@fosscord/api";
|
||||
|
||||
const router = Router();
|
||||
|
||||
// This sucks. I would use a DeepPartial, my own or typeorms, but they both generate inncorect schema
|
||||
export interface UserGuildSettingsSchema
|
||||
extends Partial<Omit<UserGuildSettings, "channel_overrides">> {
|
||||
channel_overrides: {
|
||||
[channel_id: string]: Partial<ChannelOverride>;
|
||||
};
|
||||
}
|
||||
|
||||
// GET doesn't exist on discord.com
|
||||
router.get("/", route({}), async (req: Request, res: Response) => {
|
||||
const user = await Member.findOneOrFail({
|
||||
@ -30,7 +22,7 @@ router.patch(
|
||||
"/",
|
||||
route({ body: "UserGuildSettingsSchema" }),
|
||||
async (req: Request, res: Response) => {
|
||||
const body = req.body as UserGuildSettings;
|
||||
const body = req.body as UserGuildSettingsSchema;
|
||||
|
||||
if (body.channel_overrides) {
|
||||
for (var channel in body.channel_overrides) {
|
||||
@ -40,9 +32,11 @@ router.patch(
|
||||
|
||||
const user = await Member.findOneOrFail({
|
||||
where: { id: req.user_id, guild_id: req.params.guild_id },
|
||||
select: ["settings"]
|
||||
|
||||
});
|
||||
user.settings = { ...user.settings, ...body };
|
||||
await user.save();
|
||||
OrmUtils.mergeDeep(user.settings || {}, body);
|
||||
Member.update({ id: req.user_id, guild_id: req.params.guild_id }, user);
|
||||
|
||||
res.json(user.settings);
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user