Deleted Flag eingeführt

This commit is contained in:
rxf
2026-01-14 07:41:14 +01:00
parent 44a93ac1e7
commit 2d83276a27

View File

@@ -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." });
}