Adapt to existing beos table in database sternwarte

Column mapping: id, name/vorname, kürzel (with umlaut), pw instead of
the planned schema. DB_NAME changed to sternwarte. create_table.sql
no longer creates beos, only the three new logbuch tables.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-27 17:34:45 +02:00
parent 4e53a7a5cd
commit 12be2f1db2
5 changed files with 25 additions and 24 deletions

View File

@@ -2,16 +2,17 @@ import bcrypt from 'bcryptjs';
import { query } from './db';
export interface Beo {
ID: number;
Kuerzel: string;
Name: string;
Passwort: string | null;
id: number;
name: string;
vorname: string | null;
kürzel: string | null;
pw: string | null;
MustChangePassword: number;
}
export async function getBeoByKuerzel(kuerzel: string): Promise<Beo | null> {
const rows = await query(
'SELECT ID, Kuerzel, Name, Passwort, MustChangePassword FROM beos WHERE Kuerzel = ?',
'SELECT id, name, vorname, `kürzel`, pw, MustChangePassword FROM beos WHERE `kürzel` = ?',
[kuerzel]
) as Beo[];
return rows[0] ?? null;
@@ -24,15 +25,19 @@ export async function verifyCredentials(
const beo = await getBeoByKuerzel(kuerzel);
if (!beo) return null;
if (!beo.Passwort) {
if (!beo.pw) {
const valid = password === 'logbuch123';
return { beo, valid };
}
const valid = await bcrypt.compare(password, beo.Passwort);
const valid = await bcrypt.compare(password, beo.pw);
return { beo, valid };
}
export async function hashPassword(password: string): Promise<string> {
return bcrypt.hash(password, 10);
}
export function getBeoDisplayName(beo: Beo): string {
return beo.vorname ? `${beo.vorname} ${beo.name}` : beo.name;
}