Löschfristen: Probelauf, Bericht ans Team, Löschen nach drei Jahren
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
cc42ab16c1
commit
9342ba10c8
5 files changed
+484
-1
No files matched your search
@@ -0,0 +1,44 @@
|
||||
#!/usr/bin/env node
|
||||
/**
|
||||
* Loeschfristen (Datenschutzerklaerung Abschnitt 7): Abo-Daten drei Jahre nach Ablauf des Jahres loeschen, in dem
|
||||
* das letzte Abo eines Kunden endet. Einmal im Jahr im Januar ausfuehren, im Container als Datei:
|
||||
* docker exec -w /app <container> node scripts/loeschfristen.mjs (Probelauf: Bericht, loescht nichts)
|
||||
* docker exec -w /app -e LOESCHFRISTEN=mail <container> node scripts/loeschfristen.mjs (Bericht als T14 ans Team)
|
||||
* docker exec -w /app -e LOESCHFRISTEN=apply <container> node scripts/loeschfristen.mjs (loescht, Bericht danach)
|
||||
*/
|
||||
import 'dotenv/config'
|
||||
import { applyDeletions, findDueDeletions, formatReport } from '../server/services/retention.js'
|
||||
import { sendAdminNotice } from '../server/services/mailer.js'
|
||||
|
||||
const MODES = new Set(['', 'mail', 'apply'])
|
||||
|
||||
/** mode: '' (Probelauf) | 'mail' | 'apply'. Liefert { plan, result, applied }. */
|
||||
export async function run({ mode = '', now = new Date(), log = console.log } = {}) {
|
||||
if (!MODES.has(mode)) throw new Error(`LOESCHFRISTEN="${mode}" ist unbekannt: leer (Probelauf), mail oder apply`)
|
||||
const plan = await findDueDeletions(now)
|
||||
if (mode === 'apply') {
|
||||
const result = await applyDeletions(plan)
|
||||
log('Löschfristen: gelöscht')
|
||||
log(formatReport(plan, result))
|
||||
return { plan, result, applied: true }
|
||||
}
|
||||
const report = formatReport(plan)
|
||||
log('Löschfristen: Probelauf, es wird nichts gelöscht')
|
||||
log(report)
|
||||
if (mode === 'mail') {
|
||||
const sent = await sendAdminNotice({
|
||||
template: 'T14',
|
||||
values: { modus: 'Probelauf', anzahl_kunden: plan.customers.length, bericht: report },
|
||||
})
|
||||
if (!sent.sent) log(`Bericht nicht verschickt: ${sent.reason}`)
|
||||
else log('Bericht als T14 ans Team geschickt.')
|
||||
}
|
||||
return { plan, result: null, applied: false }
|
||||
}
|
||||
|
||||
if (import.meta.url === `file://${process.argv[1]}`) {
|
||||
run({ mode: process.env.LOESCHFRISTEN || '' }).catch((err) => {
|
||||
console.error('❌', err.message)
|
||||
process.exit(1)
|
||||
})
|
||||
}
|
||||
Reference in new issue
Block a user