From 6dfcee3190a3fd510f6ff994e92f001166689be1 Mon Sep 17 00:00:00 2001 From: MathMan05 Date: Fri, 6 Feb 2026 23:20:28 -0600 Subject: [PATCH] allow tag modification --- src/api/routes/channels/#channel_id/tags.ts | 42 +++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/api/routes/channels/#channel_id/tags.ts b/src/api/routes/channels/#channel_id/tags.ts index 93769d662..a84e4b429 100644 --- a/src/api/routes/channels/#channel_id/tags.ts +++ b/src/api/routes/channels/#channel_id/tags.ts @@ -20,6 +20,7 @@ import { route } from "@spacebar/api"; import { Channel, ChannelUpdateEvent, emitEvent, Tag } from "@spacebar/util"; import { Request, Response, Router } from "express"; import { TagCreateSchema } from "@spacebar/schemas"; +import { HTTPError } from "#util/util/lambert-server"; const router: Router = Router({ mergeParams: true }); @@ -68,6 +69,47 @@ router.post( }, ); +router.put( + "/:tag_id", + route({ + requestBody: "TagCreateSchema", + permission: "MANAGE_CHANNELS", + responses: { + 200: { + body: "Channel", + }, + 404: {}, + }, + }), + async (req: Request, res: Response) => { + const body = req.body as TagCreateSchema; + const { channel_id, tag_id } = req.params as Record; + + const channel = await Channel.findOneOrFail({ + where: { id: channel_id }, + relations: ["available_tags"], + }); + + if (!channel.isForum()) throw new Error("is not thread only channel"); + + const tag = channel.available_tags?.find((tag) => tag.id == tag_id); + //TODO better error + if (!tag) throw new HTTPError("Tag not found"); + tag.assign(body); + + await Promise.all([ + tag.save(), + emitEvent({ + event: "CHANNEL_UPDATE", + data: channel.toJSON(), + channel_id, + } as ChannelUpdateEvent), + ]); + + res.json(channel.toJSON()); + }, +); + router.delete( "/:tag_id", route({