From 13b9f0aac0ac7069ff89409c8093bb82ef1b9d6a Mon Sep 17 00:00:00 2001 From: Behzad Rabiei <53224485+Behzad-rabiei@users.noreply.github.com> Date: Wed, 16 Aug 2023 14:05:37 +0400 Subject: [PATCH] [REFACTOR]: add getUsername func and fix error --- src/controllers/memberActivity.controller.ts | 6 +++--- src/services/guildMember.service.ts | 13 ++++++++++++- src/services/role.service.ts | 3 +-- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/controllers/memberActivity.controller.ts b/src/controllers/memberActivity.controller.ts index ab1ee5bd..5481248f 100644 --- a/src/controllers/memberActivity.controller.ts +++ b/src/controllers/memberActivity.controller.ts @@ -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) @@ -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) @@ -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) diff --git a/src/services/guildMember.service.ts b/src/services/guildMember.service.ts index 5b6622f6..8731e123 100644 --- a/src/services/guildMember.service.ts +++ b/src/services/guildMember.service.ts @@ -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. @@ -163,6 +173,7 @@ async function getGuildMember(connection: Connection, filter: object): Promise