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 { Router, Response, Request } from "express";
|
||||||
import {
|
import {
|
||||||
Channel,
|
Channel,
|
||||||
ChannelOverride,
|
|
||||||
Member,
|
Member,
|
||||||
UserGuildSettings,
|
OrmUtils,
|
||||||
|
UserGuildSettingsSchema,
|
||||||
} from "@fosscord/util";
|
} from "@fosscord/util";
|
||||||
import { route } from "@fosscord/api";
|
import { route } from "@fosscord/api";
|
||||||
|
|
||||||
const router = Router();
|
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
|
// GET doesn't exist on discord.com
|
||||||
router.get("/", route({}), async (req: Request, res: Response) => {
|
router.get("/", route({}), async (req: Request, res: Response) => {
|
||||||
const user = await Member.findOneOrFail({
|
const user = await Member.findOneOrFail({
|
||||||
@ -30,7 +22,7 @@ router.patch(
|
|||||||
"/",
|
"/",
|
||||||
route({ body: "UserGuildSettingsSchema" }),
|
route({ body: "UserGuildSettingsSchema" }),
|
||||||
async (req: Request, res: Response) => {
|
async (req: Request, res: Response) => {
|
||||||
const body = req.body as UserGuildSettings;
|
const body = req.body as UserGuildSettingsSchema;
|
||||||
|
|
||||||
if (body.channel_overrides) {
|
if (body.channel_overrides) {
|
||||||
for (var channel in body.channel_overrides) {
|
for (var channel in body.channel_overrides) {
|
||||||
@ -40,9 +32,11 @@ router.patch(
|
|||||||
|
|
||||||
const user = await Member.findOneOrFail({
|
const user = await Member.findOneOrFail({
|
||||||
where: { id: req.user_id, guild_id: req.params.guild_id },
|
where: { id: req.user_id, guild_id: req.params.guild_id },
|
||||||
|
select: ["settings"]
|
||||||
|
|
||||||
});
|
});
|
||||||
user.settings = { ...user.settings, ...body };
|
OrmUtils.mergeDeep(user.settings || {}, body);
|
||||||
await user.save();
|
Member.update({ id: req.user_id, guild_id: req.params.guild_id }, user);
|
||||||
|
|
||||||
res.json(user.settings);
|
res.json(user.settings);
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user