Skip to content

Commit

Permalink
feat: added deleteCalendar option
Browse files Browse the repository at this point in the history
  • Loading branch information
titanism committed Sep 2, 2024
1 parent 97a0ebd commit 482e9da
Showing 1 changed file with 19 additions and 23 deletions.
42 changes: 19 additions & 23 deletions routes/calendar/calendar/delete.js
Original file line number Diff line number Diff line change
@@ -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 = '';
};
Expand Down

0 comments on commit 482e9da

Please sign in to comment.