mirror of
https://github.com/spacebarchat/server.git
synced 2026-05-14 20:35:17 +00:00
deleting tags
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user