From 48eade901a29b601f364a107e8d533134ff2a5e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20H=C3=A5rek=20Andreassen?= Date: Mon, 8 Apr 2024 17:14:48 +0200 Subject: [PATCH] refactor: Make into own variable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Tim HÄrek Andreassen --- lib/caching.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/caching.ts b/lib/caching.ts index b0c46f8..f72860e 100644 --- a/lib/caching.ts +++ b/lib/caching.ts @@ -32,16 +32,18 @@ async function updateFetch(existingSeries: Series): Promise serieEpisode.id === episode.id); }); + /** + * Since we don't control the API, + * we should not make assumptions about the order, + * but rather sort the episode to what we want. + */ + const episodesSorted = [...newEpisodes, ...existingSeries.episodes] + .sort((a, b) => a.date.getTime() > b.date.getTime() ? -1 : 1); + const updated = { ...existingSeries, lastFetch: new Date(), - /** - * Since we don't control the API, - * we should not make assumptions about the order, - * but rather sort the episode to what we want. - */ - episodes: [...newEpisodes, ...existingSeries.episodes] - .sort((a, b) => a.date.getTime() > b.date.getTime() ? -1 : 1), + episodes: episodesSorted, }; const updateSuccessful = await storage.write(updated);