Skip to content

Commit

Permalink
Update name in user profile
Browse files Browse the repository at this point in the history
  • Loading branch information
evanlihou committed Jun 3, 2024
1 parent 1e88738 commit e9123c7
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions FiMAdminApi/Controllers/UsersController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public async Task<ActionResult> GetUser(string id)
}

[HttpPut("{id:guid}")]
public async Task<ActionResult> UpdateUser(string id, [FromBody] UpdateRolesRequest request)
public async Task<ActionResult> UpdateUser(Guid id, [FromBody] UpdateRolesRequest request)
{
var update = new FixedAdminUserAttributes();
if (request.NewRoles is not null)
Expand All @@ -129,12 +129,28 @@ public async Task<ActionResult> UpdateUser(string id, [FromBody] UpdateRolesRequ
update.Role = request.NewRoles.Contains(GlobalRole.Superuser) ? "service_role" : "authenticated";
}
if (request.Name is not null)
{
update.UserMetadata = new Dictionary<string, object>
{
{ "name", request.Name }
};

var profile = await dbContext.Profiles.FindAsync(id);
if (profile is null)
{
profile = new Profile()
{
Id = id
};
await dbContext.Profiles.AddAsync(profile);
}

profile.Name = request.Name;

await dbContext.SaveChangesAsync();
}

await adminClient.UpdateUserById(id, update);
await adminClient.UpdateUserById(id.ToString(), update);

return Ok();
}
Expand Down

0 comments on commit e9123c7

Please sign in to comment.