This commit is contained in:
Matthias Hochmeister
2026-03-13 15:09:43 +01:00
parent 7833dca29c
commit 20d2c9093a
4 changed files with 52 additions and 6 deletions

View File

@@ -544,6 +544,24 @@ class MemberService {
}
}
/**
* Ensures a mitglieder_profile row exists for the given user.
* Safe to call on every login — idempotent via ON CONFLICT DO NOTHING.
* Errors are caught and logged without throwing.
*/
async ensureProfileExists(userId: string): Promise<void> {
try {
await pool.query(
`INSERT INTO mitglieder_profile (user_id, status)
VALUES ($1, 'aktiv')
ON CONFLICT (user_id) DO NOTHING`,
[userId]
);
} catch (error) {
logger.warn('ensureProfileExists failed (non-fatal)', { error, userId });
}
}
/**
* Returns aggregate member counts, used by the dashboard KPI cards.
* Optionally scoped to a single status value.