Suspects: Eingabezeile oben, Letzter Kontakt standardmäßig heute
- Eingabezeile über der Liste, mit Abstand und Knopf Hinzufügen; Liste neueste zuerst, neue Einträge erscheinen direkt darunter - Letzter Kontakt neuer Zeilen = heute (Ortszeit), auch serverseitig, wenn das Feld beim Anlegen fehlt Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
78d6bef52c
commit
33c9dbdb2b
@@ -46,6 +46,9 @@ function readBody(body) {
|
||||
return out;
|
||||
}
|
||||
|
||||
/** Heute in deutscher Zeit als YYYY-MM-DD (sv-SE formatiert genau so). */
|
||||
const localDate = () => new Date().toLocaleDateString('sv-SE', { timeZone: 'Europe/Berlin' });
|
||||
|
||||
const inDays = (days) => new Date(Date.now() + days * 86_400_000).toISOString().slice(0, 19).replace('T', ' ');
|
||||
|
||||
const SELECT = `
|
||||
@@ -58,8 +61,8 @@ const normalize = (row) => ({ ...row, archived: Boolean(row.archived) });
|
||||
router.get('/', async (req, res, next) => {
|
||||
const archived = String(req.query.archived ?? '0') === '1';
|
||||
try {
|
||||
// Neueste unten: die Tabelle waechst wie eine Liste nach unten.
|
||||
const [rows] = await pool.query(`${SELECT} WHERE s.archived = ? ORDER BY ${archived ? 's.updated_at DESC' : 's.id'}`, [
|
||||
// Neueste oben - direkt unter der Eingabezeile, die oben steht.
|
||||
const [rows] = await pool.query(`${SELECT} WHERE s.archived = ? ORDER BY ${archived ? 's.updated_at DESC' : 's.id DESC'}`, [
|
||||
archived ? 1 : 0,
|
||||
]);
|
||||
res.json({ suspects: rows.map(normalize) });
|
||||
@@ -83,6 +86,8 @@ router.get('/reminders', async (req, res, next) => {
|
||||
router.post('/', async (req, res, next) => {
|
||||
const data = readBody(req.body || {});
|
||||
if (!data.name) return res.status(400).json({ error: 'Der Name ist erforderlich.' });
|
||||
// Ohne Angabe gilt heute als letzter Kontakt; ein bewusst leeres Feld (null) bleibt leer.
|
||||
if (req.body?.last_contact_on === undefined) data.last_contact_on = localDate();
|
||||
try {
|
||||
const columns = Object.keys(data);
|
||||
const [result] = await pool.query(
|
||||
|
||||
Reference in New Issue
Block a user