Archived
Arbeitstag-Grenze auf 6 Uhr + Feierabend reversibel
Nachtarbeit über Mitternacht brach bisher den Check-Out ("Du bist heute
noch nicht locked in") und sperrte nach versehentlichem Feierabend den Tag.
- Tag = Kalendertag des Check-ins; eine über Mitternacht laufende Session
zaehlt zum Starttag, bis 06:00 des Folgetags (isWorkdaySealed)
- checkOut/today finden den offenen Eintrag statt stur "heute"
- reopen ("Arbeit fortsetzen") hebt einen Feierabend wieder auf
- applyWorkdayBoundary: nahtloser 6-Uhr-Schnitt (Auto-Checkout + Folge-Tag,
offene ToDos wandern mit)
- Reflexion/ToDo-Edit folgen der 6-Uhr-Grenze statt Mitternacht
- Cron apply-workday-boundaries fuer Team-Dashboard-Konsistenz
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
b39c67d1aa
commit
39e259f3ac
5 files changed
+308
-49
No files matched your search
@@ -1,8 +1,10 @@
|
||||
import type { FastifyInstance, FastifyRequest } from 'fastify';
|
||||
import { isNull } from 'drizzle-orm';
|
||||
import { dayEntry } from '@cockpit/db';
|
||||
import { loadEnv } from '../env.js';
|
||||
import { logger } from '../lib/logger.js';
|
||||
import { getDb } from '../db.js';
|
||||
import { publishYesterdaysEntries } from '../routers/day-entry.js';
|
||||
import { publishYesterdaysEntries, applyWorkdayBoundary } from '../routers/day-entry.js';
|
||||
import { previousWerktag, todayIso } from '../lib/werktag.js';
|
||||
|
||||
function authorize(req: FastifyRequest): void {
|
||||
@@ -15,6 +17,33 @@ function authorize(req: FastifyRequest): void {
|
||||
}
|
||||
|
||||
export async function registerCronRoutes(app: FastifyInstance): Promise<void> {
|
||||
// 6-Uhr-Schnitt teamweit: beendet offene Nacht-Einträge, deren Arbeitstag
|
||||
// abgelaufen ist, und startet den Folge-Tag. Lazy passiert das ohnehin beim
|
||||
// nächsten Request der Person — dieser Cron (≈06:05) hält das Team-Dashboard
|
||||
// konsistent, auch ohne dass die Person aktiv wird.
|
||||
app.post('/internal/cron/apply-workday-boundaries', async (req, reply) => {
|
||||
try {
|
||||
authorize(req);
|
||||
} catch (err) {
|
||||
reply.code(401);
|
||||
logger.warn({ err }, 'unauthorized cron call');
|
||||
return { error: 'unauthorized' };
|
||||
}
|
||||
const { db } = getDb();
|
||||
const now = new Date();
|
||||
const openRows = await db
|
||||
.selectDistinct({ userId: dayEntry.userId })
|
||||
.from(dayEntry)
|
||||
.where(isNull(dayEntry.checkedOutAt));
|
||||
let cut = 0;
|
||||
for (const { userId } of openRows) {
|
||||
await applyWorkdayBoundary(db, userId, now);
|
||||
cut++;
|
||||
}
|
||||
logger.info({ usersChecked: cut }, 'applied workday boundaries');
|
||||
return { ok: true, usersChecked: cut };
|
||||
});
|
||||
|
||||
app.post('/internal/cron/publish-day-entries', async (req, reply) => {
|
||||
try {
|
||||
authorize(req);
|
||||
|
||||
Reference in new issue
Block a user