refactor: Make into own variable

Signed-off-by: Tim Hårek Andreassen <tim@harek.no>
This commit is contained in:
Tim Hårek Andreassen 2024-04-08 17:14:48 +02:00
parent cd8df3284a
commit 48eade901a
No known key found for this signature in database
GPG Key ID: E59C7734F0E10EB5
1 changed files with 9 additions and 7 deletions

View File

@ -32,16 +32,18 @@ async function updateFetch(existingSeries: Series): Promise<UpdatedSeries | null
return !existingSeries.episodes.find((serieEpisode) => serieEpisode.id === episode.id);
});
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),
const episodesSorted = [...newEpisodes, ...existingSeries.episodes]
.sort((a, b) => a.date.getTime() > b.date.getTime() ? -1 : 1);
const updated = {
...existingSeries,
lastFetch: new Date(),
episodes: episodesSorted,
};
const updateSuccessful = await storage.write(updated);