✨ Ensure profile created maintenance method
This commit is contained in:
parent
b0a616c17c
commit
2399bf0309
@ -428,4 +428,13 @@ public class AccountController(
|
||||
.Take(take)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
[HttpPost("/maintenance/ensureProfileCreated")]
|
||||
[Authorize]
|
||||
[RequiredPermission("maintenance", "accounts.profiles")]
|
||||
public async Task<ActionResult> EnsureProfileCreated()
|
||||
{
|
||||
await accounts.EnsureAccountProfileCreated();
|
||||
return Ok();
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@ using System.Globalization;
|
||||
using System.Reflection;
|
||||
using DysonNetwork.Sphere.Localization;
|
||||
using DysonNetwork.Sphere.Permission;
|
||||
using EFCore.BulkExtensions;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using Microsoft.Extensions.Localization;
|
||||
@ -48,4 +49,19 @@ public class AccountService(
|
||||
.FirstOrDefaultAsync();
|
||||
return profile?.Level;
|
||||
}
|
||||
|
||||
/// Maintenance methods for server administrator
|
||||
|
||||
public async Task EnsureAccountProfileCreated()
|
||||
{
|
||||
var accountsId = await db.Accounts.Select(a => a.Id).ToListAsync();
|
||||
var existingId = await db.AccountProfiles.Select(p => p.AccountId).ToListAsync();
|
||||
var missingId = accountsId.Except(existingId).ToList();
|
||||
|
||||
if (missingId.Count != 0)
|
||||
{
|
||||
var newProfiles = missingId.Select(id => new Profile { AccountId = id }).ToList();
|
||||
await db.BulkInsertAsync(newProfiles);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user