Checkout Server bestätigung, Darkmode Checkout server
This commit is contained in:
@@ -30,7 +30,14 @@ function sendResponse(req, res, success, data) {
|
||||
if (!success && data.status) {
|
||||
res.status(data.status);
|
||||
}
|
||||
res.render('checkin-result', { success, title, message });
|
||||
res.render('checkin-result', {
|
||||
success,
|
||||
title,
|
||||
message,
|
||||
confirmUrl: data.confirmUrl || null,
|
||||
confirmLabel: data.confirmLabel || null,
|
||||
confirmMethod: data.confirmMethod || 'GET'
|
||||
});
|
||||
} else {
|
||||
if (success) {
|
||||
res.json({ success: true, ...data });
|
||||
@@ -106,8 +113,13 @@ checkinApp.get('/api/checkin/:userId', (req, res) => {
|
||||
});
|
||||
});
|
||||
|
||||
// API: Check-out (Gehen)
|
||||
checkinApp.get('/api/checkout/:userId', (req, res) => {
|
||||
// API: Check-out (Gehen) - GET und POST (POST für force-Bestätigung)
|
||||
checkinApp.post('/api/checkout/:userId', express.urlencoded({ extended: false }), (req, res) => {
|
||||
handleCheckout(req, res, true);
|
||||
});
|
||||
checkinApp.get('/api/checkout/:userId', (req, res) => handleCheckout(req, res, false));
|
||||
|
||||
function handleCheckout(req, res, force) {
|
||||
const userId = parseInt(req.params.userId);
|
||||
const currentDate = getCurrentDate();
|
||||
const currentTime = getCurrentTime();
|
||||
@@ -131,7 +143,28 @@ checkinApp.get('/api/checkout/:userId', (req, res) => {
|
||||
status: 400
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// Wenn bereits eine End-Zeit existiert und nicht erzwungen wird → Bestätigung anfordern
|
||||
if (entry.end_time && !force) {
|
||||
if (wantsHtml(req)) {
|
||||
return res.render('checkin-result', {
|
||||
success: true,
|
||||
title: 'Bereits ausgecheckt',
|
||||
message: `Du wurdest heute bereits um ${entry.end_time} ausgecheckt. Möchtest du die End-Zeit auf ${currentTime} überschreiben?`,
|
||||
confirmUrl: `/api/checkout/${userId}`,
|
||||
confirmMethod: 'POST',
|
||||
confirmLabel: 'Ja, End-Zeit überschreiben'
|
||||
});
|
||||
}
|
||||
return res.status(409).json({
|
||||
success: false,
|
||||
error: 'Bereits ausgecheckt',
|
||||
existing_end_time: entry.end_time,
|
||||
confirm_url: `/api/checkout/${userId}`,
|
||||
confirm_method: 'POST'
|
||||
});
|
||||
}
|
||||
|
||||
// Berechne total_hours basierend auf start_time, end_time und break_minutes
|
||||
const breakMinutes = entry.break_minutes || 0;
|
||||
const totalHours = updateTotalHours(entry.start_time, currentTime, breakMinutes);
|
||||
@@ -154,7 +187,7 @@ checkinApp.get('/api/checkout/:userId', (req, res) => {
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Check-in-Server starten (auf Port 3334)
|
||||
checkinApp.listen(CHECKIN_PORT, () => {
|
||||
|
||||
Reference in New Issue
Block a user