From 5c9af09e85ca0fa02b62580d8ac146f3ea05cf4d Mon Sep 17 00:00:00 2001 From: Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> Date: Sat, 4 Sep 2021 11:26:25 +0200 Subject: :bug: api member add roles -> make sure that roles exist --- .../routes/guilds/#guild_id/members/#member_id/index.ts | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'api/src/routes/guilds/#guild_id/members') 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 66c508a2..51bb010d 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 @@ -38,14 +38,13 @@ router.patch("/", check(MemberChangeSchema), async (req: Request, res: Response) member.roles = body.roles.map((x) => new Role({ id: x })); // foreign key constraint will fail if role doesn't exist } - Promise.all([ - member.save(), - emitEvent({ - event: "GUILD_MEMBER_UPDATE", - guild_id, - data: { ...member, roles: member.roles.map((x) => x.id) } - } as GuildMemberUpdateEvent) - ]); + await member.save(); + // do not use promise.all as we have to first write to db before emitting the event + await emitEvent({ + event: "GUILD_MEMBER_UPDATE", + guild_id, + data: { ...member, roles: member.roles.map((x) => x.id) } + } as GuildMemberUpdateEvent); res.json(member); }); -- cgit 1.4.1