diff --git a/server/api/controller/event.js b/server/api/controller/event.js index 957e74b1..08f8cab2 100644 --- a/server/api/controller/event.js +++ b/server/api/controller/event.js @@ -11,7 +11,7 @@ const Col = helpers.col const notifier = require('../../notifier') const { htmlToText } = require('html-to-text') -const { Event, Resource, Tag, Place, Notification, APUser, Collection } = require('../models/models') +const { Event, Resource, Tag, Place, Notification, APUser, Collection, EventNotification } = require('../models/models') const exportController = require('./export') @@ -586,6 +586,7 @@ const eventController = { try { // remove related resources await Resource.destroy({ where: { eventId: event.id }}) + await EventNotification.destroy({ where: { eventId: event.id }}) // and finally remove the event await event.destroy() diff --git a/server/helpers/ap.js b/server/helpers/ap.js index a59eb5a1..04d43756 100644 --- a/server/helpers/ap.js +++ b/server/helpers/ap.js @@ -1,4 +1,4 @@ -const { Event, Resource } = require('../api/models/models') +const { Event, Resource, EventNotification } = require('../api/models/models') const { Op } = require('sequelize') const { DateTime } = require('luxon') const log = require('../log') @@ -9,13 +9,15 @@ module.exports = { const events = await Event.findAll({ where: { start_datetime: { [Op.lt]: now }, apUserApId: { [Op.ne]: null } - }}) + }, raw: true }) if (!events.length) { return } log.info(`Remove ${events.length} past federated events and related resources`) await Resource.destroy({ where: { eventId: events.map(e => e.id) }}) + await EventNotification.destroy({ where: { eventId: events.map(e => e.id) }}) + await Event.destroy({ where: { start_datetime: { [Op.lt]: now },