summary refs log tree commit diff
path: root/api/src
diff options
context:
space:
mode:
authorFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-09-04 11:26:25 +0200
committerFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-09-04 11:26:25 +0200
commit5c9af09e85ca0fa02b62580d8ac146f3ea05cf4d (patch)
treede908b2ebbfe172f1f5eba92530e467056308164 /api/src
parent:bug: fix ready members payload (diff)
downloadserver-5c9af09e85ca0fa02b62580d8ac146f3ea05cf4d.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.ts15
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);
 });