mirror of
https://github.com/nfonteyne/octane-website.git
synced 2026-09-03 23:24:48 +02:00
update: better view concert history
This commit is contained in:
parent
0773f39763
commit
a09d16238b
7 changed files with 80 additions and 26 deletions
|
|
@ -14,8 +14,8 @@ function setRunning() {
|
|||
state = { status: 'running', triggeredAt: new Date().toISOString(), message: null, node: null };
|
||||
}
|
||||
|
||||
function setSuccess() {
|
||||
state = { ...state, status: 'success', message: null, node: null };
|
||||
function setSuccess(message) {
|
||||
state = { ...state, status: 'success', message: message || null, node: null };
|
||||
}
|
||||
|
||||
function setError(message, node) {
|
||||
|
|
|
|||
|
|
@ -29,8 +29,15 @@ async function upsertPerson(client, name) {
|
|||
return rows[0].id;
|
||||
}
|
||||
|
||||
// Returns ingestion counts so callers can surface a diagnostic (e.g. "12
|
||||
// slots but 0 availability rows" points at a payload-shape mismatch from
|
||||
// n8n, since a slot with no matching calendar_availability rows is silently
|
||||
// excluded from getSlots() below — it would otherwise look like "nothing
|
||||
// happened" with no error anywhere.
|
||||
async function ingestSlots(slots) {
|
||||
const client = await pool.connect();
|
||||
let availabilityRows = 0;
|
||||
let slotsWithNoPeople = 0;
|
||||
try {
|
||||
await client.query('BEGIN');
|
||||
for (const slot of slots) {
|
||||
|
|
@ -51,10 +58,23 @@ async function ingestSlots(slots) {
|
|||
const slotId = slotRows[0].id;
|
||||
|
||||
// people may arrive as a JSON string from n8n's Set-node serialization.
|
||||
const people = typeof slot.people === 'string' ? JSON.parse(slot.people) : slot.people || [];
|
||||
let people = typeof slot.people === 'string' ? JSON.parse(slot.people) : slot.people || [];
|
||||
if (!Array.isArray(people)) people = [];
|
||||
|
||||
if (people.length === 0) {
|
||||
slotsWithNoPeople += 1;
|
||||
console.warn('[calendar] ingest: slot has no people entries', {
|
||||
lower: slot.lower,
|
||||
upper: slot.upper,
|
||||
rawPeopleType: typeof slot.people,
|
||||
});
|
||||
}
|
||||
|
||||
for (const person of people) {
|
||||
if (!person || !person.name) continue;
|
||||
if (!person || !person.name) {
|
||||
console.warn('[calendar] ingest: skipped a person entry with no "name" field', person);
|
||||
continue;
|
||||
}
|
||||
const personId = await upsertPerson(client, person.name);
|
||||
await client.query(
|
||||
`INSERT INTO calendar_availability (slot_id, person_id, is_available, checked_at)
|
||||
|
|
@ -64,6 +84,7 @@ async function ingestSlots(slots) {
|
|||
checked_at = excluded.checked_at`,
|
||||
[slotId, personId, !!person.available]
|
||||
);
|
||||
availabilityRows += 1;
|
||||
}
|
||||
}
|
||||
await client.query('COMMIT');
|
||||
|
|
@ -73,6 +94,10 @@ async function ingestSlots(slots) {
|
|||
} finally {
|
||||
client.release();
|
||||
}
|
||||
|
||||
const summary = { slotsProcessed: slots.length, availabilityRows, slotsWithNoPeople };
|
||||
console.log('[calendar] ingest summary:', summary);
|
||||
return summary;
|
||||
}
|
||||
|
||||
async function getSlots({ minPeople = 1, personIds = null, weeks = 3 } = {}) {
|
||||
|
|
|
|||
|
|
@ -78,12 +78,16 @@ router.post('/refresh', (req, res) => {
|
|||
|
||||
const data = await response.json();
|
||||
if (!Array.isArray(data.slots)) {
|
||||
console.error('[calendar] n8n response had no "slots" array. Raw body:', JSON.stringify(data).slice(0, 500));
|
||||
workflowState.setError('Unexpected response format from n8n');
|
||||
return;
|
||||
}
|
||||
|
||||
await calendarRepo.ingestSlots(data.slots);
|
||||
workflowState.setSuccess();
|
||||
const summary = await calendarRepo.ingestSlots(data.slots);
|
||||
workflowState.setSuccess(
|
||||
`${summary.slotsProcessed} créneaux reçus, ${summary.availabilityRows} disponibilités enregistrées` +
|
||||
(summary.slotsWithNoPeople > 0 ? ` (${summary.slotsWithNoPeople} créneaux sans aucune personne — voir les logs serveur)` : '')
|
||||
);
|
||||
} catch (err) {
|
||||
clearTimeout(watchdog);
|
||||
const message = err.name === 'AbortError' ? 'n8n did not respond within 5 minutes' : err.message;
|
||||
|
|
|
|||
|
|
@ -21,9 +21,11 @@ router.post(
|
|||
return res.status(400).json({ error: 'expected_array_of_slots' });
|
||||
}
|
||||
try {
|
||||
await calendarRepo.ingestSlots(slots);
|
||||
workflowState.setSuccess();
|
||||
res.json({ ok: true, count: slots.length });
|
||||
const summary = await calendarRepo.ingestSlots(slots);
|
||||
workflowState.setSuccess(
|
||||
`${summary.slotsProcessed} créneaux reçus, ${summary.availabilityRows} disponibilités enregistrées`
|
||||
);
|
||||
res.json({ ok: true, ...summary });
|
||||
} catch (err) {
|
||||
workflowState.setError(err.message);
|
||||
res.status(500).json({ error: err.message });
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue