mirror of
https://github.com/spacebarchat/server.git
synced 2024-11-11 13:14:06 +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: Get channel
|
||||
|
||||
router.delete("/", async (req, res) => {
|
||||
const { channel_id } = req.params
|
||||
router.get("/", async (req, res) => {
|
||||
const { channel_id } = req.params;
|
||||
|
||||
const channel = await ChannelModel.findOne({ id: channel_id }).exec();
|
||||
if (!channel) throw new HTTPError("Channel not found", 404);
|
||||
if (channel.guild_id) {
|
||||
|
||||
const permission = await getPermission(req.user_id, channel.guild_id)
|
||||
permission.hasThrow("MANAGE_CHANNELS")
|
||||
}
|
||||
const permission = await getPermission(req.user_id, channel.guild_id, channel_id);
|
||||
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
|
||||
|
||||
await emitEvent({ event: "CHANNEL_DELETE", data: channel, guild_id: channel_id, channel_id} as ChannelDeleteEvent);
|
||||
|
||||
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) => {
|
||||
var payload = req.body as ChannelModifySchema //new data
|
||||
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);
|
||||
var payload = req.body as ChannelModifySchema;
|
||||
const { channel_id } = req.params;
|
||||
|
||||
const permission = await getPermission(req.user_id, channel.guild_id, channel_id)
|
||||
permission.hasThrow("MANAGE_CHANNELS")
|
||||
channel = await ChannelModel.findOneAndUpdate({ id: channel_id }, payload).exec()
|
||||
if (!channel) throw new HTTPError("Channel not found", 404);
|
||||
const permission = await getPermission(req.user_id, undefined, channel_id);
|
||||
permission.hasThrow("MANAGE_CHANNELS");
|
||||
|
||||
//const data = toObject(channel);
|
||||
//TODO: Reload channel list if request successful
|
||||
const channel = await ChannelModel.findOneAndUpdate({ id: channel_id }, payload).exec();
|
||||
if (!channel) throw new HTTPError("Channel not found", 404);
|
||||
|
||||
await emitEvent({
|
||||
event: "CHANNEL_UPDATE",
|
||||
data: channel,
|
||||
data: toObject(channel),
|
||||
guild_id: channel.guild_id,
|
||||
} as ChannelUpdateEvent)
|
||||
channel_id,
|
||||
} as ChannelUpdateEvent);
|
||||
|
||||
res.send(toObject(channel));
|
||||
})
|
||||
});
|
||||
|
||||
export default router;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user