fix(backend): return last_sid_reroll in API, update last sid reroll + last active correctly

This commit is contained in:
sam 2024-09-26 17:09:27 +02:00
parent b5f9ef9bd6
commit e83895255e
Signed by: sam
GPG key ID: B4EF20DDE721CAA1
3 changed files with 17 additions and 6 deletions

View file

@ -225,10 +225,12 @@ public class UsersController(
if (CurrentUser!.LastSidReroll > minTimeAgo)
throw new ApiError.BadRequest("Cannot reroll short ID yet");
// Using ExecuteUpdateAsync here as the new short ID is generated by the database
await db.Users.Where(u => u.Id == CurrentUser.Id)
.ExecuteUpdateAsync(s => s
.SetProperty(u => u.Sid, _ => db.FindFreeUserSid())
.SetProperty(u => u.LastSidReroll, _ => clock.GetCurrentInstant()));
.SetProperty(u => u.LastSidReroll, clock.GetCurrentInstant())
.SetProperty(u => u.LastActive, clock.GetCurrentInstant()));
var user = await db.ResolveUserAsync(CurrentUser.Id);
return Ok(await userRenderer.RenderUserAsync(user, CurrentUser, CurrentToken, renderMembers: false));