From 03493e34f1c526e0e0586841de9fbeab0b14c0a7 Mon Sep 17 00:00:00 2001 From: Ryan Mwangi Date: Mon, 14 Oct 2024 15:49:20 +0300 Subject: [PATCH] read existing data from calendars.json --- server.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/server.js b/server.js index 43d4507..cae56e1 100644 --- a/server.js +++ b/server.js @@ -128,7 +128,14 @@ function addLinkToGroup(linkGroup, url, prefix, overrideSummary) { //adding the new link to the calendarData object app.post('/add-link', (req, res) => { const { linkGroupName, linkUrl, prefix, overrideSummary } = req.body; - + // Read the existing data from calendars.json + const calendarsFile = 'calendars.json'; + let calendarsData = {}; + try { + calendarsData = JSON.parse(fs.readFileSync(calendarsFile, 'utf8')); + } catch (error) { + console.error(error); + } // Add the new link to the calendarData object let linkGroup = calendarData.linkGroups.find((group) => group.name === linkGroupName); if (!linkGroup) {