1
0
mirror of https://github.com/spacebarchat/server.git synced 2024-11-11 05:02:37 +01:00

finished /invite route #21

This commit is contained in:
xnacly 2021-04-08 17:53:57 +02:00
parent 3252e91f6b
commit 5a0351aa05

View File

@ -1,4 +1,28 @@
import { Router } from "express";
import { Router, Request, Response } from "express";
import { getPermission, InviteModel, toObject } from "fosscord-server-util";
import { HTTPError } from "lambert-server";
const router: Router = Router();
router.get("/:invite_code", async (req: Request, res: Response) => {
const { invite_code: code } = req.params;
const invite = await InviteModel.findOne({ code }).exec();
if (!invite) throw new HTTPError("Unknown Invite", 404);
res.status(200).send({ invite: toObject(invite) });
});
router.delete("/:invite_code", async (req: Request, res: Response) => {
const { invite_code: code } = req.params;
const invite = await InviteModel.findOne({ code }).exec();
if (!invite) throw new HTTPError("Unknown Invite", 404);
const { guild_id, channel_id } = invite;
const perms = await getPermission(req.user_id, guild_id, channel_id);
if (!perms.has("MANAGE_GUILD") || !perms.has("MANAGE_CHANNELS")) throw new HTTPError("You aren't allow", 401);
res.status(200).send({ invite: toObject(invite) });
});
export default router;