mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-13 22:32:04 +00:00
restoreBackup becomes an orchestrator: the checks before the first delete move to restore-preflight.ts, and the transaction runs the steps listed in backup-domains.ts in dependency order, emptying the account first and then rebuilding it domain by domain. The inline restores for measurements, medications, mood, labs, illness, allergies, family history, workouts, nutrient days, documents, the instance settings and the cleared notification channels move into one module per domain, beside the existing section modules. Cross-domain references travel through one typed context instead of local variables. The order of every write, the refusals and their audit rows, the skip report, the cleared counts and the reported phases are unchanged; the golden copies of the restored account still match. Guards that pinned the restore by path now point at the domain files.
27 lines
991 B
TypeScript
27 lines
991 B
TypeScript
/**
|
|
* The notification channels, which a backup deliberately never carries
|
|
* (`NOT_IN_BACKUP_MODELS` says why for each) and a restore therefore clears:
|
|
* a channel, a Web Push endpoint or a pending Telegram deletion from before
|
|
* the restore addresses a chat or a browser the restored account has not
|
|
* been through setup with on this host.
|
|
*/
|
|
import type { RestoreContext } from "@/lib/export/restore-context";
|
|
|
|
export async function clearNotificationChannels(
|
|
ctx: RestoreContext,
|
|
): Promise<void> {
|
|
const { tx, ownerId } = ctx;
|
|
const channels = await tx.notificationChannel.deleteMany({
|
|
where: { userId: ownerId },
|
|
});
|
|
const subs = await tx.pushSubscription.deleteMany({
|
|
where: { userId: ownerId },
|
|
});
|
|
const tgDel = await tx.telegramScheduledDeletion.deleteMany({
|
|
where: { userId: ownerId },
|
|
});
|
|
ctx.cleared.notificationChannels = channels.count;
|
|
ctx.cleared.pushSubscriptions = subs.count;
|
|
ctx.cleared.telegramScheduledDeletions = tgDel.count;
|
|
}
|