Skip to content

Commit

Permalink
fix (User) : remove jwt update after update user information (#106)
Browse files Browse the repository at this point in the history
* fix (User) : remove jwt update after update user information

* fix (Test) : fix tets
  • Loading branch information
mahdijafariii authored Sep 8, 2024
1 parent e899001 commit f842224
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,15 @@ public async Task UpdateUserInformationByAdminAsync(Guid id, UpdateAdminDto upda
{
throw new AdminProtectedException();
}

await ValidateUserInformation(user, updateAdminDto);
_validationService.EmailCheck(updateAdminDto.Email);
_validationService.PhoneNumberCheck(updateAdminDto.PhoneNumber);
await CheckExistenceOfRole(user,updateAdminDto);
await CheckExistenceOfRole(user, updateAdminDto);
await SetUpdatedInformation(user, updateAdminDto);
}

private async Task ValidateUserInformation(User user,UpdateAdminDto updateAdminDto)
private async Task ValidateUserInformation(User user, UpdateAdminDto updateAdminDto)
{
var checkUsername = await _userRepository.GetUserByUsernameAsync(updateAdminDto.UserName);
var checkEmail = await _userRepository.GetUserByEmailAsync(updateAdminDto.Email);
Expand All @@ -49,16 +50,14 @@ private async Task ValidateUserInformation(User user,UpdateAdminDto updateAdminD
throw new DuplicateUserException();
}

private async Task CheckExistenceOfRole(User user,UpdateAdminDto updateAdminDto)
private async Task CheckExistenceOfRole(User user, UpdateAdminDto updateAdminDto)
{
var role = await _roleRepository.GetRoleByNameAsync(updateAdminDto.RoleName);
if (role == null)
{
throw new RoleNotFoundException();
}

await SetUpdatedInformation(user, updateAdminDto);
await _jwtService.UpdateUserCookie(user.Username, false);
}

private async Task SetUpdatedInformation(User user, UpdateAdminDto updateAdminDto)
Expand All @@ -76,7 +75,7 @@ private async Task SetUpdatedInformation(User user, UpdateAdminDto updateAdminDt
user.RoleId = role.Id;
await _userRepository.UpdateUserAsync(user.Id, user);
}


public async Task<bool> DeleteUserAsync(Guid id)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,7 @@ await _userRepository
u.PhoneNumber == updateAdminDto.PhoneNumber &&
u.Role.RoleName == updateAdminDto.RoleName
));

await _jwtService
.Received()
.UpdateUserCookie(updateAdminDto.UserName, false);

}

[Fact]
Expand Down

0 comments on commit f842224

Please sign in to comment.