Agenda refactor
This commit is contained in:
parent
f9ecffd78c
commit
b5c15964e7
@ -1082,6 +1082,35 @@ export async function syncMicrosoftCalendar(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Delete events that are no longer in Microsoft calendar
|
||||||
|
// Build a set of all Microsoft event IDs we just synced
|
||||||
|
const syncedMicrosoftIds = new Set<string>();
|
||||||
|
for (const caldavEvent of caldavEvents) {
|
||||||
|
if (caldavEvent.uid) {
|
||||||
|
syncedMicrosoftIds.add(caldavEvent.uid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find events in DB that have externalEventId but are not in the synced list
|
||||||
|
// Only delete events that have an externalEventId (to avoid deleting manually created events)
|
||||||
|
for (const existingEvent of existingEvents) {
|
||||||
|
const externalId = (existingEvent as any).externalEventId;
|
||||||
|
if (externalId && !syncedMicrosoftIds.has(externalId)) {
|
||||||
|
// This event exists in DB but not in Microsoft - it was deleted in Microsoft
|
||||||
|
logger.info('Deleting event that no longer exists in Microsoft', {
|
||||||
|
eventId: existingEvent.id,
|
||||||
|
title: existingEvent.title,
|
||||||
|
externalEventId: externalId,
|
||||||
|
});
|
||||||
|
|
||||||
|
await prisma.event.delete({
|
||||||
|
where: { id: existingEvent.id },
|
||||||
|
});
|
||||||
|
|
||||||
|
deleted++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Update sync timestamp
|
// Update sync timestamp
|
||||||
await prisma.calendarSync.update({
|
await prisma.calendarSync.update({
|
||||||
where: { id: calendarSyncId },
|
where: { id: calendarSyncId },
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user