mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-17 23:52:24 +00:00
feat(admin): pulse day-mean dry run, apply step and admin card
This commit is contained in:
1 parent
877920f5f7
commit
9f17cef8e4
17 files changed
+915
-16
No files matched your search
@@ -63,9 +63,6 @@ export interface PulseDayMeanPayload {
|
||||
action: "dry_run" | "rebuild";
|
||||
}
|
||||
|
||||
/** How old a finished dry run may be for the apply step to accept it. */
|
||||
export const DRY_RUN_FRESH_MS = 7 * 24 * 60 * 60 * 1000;
|
||||
|
||||
const DAY_MS = 24 * 60 * 60 * 1000;
|
||||
/** Days of one account's pulse a dry-run statement covers. */
|
||||
const DRY_RUN_WINDOW_DAYS = 90;
|
||||
@@ -131,17 +128,6 @@ export async function readPulseDayMeanStatus(): Promise<PulseDayMeanStatus> {
|
||||
};
|
||||
}
|
||||
|
||||
/** A finished dry run from the last seven days, the apply step's condition. */
|
||||
export function hasFreshDryRun(
|
||||
status: PulseDayMeanStatus,
|
||||
now: Date = new Date(),
|
||||
): boolean {
|
||||
const run = status.lastDryRun;
|
||||
if (!run || run.status !== "done" || run.finishedAt === null) return false;
|
||||
const finished = Date.parse(run.finishedAt);
|
||||
return Number.isFinite(finished) && now.getTime() - finished <= DRY_RUN_FRESH_MS;
|
||||
}
|
||||
|
||||
/** The only write a dry run makes. */
|
||||
export async function writeDryRun(run: PulseDayMeanDryRun): Promise<void> {
|
||||
await prisma.appSettings.upsert({
|
||||
|
||||
@@ -53,6 +53,8 @@ export const adminKeys = {
|
||||
adminEncryptionStatus: () => ["admin", "encryption", "status"] as const,
|
||||
adminMeasurementMaintenance: () =>
|
||||
["admin", "maintenance", "measurements"] as const,
|
||||
/** v1.43 — the pulse day-mean method, its dry run and apply step. */
|
||||
adminPulseDayMean: () => ["admin", "maintenance", "pulse-day-mean"] as const,
|
||||
/** v1.40.0 — the "Back up your encryption key" step (admin + dashboard banner). */
|
||||
adminEncryptionKeyBackup: () =>
|
||||
["admin", "encryption", "key-backup"] as const,
|
||||
|
||||
@@ -56,3 +56,22 @@ export interface PulseDayMeanStatus {
|
||||
appliedAt: string | null;
|
||||
lastDryRun: PulseDayMeanDryRun | null;
|
||||
}
|
||||
|
||||
/** How old a finished dry run may be for the apply step to accept it. */
|
||||
const DRY_RUN_FRESH_MS = 7 * 24 * 60 * 60 * 1000;
|
||||
|
||||
/**
|
||||
* A finished dry run from the last seven days: the apply step's condition,
|
||||
* enforced by the route and mirrored by the admin card's button.
|
||||
*/
|
||||
export function hasFreshDryRun(
|
||||
status: Pick<PulseDayMeanStatus, "lastDryRun">,
|
||||
now: Date = new Date(),
|
||||
): boolean {
|
||||
const run = status.lastDryRun;
|
||||
if (!run || run.status !== "done" || run.finishedAt === null) return false;
|
||||
const finished = Date.parse(run.finishedAt);
|
||||
return (
|
||||
Number.isFinite(finished) && now.getTime() - finished <= DRY_RUN_FRESH_MS
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user