diff options
author | Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> | 2021-09-04 11:26:25 +0200 |
---|---|---|
committer | Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> | 2021-09-04 11:26:25 +0200 |
commit | cc9f43fb63260c7ae345ae4ddacbcabc3dbcf0ac (patch) | |
tree | 1c637a5693c8f072499ea2bb9ed473f76d5bc32e /api/src | |
parent | :bug: fix ready members payload (diff) | |
download | server-cc9f43fb63260c7ae345ae4ddacbcabc3dbcf0ac.tar.xz |
:bug: api member add roles -> make sure that roles exist
Diffstat (limited to 'api/src')
-rw-r--r-- | api/src/routes/guilds/#guild_id/members/#member_id/index.ts | 15 |
1 files changed, 7 insertions, 8 deletions
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); }); |