diff --git a/src/api/routes/channels/#channel_id/index.ts b/src/api/routes/channels/#channel_id/index.ts
index e8c6ecfb..a73e795a 100644
--- a/src/api/routes/channels/#channel_id/index.ts
+++ b/src/api/routes/channels/#channel_id/index.ts
@@ -150,6 +150,7 @@ router.patch(
const { channel_id } = req.params as { [key: string]: string };
const channel = await Channel.findOneOrFail({
where: { id: channel_id },
+ relations: payload.available_tags ? ["available_tags"] : [],
});
if (channel.isThread()) {
@@ -164,6 +165,16 @@ router.patch(
req.permission!.hasThrow("MANAGE_CHANNELS");
}
+ if (payload.available_tags) {
+ if (channel.isForum() && channel.available_tags) {
+ //TODO maybe error if this fails, and maybe handle creating tags?
+ const filter = new Set(payload.available_tags.map(({ id }) => id));
+ const tags = channel.available_tags.filter((_) => !filter.has(_.id));
+ tags.forEach((_) => _.remove());
+ channel.available_tags = channel.available_tags.filter((_) => filter.has(_.id));
+ }
+ }
+
if (payload.icon) payload.icon = await handleFile(`/channel-icons/${channel_id}`, payload.icon);
channel.assign(payload);
diff --git a/src/api/routes/channels/#channel_id/tags.ts b/src/api/routes/channels/#channel_id/tags.ts
index c600752d..d6c07e54 100644
--- a/src/api/routes/channels/#channel_id/tags.ts
+++ b/src/api/routes/channels/#channel_id/tags.ts
@@ -66,4 +66,41 @@ router.post(
},
);
+router.delete(
+ "/:tag_id",
+ route({
+ permission: "MANAGE_CHANNELS",
+ responses: {
+ 201: {},
+ 404: {},
+ },
+ }),
+ async (req: Request, res: Response) => {
+ const { channel_id, tag_id } = req.params as Record<string, string>;
+
+ 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 = await Tag.findOneByOrFail({
+ id: tag_id,
+ });
+ channel.available_tags = channel.available_tags?.filter((t) => t.id !== tag.id);
+
+ await Promise.all([
+ tag.remove(),
+ emitEvent({
+ event: "CHANNEL_UPDATE",
+ data: channel.toJSON(),
+ channel_id,
+ } as ChannelUpdateEvent),
+ ]);
+
+ res.json(channel.toJSON());
+ },
+);
+
export default router;
|