From 0bba59383b70728423bfa2a39bc1a58e1f457329 Mon Sep 17 00:00:00 2001 From: Mathias Wagner Date: Sun, 12 Nov 2023 18:28:16 +0100 Subject: [PATCH] Updated the channel.ts routes --- api/routes/channels.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/api/routes/channels.ts b/api/routes/channels.ts index 247fea3..ca2fc9f 100644 --- a/api/routes/channels.ts +++ b/api/routes/channels.ts @@ -7,6 +7,11 @@ import {patchChannel} from "../validations/channelValidation"; const app = Router(); +/** + * Check if the channel exists and if the user can edit it + * @param req AuthenticatedRequest + * @param res Response + */ const checkChannel = async (req: AuthenticatedRequest, res: Response) => { if (!req.params.channelId) { res.status(400).json({message: "Missing channelId parameter"}); @@ -28,13 +33,11 @@ const checkChannel = async (req: AuthenticatedRequest, res: Response) => { return channel; } -app.get("/", async (req: AuthenticatedRequest, res: Response) => { - if (!req.query.guildId) - return res.status(400).json({message: "Missing guildId query parameter"}); - if (!await canEditGuild(req.user.refreshDate!, req.user.refreshToken, req.user.accessToken, req.query.guildId as string)) +app.get("/:guildId", async (req: AuthenticatedRequest, res: Response) => { + if (!await canEditGuild(req.user.refreshDate!, req.user.refreshToken, req.user.accessToken, req.params.guildId as string)) return res.status(403).json({message: "You are not allowed to edit this guild"}); - res.json((await listChannels(req.query.guildId as string)).map(channel => ({ + res.json((await listChannels(req.params.guildId as string)).map(channel => ({ ...channel.dataValues, id: undefined, webhookToken: undefined, guildId: undefined })));