update FDISK sync
This commit is contained in:
@@ -69,7 +69,9 @@ export async function syncToDatabase(
|
||||
const profileResult = await client.query<{ user_id: string }>(
|
||||
`SELECT mp.user_id
|
||||
FROM mitglieder_profile mp
|
||||
WHERE mp.fdisk_standesbuch_nr = $1`,
|
||||
JOIN users u ON u.id = mp.user_id
|
||||
WHERE mp.fdisk_standesbuch_nr = $1
|
||||
AND u.last_login_at IS NOT NULL`,
|
||||
[member.standesbuchNr]
|
||||
);
|
||||
|
||||
@@ -78,18 +80,20 @@ export async function syncToDatabase(
|
||||
if (profileResult.rows.length > 0) {
|
||||
userId = profileResult.rows[0].user_id;
|
||||
} else {
|
||||
// Fallback: match by name (case-insensitive)
|
||||
// Fallback: match by name (case-insensitive), only logged-in users
|
||||
const nameResult = await client.query<{ id: string }>(
|
||||
`SELECT u.id
|
||||
FROM users u
|
||||
JOIN mitglieder_profile mp ON mp.user_id = u.id
|
||||
WHERE LOWER(u.given_name) = LOWER($1)
|
||||
AND LOWER(u.family_name) = LOWER($2)
|
||||
LIMIT 1`,
|
||||
AND u.last_login_at IS NOT NULL`,
|
||||
[member.vorname, member.zuname]
|
||||
);
|
||||
|
||||
if (nameResult.rows.length > 0) {
|
||||
if (nameResult.rows.length > 1) {
|
||||
log(`WARN: skipping ${member.vorname} ${member.zuname} (Standesbuch-Nr ${member.standesbuchNr}) — duplicate name match (${nameResult.rows.length} users)`);
|
||||
} else if (nameResult.rows.length === 1) {
|
||||
userId = nameResult.rows[0].id;
|
||||
// Store the Standesbuch-Nr now that we found a match
|
||||
await client.query(
|
||||
|
||||
Reference in New Issue
Block a user