Updated the channel.ts routes
This commit is contained in:
parent
84494849f8
commit
0bba59383b
@ -7,6 +7,11 @@ import {patchChannel} from "../validations/channelValidation";
|
||||
|
||||
const app = Router();
|
||||
|
||||
/**
|
||||
* Check if the channel exists and if the user can edit it
|
||||
* @param req AuthenticatedRequest
|
||||
* @param res Response
|
||||
*/
|
||||
const checkChannel = async (req: AuthenticatedRequest, res: Response) => {
|
||||
if (!req.params.channelId) {
|
||||
res.status(400).json({message: "Missing channelId parameter"});
|
||||
@ -28,13 +33,11 @@ const checkChannel = async (req: AuthenticatedRequest, res: Response) => {
|
||||
return channel;
|
||||
}
|
||||
|
||||
app.get("/", async (req: AuthenticatedRequest, res: Response) => {
|
||||
if (!req.query.guildId)
|
||||
return res.status(400).json({message: "Missing guildId query parameter"});
|
||||
if (!await canEditGuild(req.user.refreshDate!, req.user.refreshToken, req.user.accessToken, req.query.guildId as string))
|
||||
app.get("/:guildId", async (req: AuthenticatedRequest, res: Response) => {
|
||||
if (!await canEditGuild(req.user.refreshDate!, req.user.refreshToken, req.user.accessToken, req.params.guildId as string))
|
||||
return res.status(403).json({message: "You are not allowed to edit this guild"});
|
||||
|
||||
res.json((await listChannels(req.query.guildId as string)).map(channel => ({
|
||||
res.json((await listChannels(req.params.guildId as string)).map(channel => ({
|
||||
...channel.dataValues,
|
||||
id: undefined, webhookToken: undefined, guildId: undefined
|
||||
})));
|
||||
|
Loading…
x
Reference in New Issue
Block a user