Skip to content

Commit

Permalink
[User profile][Duy] Return user's roles when getting profile
Browse files Browse the repository at this point in the history
  • Loading branch information
duykasama committed Mar 20, 2024
1 parent 5f0d952 commit 68cd404
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions Domus.Service/Implementations/UserService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,12 @@ public async Task<ServiceActionResult> GetSelfProfile(string token)
throw new InvalidTokenException();

var userId = _jwtService.GetTokenClaim(token, TokenClaimConstants.SUBJECT)?.ToString() ?? throw new UserNotFoundException();
var user = await _userManager.Users.Where(u => u.Id == userId)
.ProjectTo<DtoDomusUser>(_mapper.ConfigurationProvider)
.FirstOrDefaultAsync() ?? throw new UserNotFoundException();
var user = await _userRepository.GetAsync(u => u.Id == userId && !u.IsDeleted) ?? throw new UserNotFoundException();
var userRoles = await _userManager.GetRolesAsync(user);
var userDto = _mapper.Map<DtoDomusUserWithRole>(user);
userDto.Role = userRoles;

return new ServiceActionResult(true) { Data = user };
return new ServiceActionResult(true) { Data = userDto };
}

public async Task<ServiceActionResult> GetAllUsers()
Expand Down

0 comments on commit 68cd404

Please sign in to comment.