mirror of
https://github.com/spacebarchat/server.git
synced 2024-11-13 14:12:41 +01:00
✨ Channel get Route
This commit is contained in:
parent
0eb6c994ae
commit
5e9fb8a2a2
@ -8,54 +8,53 @@ const router: Router = Router();
|
|||||||
// TODO: delete channel
|
// TODO: delete channel
|
||||||
// TODO: Get channel
|
// TODO: Get channel
|
||||||
|
|
||||||
router.delete("/", async (req, res) => {
|
router.get("/", async (req, res) => {
|
||||||
const { channel_id } = req.params
|
const { channel_id } = req.params;
|
||||||
|
|
||||||
const channel = await ChannelModel.findOne({ id: channel_id }).exec();
|
const channel = await ChannelModel.findOne({ id: channel_id }).exec();
|
||||||
if (!channel) throw new HTTPError("Channel not found", 404);
|
if (!channel) throw new HTTPError("Channel not found", 404);
|
||||||
if (channel.guild_id) {
|
|
||||||
|
|
||||||
const permission = await getPermission(req.user_id, channel.guild_id)
|
const permission = await getPermission(req.user_id, channel.guild_id, channel_id);
|
||||||
permission.hasThrow("MANAGE_CHANNELS")
|
permission.hasThrow("VIEW_CHANNEL");
|
||||||
}
|
|
||||||
|
|
||||||
// TODO Channel Update Gateway event will fire for each of them
|
return res.send(toObject(channel));
|
||||||
|
});
|
||||||
|
|
||||||
await ChannelModel.deleteOne({ id: channel_id })
|
router.delete("/", async (req, res) => {
|
||||||
|
const { channel_id } = req.params;
|
||||||
|
|
||||||
|
const channel = await ChannelModel.findOne({ id: channel_id }).exec();
|
||||||
|
const permission = await getPermission(req.user_id, channel?.guild_id, channel_id, { channel });
|
||||||
|
permission.hasThrow("MANAGE_CHANNELS");
|
||||||
|
|
||||||
|
await ChannelModel.deleteOne({ id: channel_id });
|
||||||
|
|
||||||
// TODO: Dm channel "close" not delete
|
// TODO: Dm channel "close" not delete
|
||||||
|
|
||||||
await emitEvent({ event: "CHANNEL_DELETE", data: channel, guild_id: channel_id, channel_id} as ChannelDeleteEvent);
|
|
||||||
|
|
||||||
const data = toObject(channel);
|
const data = toObject(channel);
|
||||||
//TODO: Reload channel list if request successful
|
|
||||||
res.send(data)
|
|
||||||
})
|
|
||||||
|
|
||||||
// should be good now
|
await emitEvent({ event: "CHANNEL_DELETE", data, guild_id: channel?.guild_id, channel_id } as ChannelDeleteEvent);
|
||||||
|
|
||||||
|
res.send(data);
|
||||||
|
});
|
||||||
|
|
||||||
router.patch("/", check(ChannelModifySchema), async (req, res) => {
|
router.patch("/", check(ChannelModifySchema), async (req, res) => {
|
||||||
var payload = req.body as ChannelModifySchema //new data
|
var payload = req.body as ChannelModifySchema;
|
||||||
const { channel_id } = req.params
|
const { channel_id } = req.params;
|
||||||
var channel = await ChannelModel.findOne({ id: channel_id }, { guild_id: true }).exec();
|
|
||||||
if (!channel) throw new HTTPError("Channel not found", 404);
|
|
||||||
|
|
||||||
const permission = await getPermission(req.user_id, channel.guild_id, channel_id)
|
const permission = await getPermission(req.user_id, undefined, channel_id);
|
||||||
permission.hasThrow("MANAGE_CHANNELS")
|
permission.hasThrow("MANAGE_CHANNELS");
|
||||||
channel = await ChannelModel.findOneAndUpdate({ id: channel_id }, payload).exec()
|
|
||||||
if (!channel) throw new HTTPError("Channel not found", 404);
|
|
||||||
|
|
||||||
//const data = toObject(channel);
|
const channel = await ChannelModel.findOneAndUpdate({ id: channel_id }, payload).exec();
|
||||||
//TODO: Reload channel list if request successful
|
if (!channel) throw new HTTPError("Channel not found", 404);
|
||||||
|
|
||||||
await emitEvent({
|
await emitEvent({
|
||||||
event: "CHANNEL_UPDATE",
|
event: "CHANNEL_UPDATE",
|
||||||
data: channel,
|
data: toObject(channel),
|
||||||
guild_id: channel.guild_id,
|
guild_id: channel.guild_id,
|
||||||
} as ChannelUpdateEvent)
|
channel_id,
|
||||||
|
} as ChannelUpdateEvent);
|
||||||
|
|
||||||
res.send(toObject(channel));
|
res.send(toObject(channel));
|
||||||
})
|
});
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user