Files
Convivo/apps/sidecar/src/transform-excel.js
T
ec23da9bb9 feat(sessions): import language tag from Sessionize Language category
Sabrina's backlog: show a per-session delivery language in the sessions
overview. Sessionize has no native language field (verified live), so the
sidecar now resolves each session's categoryItems against a session
category titled "Language" (Sessionize's own demo-endpoint pattern) and
ships it as a plain string; a native session.language wins if it ever
appears.

- migration 20261021090000: sessions.language + re-created
  get_agenda / sync_sessionize_event / sync_sessionize_excel. Language
  upserts with the same coalesce(excluded, existing) rule as level/area,
  so a source without language never erases it. get_agenda is dropped +
  re-created (OUT shape change) and re-granted to anon/authenticated.
- sidecar: transform extracted to sessionize-transform.js (unit-tested);
  Excel import gains Language / Sprache / "Sprache / Language" headers.
- attendee app: third agenda filter dropdown ("All languages", only
  rendered when values exist) + language pill in SessionDetail.
- admin app: Sessions search + subtitle include language.
- seed: English for all talks, German for the two German-titled sessions.
- tests: session_language_tests.sql (8 assertions, all pass),
  sessionize-transform.test.js (7), transform-excel Language case; 43/43
  sidecar tests, date-guard/gridsmart/session-persistence suites green.
- docs: schema.md sessions columns + next-steps.md completion entry.

Organizer precondition (Sabrina): define the "Language" category AND
enable session custom fields on the event's API/Embed page, otherwise
live syncs keep language null (Excel import is the fallback).

Co-authored-by: Stephan Charles <[email protected]>
Co-authored-by: Amelia Hernandez <[email protected]>
Co-authored-by: Markus Franz <[email protected]>
Co-authored-by: Sabrina Hota <[email protected]>
Co-authored-by: Nilüfer Doğan <[email protected]>
2026-10-20 22:55:24 +02:00

109 lines
4.4 KiB
JavaScript

const XLSX = require('xlsx');
const { createHash } = require('node:crypto');
function excelSerialToTime(serial, durationMin) {
const ms = Math.round((serial - 25569) * 86400 * 1000);
const date = new Date(ms);
const end = new Date(ms + (durationMin || 0) * 60 * 1000);
return {
date: date.toISOString().slice(0, 10),
start_time: date.toISOString().slice(11, 19),
end_time: end.toISOString().slice(11, 19),
};
}
function firstNonempty(row, headers) {
for (const header of headers) {
const value = String(row[header.toLowerCase()] ?? '').trim();
if (value) return value;
}
return '';
}
function transformExcel(buffer) {
const workbook = XLSX.read(buffer, { type: 'buffer' });
const readRows = (sheetName) => sheetName
? XLSX.utils.sheet_to_json(workbook.Sheets[sheetName], { defval: '' }).map((row) =>
Object.fromEntries(Object.entries(row).map(([header, value]) => [header.trim().toLowerCase(), value])))
: [];
const toRows = (kind, otherKind) => {
const sheetNames = workbook.SheetNames.filter((name) =>
kind !== 'session' || !name.toLowerCase().includes('service'));
const sheetName = sheetNames.find((name) =>
name.toLowerCase().includes(kind) && !name.toLowerCase().includes(otherKind))
|| sheetNames.find((name) => name.toLowerCase().includes(kind));
return readRows(sheetName);
};
const speakerById = new Map();
const speakersByEmail = new Map();
for (const row of toRows('speaker', 'session')) {
const id = firstNonempty(row, ['Speaker Id']);
const email = firstNonempty(row, ['Email']);
const fullName = [firstNonempty(row, ['FirstName']), firstNonempty(row, ['LastName'])]
.filter(Boolean).join(' ');
if (!id || !email || !fullName) continue;
speakerById.set(id, email);
if (!speakersByEmail.has(email)) {
speakersByEmail.set(email, {
email,
full_name: fullName,
external_id: id,
linkedin_url: firstNonempty(row, ['LinkedIn']) || null,
});
}
}
const sessionsById = new Map();
const serviceSheet = workbook.SheetNames.find((name) => name.trim().toLowerCase() === 'service sessions');
const sessionRows = [
...toRows('session', 'speaker').map((row) => ({ row, serviceSheet: false })),
...readRows(serviceSheet).map((row) => ({ row, serviceSheet: true })),
];
for (const entry of sessionRows) {
const { row } = entry;
const title = firstNonempty(row, ['Title']);
const scheduledAt = Number(row['scheduled at']);
const duration = Number(row['scheduled duration']);
if (!title || !Number.isFinite(scheduledAt) || scheduledAt <= 0) continue;
const isServiceSession = entry.serviceSheet
|| /service|break|lunch|closing|plenum/i.test(firstNonempty(row, ['Session Format']));
const room = firstNonempty(row, ['Room']) || null;
const timing = excelSerialToTime(scheduledAt, Number.isFinite(duration) ? duration : 0);
const id = firstNonempty(row, ['Session Id']) || (isServiceSession
? `excel-service:${createHash('sha256').update(JSON.stringify([title, room, timing.date, timing.start_time])).digest('hex')}`
: '');
if (!id) continue;
const area = firstNonempty(row, ['Themenfeld / Area of Topic', 'Area', 'Topic']) || null;
// Sessionize exports a Language column when the event uses its language
// feature (German UI: "Sprache / Language").
const language = firstNonempty(row, ['Sprache / Language', 'Language', 'Sprache']) || null;
if (!sessionsById.has(id)) {
sessionsById.set(id, {
external_id: id,
title,
description: firstNonempty(row, ['Description']) || null,
room,
...timing,
is_service_session: isServiceSession,
level: firstNonempty(row, ['Level']) || null,
area,
language,
speakers: [],
});
}
const session = sessionsById.get(id);
if (!session.area && area) session.area = area;
if (!session.language && language) session.language = language;
const speakerIds = firstNonempty(row, ['Speaker Ids', 'Speaker Id'])
.split(',').map((speakerId) => speakerId.trim()).filter(Boolean);
for (const speakerId of speakerIds) {
const email = speakerById.get(speakerId);
if (email && !session.speakers.includes(email)) session.speakers.push(email);
}
}
return { payload: { speakers: [...speakersByEmail.values()], sessions: [...sessionsById.values()] } };
}
module.exports = { transformExcel };