Use logsDb for the status history

This commit is contained in:
Owen
2026-04-28 16:38:13 -07:00
parent 85415176ab
commit 2a29062659
6 changed files with 67 additions and 38 deletions

View File

@@ -84,7 +84,7 @@ export async function registerNewt(
maxBatchSize: siteProvisioningKeys.maxBatchSize,
numUsed: siteProvisioningKeys.numUsed,
validUntil: siteProvisioningKeys.validUntil,
approveNewSites: siteProvisioningKeys.approveNewSites,
approveNewSites: siteProvisioningKeys.approveNewSites
})
.from(siteProvisioningKeys)
.innerJoin(
@@ -125,7 +125,10 @@ export async function registerNewt(
);
}
if (keyRecord.maxBatchSize && keyRecord.numUsed >= keyRecord.maxBatchSize) {
if (
keyRecord.maxBatchSize &&
keyRecord.numUsed >= keyRecord.maxBatchSize
) {
return next(
createHttpError(
HttpCode.UNAUTHORIZED,
@@ -134,7 +137,10 @@ export async function registerNewt(
);
}
if (keyRecord.validUntil && new Date(keyRecord.validUntil) < new Date()) {
if (
keyRecord.validUntil &&
new Date(keyRecord.validUntil) < new Date()
) {
return next(
createHttpError(
HttpCode.UNAUTHORIZED,
@@ -154,7 +160,10 @@ export async function registerNewt(
}
if (!org.subnet) {
return next(
createHttpError(HttpCode.INTERNAL_SERVER_ERROR, "Organization subnet not found")
createHttpError(
HttpCode.INTERNAL_SERVER_ERROR,
"Organization subnet not found"
)
);
}
@@ -195,7 +204,6 @@ export async function registerNewt(
let newSiteId: number | undefined;
await db.transaction(async (trx) => {
const newClientAddress = await getNextAvailableClientSubnet(orgId);
if (!newClientAddress) {
return next(
@@ -219,11 +227,11 @@ export async function registerNewt(
address: clientAddress,
type: "newt",
dockerSocketEnabled: true,
status: keyRecord.approveNewSites ? "approved" : "pending",
status: keyRecord.approveNewSites ? "approved" : "pending"
})
.returning();
await trx.insert(statusHistory).values({
await logsDb.insert(statusHistory).values({
entityType: "site",
entityId: newSite.siteId,
orgId: orgId,