feat: Show last updated movies per year
Add API and UI to display the last updated movies for the active year. Co-authored-by: mathieumoran1 <[email protected]>
This commit is contained in:
co-authored by
mathieumoran1
parent
03a4b4e5dc
commit
6cb503fe35
@@ -11,6 +11,30 @@ window.onload = async function () {
|
||||
}
|
||||
}
|
||||
|
||||
async function fetchMoviesLastUpdated(year, token) {
|
||||
const el = document.getElementById('movies-last-updated');
|
||||
if (!el) return;
|
||||
|
||||
try {
|
||||
const res = await fetch(`/api/movies/last-update?year=${encodeURIComponent(String(year))}`, {
|
||||
method: 'GET',
|
||||
headers: { 'Authorization': `Bearer ${token}` },
|
||||
});
|
||||
if (!res.ok) return;
|
||||
|
||||
const data = await res.json();
|
||||
const lastUpdatedIso = data?.lastUpdated;
|
||||
if (!lastUpdatedIso) return;
|
||||
|
||||
const d = new Date(lastUpdatedIso);
|
||||
if (Number.isNaN(d.getTime())) return;
|
||||
|
||||
el.textContent = d.toLocaleString('fr-FR', { dateStyle: 'medium', timeStyle: 'short' });
|
||||
} catch (_) {
|
||||
// Keep the default placeholder (—)
|
||||
}
|
||||
}
|
||||
|
||||
const activeYear = await fetchActiveYear();
|
||||
document.title = `Pool Oscars ${activeYear} - Films`;
|
||||
const oscarYearEl = document.getElementById('oscar-year');
|
||||
@@ -46,6 +70,9 @@ window.onload = async function () {
|
||||
window.location.href = '/';
|
||||
}
|
||||
|
||||
// Populate "Dernière mise à jour des films" banner (per active year)
|
||||
await fetchMoviesLastUpdated(activeYear, token);
|
||||
|
||||
const res = await fetch(`/api/movies?year=${encodeURIComponent(String(activeYear))}`, {
|
||||
method: 'GET',
|
||||
headers: { 'Authorization': `Bearer ${token}` },
|
||||
|
||||
+4
-1
@@ -73,7 +73,10 @@ router.get("/last-update", async (req, res) => {
|
||||
try {
|
||||
jwt.verify(token, process.env.JWT_SECRET);
|
||||
|
||||
const latestMovie = await Movie.findOne().sort({ updatedAt: -1, createdAt: -1, _id: -1 });
|
||||
const year = parseOscarYear(req.query.year);
|
||||
const filter = year ? { year } : {};
|
||||
|
||||
const latestMovie = await Movie.findOne(filter).sort({ updatedAt: -1, createdAt: -1, _id: -1 });
|
||||
if (!latestMovie) {
|
||||
return res.status(200).json({ lastUpdated: null });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user