update: description in ics shared calendar, and realtive display depending on the votes

This commit is contained in:
Nathan FONTEYNE 2026-07-31 11:51:05 +02:00
parent 5759a1f248
commit 212016e88f
10 changed files with 92 additions and 25 deletions

View file

@ -187,6 +187,7 @@ router.get(
marginMinutes: settings.marginMinutes,
concertStart: formatTime(settings.concert.startHour, settings.concert.startMinute),
concertEnd: formatTime(settings.concert.endHour, settings.concert.endMinute),
rehearsalConfirmThreshold: settings.rehearsalConfirmThreshold,
});
})
);
@ -213,7 +214,7 @@ router.patch(
'/settings',
requireAdmin,
asyncHandler(async (req, res) => {
const { weekdayStart, weekdayEnd, weekendStart, weekendEnd, marginMinutes, concertStart, concertEnd } = req.body || {};
const { weekdayStart, weekdayEnd, weekendStart, weekendEnd, marginMinutes, concertStart, concertEnd, rehearsalConfirmThreshold } = req.body || {};
const times = { weekdayStart, weekdayEnd, weekendStart, weekendEnd, concertStart, concertEnd };
for (const [key, value] of Object.entries(times)) {
if (!TIME_RE.test(value || '')) {
@ -233,8 +234,12 @@ router.patch(
if (!Number.isInteger(margin) || margin < 0 || margin > 180) {
return res.status(400).json({ error: 'invalid_margin_minutes' });
}
const threshold = Number(rehearsalConfirmThreshold);
if (!Number.isInteger(threshold) || threshold < 1 || threshold > 50) {
return res.status(400).json({ error: 'invalid_rehearsal_confirm_threshold' });
}
const values = { ...times, marginMinutes: margin };
const values = { ...times, marginMinutes: margin, rehearsalConfirmThreshold: threshold };
await calendarRepo.updateSlotSettings(values);
res.json(values);
})

View file

@ -5,6 +5,7 @@
const express = require('express');
const usersRepo = require('../repositories/usersRepo');
const rehearsalsRepo = require('../repositories/rehearsalsRepo');
const calendarRepo = require('../repositories/calendarRepo');
const { buildRehearsalsFeed } = require('../lib/icsFeed');
const asyncHandler = require('../lib/asyncHandler');
@ -16,10 +17,12 @@ router.get(
const user = await usersRepo.findByIcsToken(req.params.token);
if (!user) return res.status(404).send('Not found');
const rehearsals = await rehearsalsRepo.findUpcoming();
const [rehearsals, settings] = await Promise.all([rehearsalsRepo.findUpcoming(), calendarRepo.getSlotSettings()]);
// req.protocol honors X-Forwarded-Proto here — see app.set('trust proxy', 1) in app.js.
const baseUrl = `${req.protocol}://${req.get('host')}`;
res
.type('text/calendar; charset=utf-8')
.send(buildRehearsalsFeed(rehearsals));
.send(buildRehearsalsFeed(rehearsals, { threshold: settings.rehearsalConfirmThreshold, baseUrl }));
})
);

View file

@ -1,14 +1,17 @@
const express = require('express');
const rehearsalsRepo = require('../repositories/rehearsalsRepo');
const calendarRepo = require('../repositories/calendarRepo');
const discord = require('../lib/discord');
const asyncHandler = require('../lib/asyncHandler');
const { computeRehearsalStatus } = require('../lib/rehearsalStatus');
const router = express.Router();
router.get(
'/',
asyncHandler(async (req, res) => {
const rehearsals = await rehearsalsRepo.findUpcoming();
const [rehearsals, settings] = await Promise.all([rehearsalsRepo.findUpcoming(), calendarRepo.getSlotSettings()]);
const threshold = settings.rehearsalConfirmThreshold;
res.json(
rehearsals.map((r) => ({
id: r.id,
@ -18,6 +21,8 @@ router.get(
proposedBy: r.proposed_by,
proposedByName: r.proposed_by_name,
votes: r.votes,
status: computeRehearsalStatus(r.votes, threshold),
confirmThreshold: threshold,
}))
);
})