Merge pull request #8 from quoije/cursor/movie-update-frontend-issue-06ef

Movie update frontend issue
This commit was merged in pull request #8.
This commit is contained in:
Mathieu Moran
2025-12-20 18:02:30 -05:00
committed by GitHub
2 changed files with 31 additions and 1 deletions
+27
View File
@@ -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(); const activeYear = await fetchActiveYear();
document.title = `Pool Oscars ${activeYear} - Films`; document.title = `Pool Oscars ${activeYear} - Films`;
const oscarYearEl = document.getElementById('oscar-year'); const oscarYearEl = document.getElementById('oscar-year');
@@ -46,6 +70,9 @@ window.onload = async function () {
window.location.href = '/'; 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))}`, { const res = await fetch(`/api/movies?year=${encodeURIComponent(String(activeYear))}`, {
method: 'GET', method: 'GET',
headers: { 'Authorization': `Bearer ${token}` }, headers: { 'Authorization': `Bearer ${token}` },
+4 -1
View File
@@ -73,7 +73,10 @@ router.get("/last-update", async (req, res) => {
try { try {
jwt.verify(token, process.env.JWT_SECRET); 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) { if (!latestMovie) {
return res.status(200).json({ lastUpdated: null }); return res.status(200).json({ lastUpdated: null });
} }