diff options
author | Madeline <46743919+MaddyUnderStars@users.noreply.github.com> | 2023-06-11 00:27:38 +1000 |
---|---|---|
committer | Madeline <46743919+MaddyUnderStars@users.noreply.github.com> | 2023-06-11 00:27:38 +1000 |
commit | 6e47b8e0b345ed064b5bdd8e16bd4d48ca9c9cd8 (patch) | |
tree | 2b92ed44e855160b2e580b0db57ad8de473a20e3 /src/api | |
parent | Return entire guild object in POST /guilds (diff) | |
download | server-6e47b8e0b345ed064b5bdd8e16bd4d48ca9c9cd8.tar.xz |
Send user and roles id array in GET /guilds/:id/members/:id
Diffstat (limited to 'src/api')
-rw-r--r-- | src/api/routes/guilds/#guild_id/members/#member_id/index.ts | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/src/api/routes/guilds/#guild_id/members/#member_id/index.ts b/src/api/routes/guilds/#guild_id/members/#member_id/index.ts index 5f1f6fa7..cafb922e 100644 --- a/src/api/routes/guilds/#guild_id/members/#member_id/index.ts +++ b/src/api/routes/guilds/#guild_id/members/#member_id/index.ts @@ -27,6 +27,8 @@ import { handleFile, Member, MemberChangeSchema, + PublicMemberProjection, + PublicUserProjection, Role, Sticker, } from "@spacebar/util"; @@ -39,7 +41,7 @@ router.get( route({ responses: { 200: { - body: "Member", + body: "APIPublicMember", }, 403: { body: "APIErrorResponse", @@ -55,9 +57,28 @@ router.get( const member = await Member.findOneOrFail({ where: { id: member_id, guild_id }, + relations: ["roles", "user"], + select: { + index: true, + // only grab public member props + ...Object.fromEntries( + PublicMemberProjection.map((x) => [x, true]), + ), + // and public user props + user: Object.fromEntries( + PublicUserProjection.map((x) => [x, true]), + ), + roles: { + id: true, + }, + }, }); - return res.json(member); + return res.json({ + ...member.toPublicMember(), + user: member.user.toPublicUser(), + roles: member.roles.map((x) => x.id), + }); }, ); |