diff options
author | Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> | 2021-09-02 19:50:05 +0200 |
---|---|---|
committer | Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> | 2021-09-02 19:50:05 +0200 |
commit | d29ccaf623910eea90852fa28cd8ec191bd7afff (patch) | |
tree | 040af2cced2548560403efb72be4d026f41908f9 /api/src/routes/guilds/#guild_id | |
parent | :art: update openapi title (diff) | |
download | server-d29ccaf623910eea90852fa28cd8ec191bd7afff.tar.xz |
:sparkles: add user_id field to Member
Diffstat (limited to 'api/src/routes/guilds/#guild_id')
-rw-r--r-- | api/src/routes/guilds/#guild_id/index.ts | 4 | ||||
-rw-r--r-- | api/src/routes/guilds/#guild_id/members/#member_id/index.ts | 10 | ||||
-rw-r--r-- | api/src/routes/guilds/#guild_id/widget.json.ts | 2 |
3 files changed, 10 insertions, 6 deletions
diff --git a/api/src/routes/guilds/#guild_id/index.ts b/api/src/routes/guilds/#guild_id/index.ts index 6f55be3b..80b5c609 100644 --- a/api/src/routes/guilds/#guild_id/index.ts +++ b/api/src/routes/guilds/#guild_id/index.ts @@ -14,8 +14,8 @@ router.get("/", async (req: Request, res: Response) => { const [guild, member_count, member] = await Promise.all([ Guild.findOneOrFail({ id: guild_id }), - Member.count({ guild: { id: guild_id }, id: req.user_id }), - Member.findOneOrFail({ id: req.user_id }) + Member.count({ guild_id: guild_id, user_id: req.user_id }), + Member.findOneOrFail({ user_id: req.user_id }) ]); if (!member_count) throw new HTTPError("You are not a member of the guild you are trying to access", 401); diff --git a/api/src/routes/guilds/#guild_id/members/#member_id/index.ts b/api/src/routes/guilds/#guild_id/members/#member_id/index.ts index d9ce91c0..733a64c4 100644 --- a/api/src/routes/guilds/#guild_id/members/#member_id/index.ts +++ b/api/src/routes/guilds/#guild_id/members/#member_id/index.ts @@ -21,7 +21,7 @@ router.get("/", async (req: Request, res: Response) => { const { guild_id, member_id } = req.params; await Member.IsInGuildOrFail(req.user_id, guild_id); - const member = await Member.findOneOrFail({ id: member_id, guild_id }); + const member = await Member.findOneOrFail({ user_id: member_id, guild_id }); return res.json(member); }); @@ -29,13 +29,17 @@ router.get("/", async (req: Request, res: Response) => { router.patch("/", check(MemberChangeSchema), async (req: Request, res: Response) => { const { guild_id, member_id } = req.params; const body = req.body as MemberChangeSchema; + + const permission = await getPermission(req.user_id, guild_id); + if (body.roles) { const roles = await Role.find({ id: In(body.roles) }); if (body.roles.length !== roles.length) throw new HTTPError("Roles not found", 404); - // TODO: check if user has permission to add role + + permission.hasThrow("MANAGE_ROLES"); } - const member = await Member.findOneOrFail({ id: member_id, guild_id }); + const member = await Member.findOneOrFail({ user_id: member_id, guild_id }); member.assign(req.body); Promise.all([ diff --git a/api/src/routes/guilds/#guild_id/widget.json.ts b/api/src/routes/guilds/#guild_id/widget.json.ts index ae1f0599..193ed095 100644 --- a/api/src/routes/guilds/#guild_id/widget.json.ts +++ b/api/src/routes/guilds/#guild_id/widget.json.ts @@ -63,7 +63,7 @@ router.get("/", async (req: Request, res: Response) => { // Fetch members // TODO: Understand how Discord's max 100 random member sample works, and apply to here (see top of this file) - let members = await Member.find({ where: { guild_id: guild_id } }); + let members = await Member.find({ guild_id: guild_id }); // Construct object to respond with const data = { |