Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: team page member sort #852

Merged
merged 2 commits into from
Jan 12, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 1 addition & 12 deletions backend/src/modules/teams/repositories/team.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,7 @@ export class TeamRepository
}

getTeam(teamId: string): Promise<Team> {
return this.findOneById(
teamId,
{ _id: 1, name: 1 },
{
path: 'users',
select: 'user role isNewJoiner',
populate: {
path: 'user',
select: '_id firstName lastName email joinedAt providerAccountCreatedAt'
}
}
);
return this.findOneById(teamId, { _id: 1, name: 1 });
}

getTeamsWithUsers(teamIds: string[]): Promise<Team[]> {
Expand Down
20 changes: 18 additions & 2 deletions backend/src/modules/teams/services/get.team.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,24 @@ export default class GetTeamService implements GetTeamServiceInterface {
return this.teamRepository.countDocuments();
}

getTeam(teamId: string) {
return this.teamRepository.getTeam(teamId);
async getTeam(teamId: string) {
const team = await this.teamRepository.getTeam(teamId);
const users = await this.teamUserRepository.getUsersOfTeam(teamId);
jpvsalvador marked this conversation as resolved.
Show resolved Hide resolved

users.sort((a, b) => {
const fullNameA = `${a.user.firstName.toLowerCase()} ${a.user.lastName.toLowerCase()}`;
const fullNameB = `${b.user.firstName.toLowerCase()} ${b.user.lastName.toLowerCase()}`;

return fullNameA < fullNameB ? -1 : 1;
});

const teamWithUsers = {
_id: team._id,
name: team.name,
users
};

return teamWithUsers;
jpvsalvador marked this conversation as resolved.
Show resolved Hide resolved
}

async getTeamsOfUser(userId: string) {
Expand Down