summary refs log tree commit diff
path: root/src/api
diff options
context:
space:
mode:
authorMathMan05 <mathmanrm@gmail.com>2026-02-05 11:15:16 -0600
committerMathMan05 <mathmanrm@gmail.com>2026-02-05 11:15:16 -0600
commitb7536c74c40c931f90e66786ac9dfbb76f77f985 (patch)
tree12282161e73259cf44215847ba0a95737f36c05b /src/api
parentanother type screw up (diff)
downloadserver-ts-b7536c74c40c931f90e66786ac9dfbb76f77f985.tar.xz
deleting tags
Diffstat (limited to 'src/api')
-rw-r--r--src/api/routes/channels/#channel_id/index.ts11
-rw-r--r--src/api/routes/channels/#channel_id/tags.ts37
2 files changed, 48 insertions, 0 deletions
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;