mirror of
https://github.com/nfonteyne/octane-website.git
synced 2026-09-03 23:24:48 +02:00
update: description in ics shared calendar, and realtive display depending on the votes
This commit is contained in:
parent
5759a1f248
commit
212016e88f
10 changed files with 92 additions and 25 deletions
|
|
@ -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);
|
||||
})
|
||||
|
|
|
|||
|
|
@ -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 }));
|
||||
})
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
}))
|
||||
);
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue