Post-event reporting + talk networking incentives
- Talk networking: per-event talk_networking_bonus awarded when two people who shared a checked-in talk accept a connection (accept_connection re-created, shared_talk flag, get_talk_cohort RPC, points_log category check widened); Convivo Networking sub-tab inside the Connect screen (Home quick action deep-links in; Connect button reflects existing connection state and is disabled for sent/connected/declined); admin Events view bonus input (0-10). - Reports: sidecar POST /export (CSV / multi-sheet XLSX / PDF report via new pdfkit dep); APPE Admin Reports view (any event: on-screen summary, session feedback summary, top-5, CSV/Excel/PDF downloads); Activity session-feedback per-session aggregate header. - Also carried: @appe.at admin trigger + default password, bulk contact delete, session level/area + event-level feedback, agenda level/area filters, admin password self-service, schedule level/area fields. - 18/18 RPC tests; both apps build; exports verified end-to-end. 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]>
This commit is contained in:
1 parent
f74db9dc26
commit
0b6d1f2b6f
35 files changed
+3973
-54
No files matched your search
Generated
+1188
File diff suppressed because it is too large.
Load diff
@@ -8,6 +8,7 @@
|
||||
"start": "node src/server.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"pdfkit": "^0.15.0",
|
||||
"xlsx": "^0.18.5"
|
||||
}
|
||||
}
|
||||
@@ -41,6 +41,7 @@
|
||||
|
||||
const http = require('http');
|
||||
const XLSX = require('xlsx');
|
||||
const PDFDocument = require('pdfkit');
|
||||
|
||||
const SUPABASE_URL = (process.env.SUPABASE_URL || 'http://supabase_kong_Convivo:8000').replace(/\/$/, '');
|
||||
const SERVICE_ROLE_KEY =
|
||||
@@ -275,6 +276,11 @@ function transform(data) {
|
||||
// A service session is a break/lunch/closing (isServiceSession) OR a
|
||||
// plenum (isPlenumSession) — plenums are full-hall items with no pick.
|
||||
is_service_session: Boolean(s.isServiceSession || s.isPlenumSession),
|
||||
// Level + area (free-text classification for agenda filtering).
|
||||
// Sessionize's public /view/ endpoint may not expose these; if present
|
||||
// (e.g. via a custom field or a future API version) we capture them.
|
||||
level: (s.level || '').trim() || null,
|
||||
area: (s.area || s.topic || '').trim() || null,
|
||||
speakers: speakerEmails,
|
||||
});
|
||||
}
|
||||
@@ -351,6 +357,11 @@ function transformExcel(buffer) {
|
||||
start_time,
|
||||
end_time,
|
||||
is_service_session: /service|break|lunch|closing|plenum/i.test(String(r['Session Format'] ?? '')),
|
||||
// Level + area (free-text classification for agenda filtering).
|
||||
// The Sessionize "Sessions and speakers (advanced)" .xlsx may include
|
||||
// "Level" and "Area"/"Topic" columns; we read them if present.
|
||||
level: String(r['Level'] ?? '').trim() || null,
|
||||
area: String(r['Area'] ?? r['Topic'] ?? '').trim() || null,
|
||||
speakers: speakerEmails,
|
||||
});
|
||||
}
|
||||
@@ -584,6 +595,301 @@ async function runPretixLoop() {
|
||||
}
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
// POST /export — event reports (CSV / XLSX / PDF)
|
||||
//
|
||||
// Fetches an event's full dataset (service role) and renders it as:
|
||||
// * csv — one combined CSV (a `table` column distinguishes the rows)
|
||||
// * xlsx — one workbook, one sheet per table
|
||||
// * pdf — a structured post-event report (summary + per-session + top points)
|
||||
// Returns { filename, mime, content_base64 }.
|
||||
// =============================================================================
|
||||
|
||||
// The tables an export can include (CSV/XLSX). The PDF always uses all of them.
|
||||
const EXPORT_TABLES = [
|
||||
'registrations',
|
||||
'checkins',
|
||||
'connections',
|
||||
'session_feedback',
|
||||
'event_feedback',
|
||||
'leaderboard',
|
||||
'points_log',
|
||||
];
|
||||
|
||||
// Escape a single CSV cell (RFC 4180).
|
||||
function csvCell(v) {
|
||||
const s = v == null ? '' : String(v);
|
||||
return /[",\n\r]/.test(s) ? '"' + s.replace(/"/g, '""') + '"' : s;
|
||||
}
|
||||
|
||||
// Render an array of flat row objects as a single CSV string.
|
||||
function rowsToCsv(rows) {
|
||||
if (rows.length === 0) return '';
|
||||
const headers = Object.keys(rows[0]);
|
||||
const lines = [headers.map(csvCell).join(',')];
|
||||
for (const r of rows) lines.push(headers.map((h) => csvCell(r[h])).join(','));
|
||||
return lines.join('\n');
|
||||
}
|
||||
|
||||
// Fetch the event's full dataset (service role), joined for readability.
|
||||
async function fetchEventDataset(eventId) {
|
||||
const events = await supabaseFetch(
|
||||
`/rest/v1/events?id=eq.${encodeURIComponent(eventId)}&select=*`,
|
||||
);
|
||||
const event = Array.isArray(events) ? events[0] : null;
|
||||
if (!event) throw new Error('event not found');
|
||||
|
||||
const [contacts, regs, checkins, connections, feedback, eventFeedback, leaderboard, pointsLog, sessions] =
|
||||
await Promise.all([
|
||||
supabaseFetch('/rest/v1/contacts?select=email,full_name'),
|
||||
supabaseFetch(`/rest/v1/registrations?event_id=eq.${encodeURIComponent(eventId)}&select=*`),
|
||||
supabaseFetch(`/rest/v1/checkins?event_id=eq.${encodeURIComponent(eventId)}&select=*`),
|
||||
supabaseFetch(`/rest/v1/connections?event_id=eq.${encodeURIComponent(eventId)}&select=*`),
|
||||
supabaseFetch(`/rest/v1/feedback?event_id=eq.${encodeURIComponent(eventId)}&select=*`),
|
||||
supabaseFetch(`/rest/v1/event_feedback?event_id=eq.${encodeURIComponent(eventId)}&select=*`),
|
||||
supabaseFetch(`/rest/v1/leaderboard?event_id=eq.${encodeURIComponent(eventId)}&select=*`),
|
||||
supabaseFetch(`/rest/v1/points_log?event_id=eq.${encodeURIComponent(eventId)}&select=*`),
|
||||
supabaseFetch(`/rest/v1/sessions?event_id=eq.${encodeURIComponent(eventId)}&select=*`),
|
||||
]);
|
||||
|
||||
const nameOf = new Map((Array.isArray(contacts) ? contacts : []).map((c) => [c.email, c.full_name]));
|
||||
const sessionTitle = new Map((Array.isArray(sessions) ? sessions : []).map((s) => [s.id, s.title]));
|
||||
const titleOf = (id) => sessionTitle.get(id) ?? id ?? '';
|
||||
const name = (email) => nameOf.get(email) ?? email ?? '';
|
||||
|
||||
return {
|
||||
event,
|
||||
registrations: (Array.isArray(regs) ? regs : []).map((r) => ({
|
||||
email: r.contact_email,
|
||||
name: name(r.contact_email),
|
||||
type: r.type,
|
||||
checked_in: r.checked_in,
|
||||
points: r.points,
|
||||
qr_token: r.qr_token,
|
||||
})),
|
||||
checkins: (Array.isArray(checkins) ? checkins : []).map((c) => ({
|
||||
email: c.contact_email,
|
||||
name: name(c.contact_email),
|
||||
session: titleOf(c.session_id),
|
||||
checked_in_by: name(c.staff_email),
|
||||
when: c.created_at,
|
||||
})),
|
||||
connections: (Array.isArray(connections) ? connections : []).map((c) => ({
|
||||
from: name(c.from_email),
|
||||
to: name(c.to_email),
|
||||
status: c.status,
|
||||
when: c.created_at,
|
||||
})),
|
||||
sessionFeedback: (Array.isArray(feedback) ? feedback : []).map((f) => ({
|
||||
email: f.contact_email,
|
||||
name: name(f.contact_email),
|
||||
session: titleOf(f.session_id),
|
||||
rating: f.rating,
|
||||
comment: f.comment,
|
||||
when: f.created_at,
|
||||
})),
|
||||
eventFeedback: (Array.isArray(eventFeedback) ? eventFeedback : []).map((f) => ({
|
||||
email: f.contact_email,
|
||||
name: name(f.contact_email),
|
||||
rating: f.rating,
|
||||
comment: f.comment,
|
||||
when: f.created_at,
|
||||
})),
|
||||
leaderboard: (Array.isArray(leaderboard) ? leaderboard : [])
|
||||
.sort((a, b) => (b.points ?? 0) - (a.points ?? 0))
|
||||
.map((l) => ({ name: l.full_name ?? name(l.contact_email), points: l.points })),
|
||||
pointsLog: (Array.isArray(pointsLog) ? pointsLog : []).map((l) => ({
|
||||
email: l.contact_email,
|
||||
name: name(l.contact_email),
|
||||
delta: l.delta,
|
||||
category: l.category,
|
||||
when: l.created_at,
|
||||
})),
|
||||
};
|
||||
}
|
||||
|
||||
// Build the combined CSV (a `table` column distinguishes the rows).
|
||||
function buildCsv(ds, tables) {
|
||||
const source = {
|
||||
registrations: ds.registrations,
|
||||
checkins: ds.checkins,
|
||||
connections: ds.connections,
|
||||
session_feedback: ds.sessionFeedback,
|
||||
event_feedback: ds.eventFeedback,
|
||||
leaderboard: ds.leaderboard,
|
||||
points_log: ds.pointsLog,
|
||||
};
|
||||
const chunks = [];
|
||||
for (const t of tables) {
|
||||
const rows = source[t] || [];
|
||||
if (rows.length === 0) continue;
|
||||
const withTable = rows.map((r) => ({ table: t, ...r }));
|
||||
chunks.push(rowsToCsv(withTable));
|
||||
}
|
||||
return chunks.join('\n');
|
||||
}
|
||||
|
||||
// Build the multi-sheet XLSX workbook (one sheet per table).
|
||||
function buildXlsx(ds, tables) {
|
||||
const source = {
|
||||
registrations: ds.registrations,
|
||||
checkins: ds.checkins,
|
||||
connections: ds.connections,
|
||||
session_feedback: ds.sessionFeedback,
|
||||
event_feedback: ds.eventFeedback,
|
||||
leaderboard: ds.leaderboard,
|
||||
points_log: ds.pointsLog,
|
||||
};
|
||||
const wb = XLSX.utils.book_new();
|
||||
for (const t of tables) {
|
||||
const rows = source[t] || [];
|
||||
const ws = XLSX.utils.json_to_sheet(rows.length > 0 ? rows : [{ note: 'no data' }]);
|
||||
XLSX.utils.book_append_sheet(wb, ws, t.slice(0, 31));
|
||||
}
|
||||
const out = XLSX.write(wb, { bookType: 'xlsx', type: 'buffer' });
|
||||
return out;
|
||||
}
|
||||
|
||||
// Build the PDF post-event report.
|
||||
function buildPdf(ds) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const doc = new PDFDocument({ size: 'A4', margin: 48 });
|
||||
const buf = [];
|
||||
doc.on('data', (c) => buf.push(c));
|
||||
doc.on('end', () => resolve(Buffer.concat(buf)));
|
||||
doc.on('error', reject);
|
||||
|
||||
const ev = ds.event;
|
||||
const h2 = (t) => {
|
||||
doc.font('Helvetica-Bold').fontSize(13);
|
||||
doc.text(t, { continued: false });
|
||||
doc.moveDown(0.4);
|
||||
};
|
||||
const line = (label, value) => {
|
||||
doc.font('Helvetica').fontSize(10);
|
||||
doc.text(`${label}: `, { continued: true });
|
||||
doc.font('Helvetica-Bold').text(String(value), { continued: false });
|
||||
doc.moveDown(0.15);
|
||||
};
|
||||
|
||||
// Header.
|
||||
doc.font('Helvetica-Bold').fontSize(18).text(ev.name || 'Event report');
|
||||
doc.font('Helvetica').fontSize(10).fillColor('#555');
|
||||
const dates = `${ev.start_date} – ${ev.end_date}${ev.location ? ` · ${ev.location}` : ''}`;
|
||||
doc.text(dates);
|
||||
doc.moveDown(0.3);
|
||||
doc.text(`Generated ${new Date().toISOString()}`);
|
||||
doc.moveDown(0.8);
|
||||
doc.fillColor('#000');
|
||||
|
||||
// Summary.
|
||||
h2('Summary');
|
||||
const byType = {};
|
||||
for (const r of ds.registrations) byType[r.type] = (byType[r.type] || 0) + 1;
|
||||
line('Registrations', ds.registrations.length);
|
||||
line('By type', Object.keys(byType).length ? Object.entries(byType).map(([t, n]) => `${t} ${n}`).join(', ') : '—');
|
||||
line('Check-ins', ds.checkins.length);
|
||||
const accepted = ds.connections.filter((c) => c.status === 'accepted').length;
|
||||
line('Connections', `${ds.connections.length} (${accepted} accepted)`);
|
||||
const sf = ds.sessionFeedback;
|
||||
line('Session feedback', sf.length ? `${sf.length} (avg ${(sf.reduce((s, f) => s + f.rating, 0) / sf.length).toFixed(2)}★)` : '—');
|
||||
const ef = ds.eventFeedback;
|
||||
line('Event feedback', ef.length ? `${ef.length} (avg ${(ef.reduce((s, f) => s + f.rating, 0) / ef.length).toFixed(2)}★)` : '—');
|
||||
const catTotals = {};
|
||||
for (const l of ds.pointsLog) catTotals[l.category] = (catTotals[l.category] || 0) + l.delta;
|
||||
line('Points by category', Object.keys(catTotals).length ? Object.entries(catTotals).map(([c, n]) => `${c} +${n}`).join(', ') : '—');
|
||||
doc.moveDown(0.6);
|
||||
|
||||
// Per-session feedback.
|
||||
h2('Session feedback');
|
||||
if (sf.length === 0) {
|
||||
doc.font('Helvetica').fontSize(10).text('No session feedback.');
|
||||
} else {
|
||||
const bySession = {};
|
||||
for (const f of sf) {
|
||||
const e = (bySession[f.session] ||= { count: 0, sum: 0 });
|
||||
e.count += 1;
|
||||
e.sum += f.rating;
|
||||
}
|
||||
const rows = Object.entries(bySession)
|
||||
.map(([title, e]) => ({ title, avg: e.sum / e.count, count: e.count }))
|
||||
.sort((a, b) => b.avg - a.avg);
|
||||
doc.font('Helvetica-Bold').fontSize(9).text('Session', { continued: true }).text(' ', { continued: true });
|
||||
doc.text('Avg', { continued: true }).text(' ', { continued: true }).text('Responses');
|
||||
doc.moveDown(0.2);
|
||||
doc.font('Helvetica').fontSize(9);
|
||||
for (const r of rows) {
|
||||
doc.text(`${r.title} · ${r.avg.toFixed(2)}★ · ${r.count}`, { lineBreak: true });
|
||||
}
|
||||
}
|
||||
doc.moveDown(0.6);
|
||||
|
||||
// Top points.
|
||||
h2('Top points');
|
||||
if (ds.leaderboard.length === 0) {
|
||||
doc.font('Helvetica').fontSize(10).text('No points yet.');
|
||||
} else {
|
||||
doc.font('Helvetica').fontSize(9);
|
||||
ds.leaderboard.slice(0, 10).forEach((l, i) => {
|
||||
doc.text(`${i + 1}. ${l.name} · ${l.points} pts`, { lineBreak: true });
|
||||
});
|
||||
}
|
||||
doc.moveDown(0.6);
|
||||
|
||||
// Event-level feedback comments.
|
||||
h2('Event-level feedback');
|
||||
const comments = ef.filter((f) => f.comment).slice(0, 50);
|
||||
if (comments.length === 0) {
|
||||
doc.font('Helvetica').fontSize(10).text('No event-level comments.');
|
||||
} else {
|
||||
doc.font('Helvetica').fontSize(9);
|
||||
for (const c of comments) {
|
||||
const body = (c.comment || '').replace(/\s+/g, ' ').trim().slice(0, 200);
|
||||
doc.text(`• [${c.rating}★] ${c.name}: ${body}`, { lineBreak: true });
|
||||
doc.moveDown(0.15);
|
||||
}
|
||||
}
|
||||
|
||||
doc.end();
|
||||
});
|
||||
}
|
||||
|
||||
// The POST /export handler.
|
||||
async function handleExport(body) {
|
||||
const { event_id: eventId, format, tables } = body || {};
|
||||
if (!eventId) throw new Error('event_id is required');
|
||||
if (!['csv', 'xlsx', 'pdf'].includes(format)) throw new Error('format must be csv, xlsx, or pdf');
|
||||
|
||||
const ds = await fetchEventDataset(eventId);
|
||||
const slug = (ds.event.name || eventId).toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-|-$/g, '') || 'event';
|
||||
|
||||
if (format === 'pdf') {
|
||||
const buf = await buildPdf(ds);
|
||||
return { filename: `${slug}-report.pdf`, mime: 'application/pdf', content_base64: buf.toString('base64') };
|
||||
}
|
||||
|
||||
const selected = (Array.isArray(tables) && tables.length > 0 ? tables : EXPORT_TABLES).filter((t) =>
|
||||
EXPORT_TABLES.includes(t),
|
||||
);
|
||||
if (selected.length === 0) throw new Error('no valid tables selected');
|
||||
|
||||
if (format === 'csv') {
|
||||
const csv = buildCsv(ds, selected);
|
||||
return {
|
||||
filename: `${slug}-report.csv`,
|
||||
mime: 'text/csv;charset=utf-8',
|
||||
content_base64: Buffer.from(csv, 'utf8').toString('base64'),
|
||||
};
|
||||
}
|
||||
// xlsx
|
||||
const buf = buildXlsx(ds, selected);
|
||||
return {
|
||||
filename: `${slug}-report.xlsx`,
|
||||
mime: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
||||
content_base64: Buffer.from(buf).toString('base64'),
|
||||
};
|
||||
}
|
||||
|
||||
const server = http.createServer(async (req, res) => {
|
||||
const url = new URL(req.url, `http://${req.headers.host || 'localhost'}`);
|
||||
const path = url.pathname;
|
||||
@@ -632,6 +938,11 @@ const server = http.createServer(async (req, res) => {
|
||||
const organizers = await fetchPretixOptions(apiKey);
|
||||
return json(res, 200, { organizers });
|
||||
}
|
||||
if (req.method === 'POST' && path === '/export') {
|
||||
const body = await readBody(req);
|
||||
const result = await handleExport(body);
|
||||
return json(res, 200, result);
|
||||
}
|
||||
return json(res, 404, { error: 'not found' });
|
||||
} catch (e) {
|
||||
return json(res, 500, { error: e.message });
|
||||
|
||||
Reference in new issue
Block a user