From c80064f1352e5150fa7d627c2ac7157f294fc37e Mon Sep 17 00:00:00 2001 From: Ryan Mwangi Date: Mon, 14 Oct 2024 15:54:41 +0300 Subject: [PATCH] Write the updated data back to calendars.json --- server.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/server.js b/server.js index cae56e1..ed6d94f 100644 --- a/server.js +++ b/server.js @@ -139,10 +139,19 @@ function addLinkToGroup(linkGroup, url, prefix, overrideSummary) { // Add the new link to the calendarData object let linkGroup = calendarData.linkGroups.find((group) => group.name === linkGroupName); if (!linkGroup) { - linkGroup = addLinkGroup(linkGroupName); - } - addLinkToGroup(linkGroup, linkUrl, prefix, overrideSummary); - + linkGroup = { + name: linkGroupName, + links: [] + }; + calendarsData.linkGroups.push(linkGroup); + } + linkGroup.links.push({ + url: linkUrl, + prefix, + overrideSummary + }); + // Write the updated data back to calendars.json + fs.writeFileSync(calendarsFile, JSON.stringify(calendarsData, null, 2)); res.json({ message: 'Link added successfully!' }); });