diff options
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; |