fix(backend): return last_sid_reroll in API, update last sid reroll + last active correctly
This commit is contained in:
parent
b5f9ef9bd6
commit
e83895255e
3 changed files with 17 additions and 6 deletions
|
@ -128,13 +128,18 @@ public class MembersController(
|
||||||
if (CurrentUser!.LastSidReroll > minTimeAgo)
|
if (CurrentUser!.LastSidReroll > minTimeAgo)
|
||||||
throw new ApiError.BadRequest("Cannot reroll short ID yet");
|
throw new ApiError.BadRequest("Cannot reroll short ID yet");
|
||||||
|
|
||||||
|
// Using ExecuteUpdateAsync here as the new short ID is generated by the database
|
||||||
await db.Members.Where(m => m.Id == member.Id)
|
await db.Members.Where(m => m.Id == member.Id)
|
||||||
.ExecuteUpdateAsync(s => s
|
.ExecuteUpdateAsync(s => s
|
||||||
.SetProperty(m => m.Sid, _ => db.FindFreeMemberSid()));
|
.SetProperty(m => m.Sid, _ => db.FindFreeMemberSid()));
|
||||||
|
|
||||||
// Re-fetch member so we can be sure the sid is correct
|
await db.Users.Where(u => u.Id == CurrentUser.Id)
|
||||||
var updatedMember = await db.ResolveMemberAsync(CurrentUser!.Id, memberRef);
|
.ExecuteUpdateAsync(s => s
|
||||||
|
.SetProperty(u => u.LastSidReroll, clock.GetCurrentInstant())
|
||||||
|
.SetProperty(u => u.LastActive, clock.GetCurrentInstant()));
|
||||||
|
|
||||||
|
// Re-fetch member to fetch the new sid
|
||||||
|
var updatedMember = await db.ResolveMemberAsync(CurrentUser!.Id, memberRef);
|
||||||
return Ok(memberRenderer.RenderMember(updatedMember, CurrentToken));
|
return Ok(memberRenderer.RenderMember(updatedMember, CurrentToken));
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -225,10 +225,12 @@ public class UsersController(
|
||||||
if (CurrentUser!.LastSidReroll > minTimeAgo)
|
if (CurrentUser!.LastSidReroll > minTimeAgo)
|
||||||
throw new ApiError.BadRequest("Cannot reroll short ID yet");
|
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)
|
await db.Users.Where(u => u.Id == CurrentUser.Id)
|
||||||
.ExecuteUpdateAsync(s => s
|
.ExecuteUpdateAsync(s => s
|
||||||
.SetProperty(u => u.Sid, _ => db.FindFreeUserSid())
|
.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);
|
var user = await db.ResolveUserAsync(CurrentUser.Id);
|
||||||
return Ok(await userRenderer.RenderUserAsync(user, CurrentUser, CurrentToken, renderMembers: false));
|
return Ok(await userRenderer.RenderUserAsync(user, CurrentUser, CurrentToken, renderMembers: false));
|
||||||
|
|
|
@ -37,7 +37,8 @@ public class UserRendererService(DatabaseContext db, MemberRendererService membe
|
||||||
: [];
|
: [];
|
||||||
|
|
||||||
return new UserResponse(
|
return new UserResponse(
|
||||||
user.Id, user.Sid, user.Username, user.DisplayName, user.Bio, user.MemberTitle, AvatarUrlFor(user), user.Links,
|
user.Id, user.Sid, user.Username, user.DisplayName, user.Bio, user.MemberTitle, AvatarUrlFor(user),
|
||||||
|
user.Links,
|
||||||
user.Names, user.Pronouns, user.Fields, user.CustomPreferences,
|
user.Names, user.Pronouns, user.Fields, user.CustomPreferences,
|
||||||
renderMembers ? members.Select(m => memberRenderer.RenderPartialMember(m, tokenHidden)) : null,
|
renderMembers ? members.Select(m => memberRenderer.RenderPartialMember(m, tokenHidden)) : null,
|
||||||
renderAuthMethods
|
renderAuthMethods
|
||||||
|
@ -47,7 +48,8 @@ public class UserRendererService(DatabaseContext db, MemberRendererService membe
|
||||||
))
|
))
|
||||||
: null,
|
: null,
|
||||||
tokenHidden ? user.ListHidden : null,
|
tokenHidden ? user.ListHidden : null,
|
||||||
tokenHidden ? user.LastActive : null
|
tokenHidden ? user.LastActive : null,
|
||||||
|
tokenHidden ? user.LastSidReroll : null
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,7 +79,9 @@ public class UserRendererService(DatabaseContext db, MemberRendererService membe
|
||||||
[property: JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
|
[property: JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
|
||||||
bool? MemberListHidden,
|
bool? MemberListHidden,
|
||||||
[property: JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
|
[property: JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
|
||||||
Instant? LastActive
|
Instant? LastActive,
|
||||||
|
[property: JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
|
||||||
|
Instant? LastSidReroll
|
||||||
);
|
);
|
||||||
|
|
||||||
public record AuthenticationMethodResponse(
|
public record AuthenticationMethodResponse(
|
||||||
|
|
Loading…
Reference in a new issue