refactor: Make into own variable
Signed-off-by: Tim Hårek Andreassen <tim@harek.no>
This commit is contained in:
parent
cd8df3284a
commit
48eade901a
|
|
@ -32,16 +32,18 @@ async function updateFetch(existingSeries: Series): Promise<UpdatedSeries | null
|
||||||
return !existingSeries.episodes.find((serieEpisode) => serieEpisode.id === episode.id);
|
return !existingSeries.episodes.find((serieEpisode) => serieEpisode.id === episode.id);
|
||||||
});
|
});
|
||||||
|
|
||||||
const updated = {
|
|
||||||
...existingSeries,
|
|
||||||
lastFetch: new Date(),
|
|
||||||
/**
|
/**
|
||||||
* Since we don't control the API,
|
* Since we don't control the API,
|
||||||
* we should not make assumptions about the order,
|
* we should not make assumptions about the order,
|
||||||
* but rather sort the episode to what we want.
|
* but rather sort the episode to what we want.
|
||||||
*/
|
*/
|
||||||
episodes: [...newEpisodes, ...existingSeries.episodes]
|
const episodesSorted = [...newEpisodes, ...existingSeries.episodes]
|
||||||
.sort((a, b) => a.date.getTime() > b.date.getTime() ? -1 : 1),
|
.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);
|
const updateSuccessful = await storage.write(updated);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue