Skip to content

Commit

Permalink
[REFACTOR]: add getUsername func and fix error
Browse files Browse the repository at this point in the history
  • Loading branch information
Behzad-rabiei committed Aug 16, 2023
1 parent a2b17e7 commit 13b9f0a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/controllers/memberActivity.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ const activeMembersCompositionTable = catchAsync(async function (req: IAuthReque
guildMember.roles = roleService.getRolesForGuildMember(guildMember, roles);
guildMember.ngu = guildMemberService.getNgu(guildMember);
guildMember.activityComposition = memberActivityService.getActivityComposition(guildMember, memberActivity, filter.activityComposition);
guildMember.username = guildMember.discriminator === "0" ? guildMember.username : guildMember.username + "#" + guildMember.discriminator;
guildMember.username = guildMemberService.getUsername(guildMember);
});
}
await closeConnection(connection)
Expand All @@ -127,7 +127,7 @@ const activeMembersOnboardingTable = catchAsync(async function (req: IAuthReques
guildMember.roles = roleService.getRolesForGuildMember(guildMember, roles);
guildMember.ngu = guildMemberService.getNgu(guildMember);
guildMember.activityComposition = memberActivityService.getActivityComposition(guildMember, memberActivity, filter.activityComposition);
guildMember.username = guildMember.discriminator === "0" ? guildMember.username : guildMember.username + "#" + guildMember.discriminator;
guildMember.username = guildMemberService.getUsername(guildMember);
});
}
await closeConnection(connection)
Expand All @@ -150,7 +150,7 @@ const disengagedMembersCompositionTable = catchAsync(async function (req: IAuthR
guildMember.roles = roleService.getRolesForGuildMember(guildMember, roles);
guildMember.ngu = guildMemberService.getNgu(guildMember);
guildMember.activityComposition = memberActivityService.getActivityComposition(guildMember, memberActivity, filter.activityComposition);
guildMember.username = guildMember.discriminator === "0" ? guildMember.username : guildMember.username + "#" + guildMember.discriminator;
guildMember.username = guildMemberService.getUsername(guildMember);
});
}
await closeConnection(connection)
Expand Down
13 changes: 12 additions & 1 deletion src/services/guildMember.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,16 @@ function getNgu(guildMember: IGuildMember): string {
}
}

/**
* Determines the username based on discriminator.
* @param {IGuildMember} guildMember - The guild member for which the ngu needs to be determined.
* @returns {string} - The determined username for guild member.
*/
function getUsername(guildMember: IGuildMember): string {
return guildMember.discriminator === "0" ? guildMember.username : guildMember.username + "#" + guildMember.discriminator;

}


/**
* Get a guild member from the database based on the filter criteria.
Expand All @@ -163,6 +173,7 @@ async function getGuildMember(connection: Connection, filter: object): Promise<I
export default {
queryGuildMembers,
getGuildMember,
getNgu
getNgu,
getUsername
}

3 changes: 1 addition & 2 deletions src/services/role.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Connection } from 'mongoose';
import { IRole } from '@togethercrew.dev/db';
import { IGuildMember } from 'tc_dbcomm';
import { IRole, IGuildMember } from '@togethercrew.dev/db';

/**
* Get a role from the database based on the filter criteria.
Expand Down

0 comments on commit 13b9f0a

Please sign in to comment.