deleting tags

This commit is contained in:
MathMan05
2026-02-05 11:15:16 -06:00
parent 00c77576f3
commit b7536c74c4
2 changed files with 48 additions and 0 deletions
@@ -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);
@@ -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;