From e4ab506abe68a4eecb1e91d940f4e367d164a666 Mon Sep 17 00:00:00 2001 From: Corban-Lee Jones Date: Fri, 2 May 2025 11:13:28 +0100 Subject: [PATCH] fix(api): patching feeds would duplicate channels #4 --- .../controllers/guild/api/feed.controller.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/server/controllers/guild/api/feed.controller.ts b/src/server/controllers/guild/api/feed.controller.ts index 812f5ee..974f55a 100644 --- a/src/server/controllers/guild/api/feed.controller.ts +++ b/src/server/controllers/guild/api/feed.controller.ts @@ -59,9 +59,12 @@ export const patch = async (request: Request, response: Response) => { const { id, name, url, active, channels } = request.body; // channels comes through as either String[] or String - const formattedChannels = Array.isArray(channels) - ? channels.map((channelId) => ({ channel_id: channelId })) - : [{ channel_id: channels }] + let formattedChannels = undefined; + if (channels !== undefined) { + formattedChannels = Array.isArray(channels) + ? channels.map((channelId) => ({ channel_id: channelId })) + : [{ channel_id: channels }] + } let feed; @@ -73,7 +76,10 @@ export const patch = async (request: Request, response: Response) => { url: url, guild_id: guildId, active: active === "on", - channels: channels !== undefined ? { create: formattedChannels } : channels + channels: { + deleteMany: {}, + create: formattedChannels + } } }); }