Fix connection update visibilty dying when given boolean

This commit is contained in:
Madeline 2022-12-24 14:00:54 +11:00 committed by Puyodead1
parent 02a4a6998d
commit a60f147156
No known key found for this signature in database
GPG Key ID: A4FA4FEC0DD353FC

View File

@ -1,5 +1,5 @@
import { route } from "@fosscord/api";
import { ConnectedAccount, DiscordApiErrors, emitEvent } from "@fosscord/util";
import { ConnectedAccount, DiscordApiErrors, emitEvent, ConnectionUpdateSchema } from "@fosscord/util";
import { Request, Response, Router } from "express";
const router = Router();
@ -9,6 +9,7 @@ router.patch(
route({ body: "ConnectionUpdateSchema" }),
async (req: Request, res: Response) => {
const { connection_name, connection_id } = req.params;
const body = req.body as ConnectionUpdateSchema;
const connection = await ConnectedAccount.findOne({
where: {
@ -31,7 +32,12 @@ router.patch(
if (!connection) return DiscordApiErrors.UNKNOWN_CONNECTION;
// TODO: do we need to do anything if the connection is revoked?
//@ts-ignore For some reason the client sends this as a boolean, even tho docs say its a number?
if (typeof body.visibility === "boolean") body.visibility = body.visibility ? 1 : 0;
connection.assign(req.body);
await ConnectedAccount.update(
{
user_id: req.user_id,