Reject already expired post deadlines
This commit is contained in:
@@ -945,6 +945,18 @@ function normalizeDeadline(value) {
|
||||
return null;
|
||||
}
|
||||
|
||||
function isDeadlineExpired(value, now = new Date()) {
|
||||
const normalized = normalizeDeadline(value);
|
||||
if (!normalized) {
|
||||
return false;
|
||||
}
|
||||
const deadline = new Date(normalized);
|
||||
if (Number.isNaN(deadline.getTime())) {
|
||||
return false;
|
||||
}
|
||||
return deadline.getTime() <= now.getTime();
|
||||
}
|
||||
|
||||
function getProfileName(profileNumber) {
|
||||
return DEFAULT_PROFILE_NAMES[profileNumber] || `Profil ${profileNumber}`;
|
||||
}
|
||||
@@ -6506,6 +6518,9 @@ app.post('/api/posts', (req, res) => {
|
||||
if (!normalizedDeadline) {
|
||||
return res.status(400).json({ error: 'deadline_at must be a valid date string' });
|
||||
}
|
||||
if (isDeadlineExpired(normalizedDeadline)) {
|
||||
return res.status(400).json({ error: 'Deadline ist bereits abgelaufen' });
|
||||
}
|
||||
}
|
||||
|
||||
const creatorDisplayName = normalizeCreatorName(created_by_name);
|
||||
@@ -6625,6 +6640,9 @@ app.put('/api/posts/:postId', (req, res) => {
|
||||
if (!normalizedDeadline) {
|
||||
return res.status(400).json({ error: 'deadline_at must be a valid date string' });
|
||||
}
|
||||
if (isDeadlineExpired(normalizedDeadline)) {
|
||||
return res.status(400).json({ error: 'Deadline ist bereits abgelaufen' });
|
||||
}
|
||||
}
|
||||
updates.push('deadline_at = ?');
|
||||
params.push(normalizedDeadline);
|
||||
|
||||
Reference in New Issue
Block a user