This commit is contained in:
2020-06-15 19:43:52 +00:00
parent 59f4c6a9d2
commit 57e24cc7d9
2 changed files with 28 additions and 2 deletions

View File

@@ -70,6 +70,26 @@ namespace AyaNova.Api.Controllers
return Ok(ApiOkResponse.Response(ret));
}
/// <summary>
/// Get DB Emptiness
/// </summary>
/// <returns>Checks if there is any data in critical tables only</returns>
[HttpGet("database-empty")]
public async Task<IActionResult> GetDbEmpty()
{
if (serverState.IsClosed)
{
//Exception for SuperUser account to handle licensing issues
if (UserIdFromContext.Id(HttpContext.Items) != 1)
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
}
if (!Authorized.HasReadFullRole(HttpContext.Items, AyaType.License))
{
return StatusCode(403, new ApiNotAuthorizedResponse());
}
return Ok(ApiOkResponse.Response(await AyaNova.Util.DbUtil.DBIsEmptyAsync(ct, log)));
}
@@ -111,7 +131,7 @@ namespace AyaNova.Api.Controllers
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserIdFromContext.Id(HttpContext.Items), 0, AyaType.License, AyaEvent.LicenseFetch), ct);
}
else
{
{
log.LogError($"LicenseController::FetchLicense - failed: {ret}");
}

View File

@@ -401,7 +401,13 @@ namespace AyaNova.Util
if (await ct.WorkOrder.AnyAsync()) return false;
if (await ct.Quote.AnyAsync()) return false;
if (await ct.PM.AnyAsync()) return false;
if (await ct.Unit.AnyAsync()) return false;
if (await ct.HeadOffice.AnyAsync()) return false;
if (await ct.LoanUnit.AnyAsync()) return false;
if (await ct.Part.AnyAsync()) return false;
if (await ct.Project.AnyAsync()) return false;
if (await ct.PurchaseOrder.AnyAsync()) return false;
return true;
}