Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor patches to handle irregular database state #36

Merged
merged 3 commits into from
Jun 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Gameboard.Api/Features/Challenge/ChallengeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@ public async Task<ChallengeSummary[]> List(SearchFilter model)
{
var q = Store.List(model.Term);

// filter out challenge records with no state used to give starting score to player
q = q.Where(p => p.Name != "_initialscore_" && p.State != null);

q = q.OrderByDescending(p => p.LastSyncTime);

q = q.Skip(model.Skip);
Expand Down
16 changes: 13 additions & 3 deletions src/Gameboard.Api/Features/Player/PlayerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,16 +176,26 @@ public async Task<Player> Delete(string id, bool sudo = false)
.ToArrayAsync()
;
}
var toArchive = Mapper.Map<ArchivedChallenge[]>(challenges);
if (toArchive.Length > 0)

if (challenges.Count > 0)
{
var toArchive = Mapper.Map<ArchivedChallenge[]>(challenges);
var teamMembers = players.Select(a => a.UserId).ToArray();
foreach (var challenge in toArchive)
{
challenge.Submissions = (await Mojo.AuditChallengeAsync(challenge.Id)).ToArray();
// gamespace may be deleted in TopoMojo which would cause error and prevent reset
try
{
challenge.Submissions = (await Mojo.AuditChallengeAsync(challenge.Id)).ToArray();
}
catch
{
challenge.Submissions = new SectionSubmission[] {};
}
challenge.TeamMembers = teamMembers;
}
Store.DbContext.ArchivedChallenges.AddRange(Mapper.Map<Data.ArchivedChallenge[]>(toArchive));
await Store.DbContext.SaveChangesAsync();
}

// courtesy call; ignore error (gamespace may have already been removed from backend)
Expand Down