forked from fahrPool/fahrPool
fix: unify Zeiterfassung timezone display and add DB guard against double clock-in
Page and CSV export now both render shift timestamps in Europe/Berlin consistently (previously CSV used UTC, page used server-local time, causing the same shift to show different clock times in each place). Also adds a partial unique index so two near-simultaneous Kommen requests for the same fahrer can no longer create two open shifts -- the existing app-layer check was check-then-act with no DB backstop.
This commit is contained in:
parent
d87e881d0e
commit
90ed4d764f
|
|
@ -0,0 +1,11 @@
|
|||
-- Verhindert auf DB-Ebene, dass ein Fahrer durch einen Race (zwei nahezu
|
||||
-- gleichzeitige Kommen-Klicks) zwei offene Schichten gleichzeitig hat --
|
||||
-- die bisherige Pruefung in kommen() (Server Action) ist reine
|
||||
-- Check-then-Act-Logik ohne Backstop. Partieller Index (nur wo geht_um
|
||||
-- null ist) statt vollstaendigem Unique-Index auf fahrer_id, da ein Fahrer
|
||||
-- durchaus mehrere ABGESCHLOSSENE Schichten pro Tag haben darf (geteilte
|
||||
-- Schichten, siehe Spec) -- nur gleichzeitig offene Schichten sind das
|
||||
-- Problem.
|
||||
create unique index arbeitszeiten_ein_offene_schicht_je_fahrer
|
||||
on public.arbeitszeiten (fahrer_id)
|
||||
where geht_um is null;
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
begin;
|
||||
select plan(14);
|
||||
select plan(15);
|
||||
|
||||
insert into auth.users (id, email) values
|
||||
('aa111111-1111-1111-1111-111111111111', 'admin@arbeitszeiten.test.local'),
|
||||
|
|
@ -35,6 +35,19 @@ select throws_ok(
|
|||
'Fahrer kann sich NICHT fuer einen anderen Fahrer einstempeln (RLS blockt INSERT mit fremder fahrer_id)'
|
||||
);
|
||||
|
||||
-- Backstop gegen Check-then-Act-Race in kommen() (Server Action): der
|
||||
-- partielle Unique-Index arbeitszeiten_ein_offene_schicht_je_fahrer
|
||||
-- verhindert eine zweite gleichzeitig offene Schicht fuer denselben Fahrer.
|
||||
select throws_ok(
|
||||
$$
|
||||
insert into public.arbeitszeiten (fahrer_id, kommt_um)
|
||||
values ('aa333333-3333-3333-3333-333333333333', now())
|
||||
$$,
|
||||
'23505',
|
||||
'duplicate key value violates unique constraint "arbeitszeiten_ein_offene_schicht_je_fahrer"',
|
||||
'Fahrer kann NICHT eine zweite offene Schicht anlegen, waehrend die erste noch offen ist (DB-Unique-Index)'
|
||||
);
|
||||
|
||||
select throws_ok(
|
||||
$$
|
||||
insert into public.arbeitszeiten (fahrer_id, kommt_um, korrigiert_von)
|
||||
|
|
|
|||
|
|
@ -112,7 +112,8 @@ export default async function ZeiterfassungPage({
|
|||
<li key={schicht.id}>
|
||||
<Card>
|
||||
<p className="text-asphalt-grey">
|
||||
{schicht.fahrer.name} — Kommt: {new Date(schicht.kommt_um).toLocaleString("de-DE")}
|
||||
{schicht.fahrer.name} — Kommt:{" "}
|
||||
{new Date(schicht.kommt_um).toLocaleString("de-DE", { timeZone: "Europe/Berlin" })}
|
||||
</p>
|
||||
<KorrekturFormular schichtId={schicht.id} />
|
||||
</Card>
|
||||
|
|
@ -154,9 +155,11 @@ export default async function ZeiterfassungPage({
|
|||
<li key={schicht.id}>
|
||||
<Card>
|
||||
<p className="text-asphalt-grey">
|
||||
{schicht.fahrer.name}: {new Date(schicht.kommt_um).toLocaleString("de-DE")}
|
||||
{schicht.fahrer.name}: {new Date(schicht.kommt_um).toLocaleString("de-DE", { timeZone: "Europe/Berlin" })}
|
||||
{" – "}
|
||||
{schicht.geht_um ? new Date(schicht.geht_um).toLocaleString("de-DE") : "läuft noch"}
|
||||
{schicht.geht_um
|
||||
? new Date(schicht.geht_um).toLocaleString("de-DE", { timeZone: "Europe/Berlin" })
|
||||
: "läuft noch"}
|
||||
</p>
|
||||
{schicht.geht_um && (
|
||||
<p className="mt-1 text-xs text-asphalt-grey/70">
|
||||
|
|
@ -169,7 +172,8 @@ export default async function ZeiterfassungPage({
|
|||
)}
|
||||
{schicht.korrigiert_von && schicht.korrigiert_am && (
|
||||
<p className="mt-1 text-xs text-status-danger">
|
||||
Korrigiert am {new Date(schicht.korrigiert_am).toLocaleString("de-DE")}
|
||||
Korrigiert am{" "}
|
||||
{new Date(schicht.korrigiert_am).toLocaleString("de-DE", { timeZone: "Europe/Berlin" })}
|
||||
</p>
|
||||
)}
|
||||
{(auftraegeMap.get(schicht.id) ?? []).map((auftrag) => (
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ function csvFeld(wert: string): string {
|
|||
}
|
||||
|
||||
function formatiereUhrzeit(iso: string): string {
|
||||
return new Date(iso).toLocaleString("de-DE", { timeZone: "UTC" });
|
||||
return new Date(iso).toLocaleString("de-DE", { timeZone: "Europe/Berlin" });
|
||||
}
|
||||
|
||||
export function schichtenZuCsv(zeilen: CsvZeile[]): string {
|
||||
|
|
|
|||
Loading…
Reference in New Issue