From 482e9dae954eae141084c756d461c589102144cf Mon Sep 17 00:00:00 2001 From: titanism <101466223+titanism@users.noreply.github.com> Date: Mon, 2 Sep 2024 11:22:54 -0500 Subject: [PATCH] feat: added deleteCalendar option --- routes/calendar/calendar/delete.js | 42 ++++++++++++++---------------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/routes/calendar/calendar/delete.js b/routes/calendar/calendar/delete.js index 5ae0dfd..f2fd115 100644 --- a/routes/calendar/calendar/delete.js +++ b/routes/calendar/calendar/delete.js @@ -1,38 +1,34 @@ -const { notFound } = require('../../../common/x-build'); const { setMissingMethod } = require('../../../common/response'); -const winston = require('../../../common/winston'); /* https://tools.ietf.org/html/rfc2518#section-8.6 */ module.exports = function (options) { - const log = winston({ ...options, label: 'calendar/delete' }); const exec = async function (ctx, calendar) { if (calendar.readonly) { setMissingMethod(ctx); return; } - if (!ctx.state.params.eventId) { - log.warn('eventId param not present'); - ctx.body = notFound(ctx.url); // Make more meaningful - return; + // + // if event id not specified this indicates we're deleting + // an entire calendar so we need to delete all events for it as well in this logic + // + if (ctx.state.params.eventId) { + await options.data.deleteEvent(ctx, { + eventId: ctx.state.params.eventId, + principalId: ctx.state.params.principalId, + calendarId: ctx.state.params.calendarId, + user: ctx.state.user, + calendar + }); + } else { + await options.data.deleteCalendar(ctx, { + principalId: ctx.state.params.principalId, + calendarId: ctx.state.params.calendarId, + user: ctx.state.user, + calendar + }); } - const existing = await options.data.getEvent(ctx, { - eventId: ctx.state.params.eventId, - principalId: ctx.state.params.principalId, - calendarId: ctx.state.params.calendarId, - user: ctx.state.user, - fullData: false - }); - log.debug(`existing event${existing ? '' : ' not'} found`); - - await options.data.deleteEvent(ctx, { - eventId: ctx.state.params.eventId, - principalId: ctx.state.params.principalId, - calendarId: ctx.state.params.calendarId, - user: ctx.state.user - }); - ctx.status = 200; ctx.body = ''; };