From 99d9bf563fb5e157600824776b149ca03cbea47c Mon Sep 17 00:00:00 2001 From: Puyodead1 Date: Sun, 10 Dec 2023 17:02:27 -0500 Subject: Start implementing webhooks --- src/api/routes/guilds/#guild_id/webhooks.ts | 35 ++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) (limited to 'src/api/routes/guilds/#guild_id/webhooks.ts') diff --git a/src/api/routes/guilds/#guild_id/webhooks.ts b/src/api/routes/guilds/#guild_id/webhooks.ts index d58659a4..a2ef7d69 100644 --- a/src/api/routes/guilds/#guild_id/webhooks.ts +++ b/src/api/routes/guilds/#guild_id/webhooks.ts @@ -16,12 +16,37 @@ along with this program. If not, see . */ -import { Router, Response, Request } from "express"; import { route } from "@spacebar/api"; +import { Webhook } from "@spacebar/util"; +import { Request, Response, Router } from "express"; const router = Router(); -//TODO: implement webhooks -router.get("/", route({}), async (req: Request, res: Response) => { - res.json([]); -}); +router.get( + "/", + route({ + description: + "Returns a list of guild webhook objects. Requires the MANAGE_WEBHOOKS permission.", + permission: "MANAGE_WEBHOOKS", + responses: { + 200: { + body: "APIWebhookArray", + }, + }, + }), + async (req: Request, res: Response) => { + const { guild_id } = req.params; + const webhooks = await Webhook.find({ + where: { guild_id }, + relations: [ + "user", + "guild", + "source_guild", + "application" /*"source_channel"*/, + ], + }); + + return res.json(webhooks); + }, +); + export default router; -- cgit 1.5.1