diff --git a/backend/src/server.js b/backend/src/server.js index 3c3f4be..bceea07 100644 --- a/backend/src/server.js +++ b/backend/src/server.js @@ -34,9 +34,9 @@ app.use(express.json()); app.get('/api/appointments', async (req, res) => { try { const db = getDb(); - // Finde alle Dokumente in der Collection 'appointments' + // Finde alle Dokumente in der Collection 'appointments', die nicht gelöscht sind const appointments = await db.collection('appointments') - .find({}) + .find({ deleted: { $ne: true } }) // Optional: Nach Termindatum sortieren (aufsteigend) .sort({ termin: 1 }) .toArray(); @@ -112,6 +112,7 @@ app.put('/api/appointments/:id', async (req, res) => { }); // 4. DELETE: Termin löschen (DELETE /api/appointments/:id) +// Soft Delete: Setzt das deleted-Flag statt den Eintrag zu löschen app.delete('/api/appointments/:id', async (req, res) => { try { const db = getDb(); @@ -119,9 +120,13 @@ app.delete('/api/appointments/:id', async (req, res) => { const filter = { _id: new ObjectId(id) }; - const result = await db.collection('appointments').deleteOne(filter); + // Setze das deleted-Flag auf true statt den Eintrag zu löschen + const result = await db.collection('appointments').updateOne( + filter, + { $set: { deleted: true, deletedAt: new Date() } } + ); - if (result.deletedCount === 0) { + if (result.matchedCount === 0) { return res.status(404).json({ message: "Termin nicht gefunden." }); }