lambdabaa / dav

WebDAV, CalDAV, and CardDAV client for nodejs and the browser.
Mozilla Public License 2.0
304 stars 71 forks source link

Is it possible to clear all objects from a specific calendar? #146

Open mikenussbaumer opened 4 years ago

mikenussbaumer commented 4 years ago

Hey!

Is there a way to reset / clear a calendar?

I tried to run this code:

const dav = require('dav');

var xhr = new dav.transport.Basic(
    new dav.Credentials({
        username: '****USER****',
        password: '****PASSWORD****'
    })
);

var client = new dav.Client(xhr);

client.createAccount({
    server: '****SERVER URL****',
    accountType: 'caldav',
    loadObjects: true
}).then((account) => {
    const calendar = account.calendars[0];

    // get all events from calendar
    calendar.objects.forEach((calendarObject) => {
        // remove current event from calendar
        client.deleteCalendarObject(calendarObject, {
            xhr: xhr
        });
    });
});

to remove all objects of a calendar, but unfortunately it does not work properly, im always getting this error:

(node:7783) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 335)
(node:7783) UnhandledPromiseRejectionWarning: Error: Bad status: 412

Maybe anyone here can help me :)

Thanks, Mike