diff options
Diffstat (limited to 'src/util/entities/Member.ts')
-rw-r--r-- | src/util/entities/Member.ts | 39 |
1 files changed, 28 insertions, 11 deletions
diff --git a/src/util/entities/Member.ts b/src/util/entities/Member.ts index 13e74dcd..8c208202 100644 --- a/src/util/entities/Member.ts +++ b/src/util/entities/Member.ts @@ -260,9 +260,9 @@ export class Member extends BaseClassWithoutId { }, }, }), - await Role.findOneOrFail({ where: { id: role_id, guild_id } }), + Role.findOneOrFail({ where: { id: role_id, guild_id } }), ]); - member.roles = member.roles.filter((x) => x.id == role_id); + member.roles = member.roles.filter((x) => x.id !== role_id); await Promise.all([ member.save(), @@ -330,17 +330,25 @@ export class Member extends BaseClassWithoutId { }); const memberCount = await Member.count({ where: { guild_id } }); - const memberPreview = await Member.find({ - where: { - guild_id, - user: { - sessions: { - status: Not("invisible" as const), // lol typescript? + + const memberPreview = ( + await Member.find({ + where: { + guild_id, + user: { + sessions: { + status: Not("invisible" as const), // lol typescript? + }, }, }, - }, - take: 10, - }); + relations: ["user", "roles"], + take: 10, + }) + ).map((member) => ({ + ...member.toPublicMember(), + user: member.user.toPublicUser(), + roles: member.roles.map((x) => x.id), + })); if ( await Member.count({ @@ -440,6 +448,15 @@ export class Member extends BaseClassWithoutId { ]); } } + + toPublicMember() { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const member: any = {}; + PublicMemberProjection.forEach((x) => { + member[x] = this[x]; + }); + return member as PublicMember; + } } export interface ChannelOverride { |