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 | |
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')
-rw-r--r-- | src/api/routes/guilds/#guild_id/members/#member_id/index.ts | 25 | ||||
-rw-r--r-- | src/util/schemas/responses/TypedResponses.ts | 2 |
2 files changed, 25 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), + }); }, ); diff --git a/src/util/schemas/responses/TypedResponses.ts b/src/util/schemas/responses/TypedResponses.ts index 099efba3..4349b93c 100644 --- a/src/util/schemas/responses/TypedResponses.ts +++ b/src/util/schemas/responses/TypedResponses.ts @@ -11,6 +11,7 @@ import { Member, Message, PrivateUser, + PublicMember, PublicUser, Role, Sticker, @@ -68,6 +69,7 @@ export type APIChannelArray = Channel[]; export type APIEmojiArray = Emoji[]; export type APIMemberArray = Member[]; +export type APIPublicMember = PublicMember; export interface APIGuildWithJoinedAt extends Guild { joined_at: string; |