fix(points): welcome check-in awards +10; add Sessions view, AI connection test, silent reload
The front-desk check-in set checked_in and printed badges but awarded nothing, so the +10 depended on which check-in a person happened to get. Every award path was reviewed: - welcome_checkin awards +10 (category checkin) on a genuine first check-in and returns points + points_awarded; checkin_attendee and preview_welcome_checkin return points_awarded too. - set_registration_checked_in(false) deleted all checkin points while keeping the checkins rows, and switching back on awarded nothing -- one mistaken toggle destroyed those points permanently. ON now recomputes from the rows that still exist and awards only the shortfall: reversible, still unfarmable. - The staff/Admin/@appe.at exclusion stays (product decision) but is no longer silent: three-way points sheets in the scanner, "no points" with a tooltip in Registrations, and the Contacts points modal refuses to apply rather than letting adjust_points (void) no-op quietly. Also in this change: - admin silent refresh (5s poll + 500ms after writes) across all data views; Registrations patches in place so rows never slide under the cursor - Settings "Validate AI connection" via a new sidecar POST /llm-test verdict endpoint (never leaks the key, distinguishes "no usage block" from "off") - new Sessions view between Schedule and Activity: speakers, attendance, ratings, attendee filter, and one button that summarises every session with feedback (one request each, concurrency 3, UI blocked until all settle) - provider requests disable thinking through one shared body builder sending both reasoning_effort:"none" and chat_template_kwargs.enable_thinking SQL: 113 / 57 / 24 assertions (set_registration_checked_in section 3 was rewritten, it asserted the bug). Sidecar 34 unit tests. Full e2e 202 passed, 0 failed. Migration applied locally only -- not deployed.
This commit is contained in:
1 parent
96e4e6a6ea
commit
fdb6045966
35 files changed
+2778
-154
No files matched your search
@@ -12,6 +12,7 @@ import type {
|
||||
Feedback,
|
||||
FeedbackSummary,
|
||||
LlmSettings,
|
||||
LlmTestResult,
|
||||
LeaderboardRow,
|
||||
PointsLogRow,
|
||||
PretixOptions,
|
||||
@@ -49,6 +50,25 @@ async function all<T>(table: string, order?: { col: string; asc?: boolean }): Pr
|
||||
return data as T[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Paged read of one event's rows. PostgREST is configured with
|
||||
* `max_rows = 1000` (supabase/config.toml) and `all()` above has no paging, so a
|
||||
* single unsorted select silently truncates at 1000 — fine for contacts at this
|
||||
* event's size, not fine for check-ins once every attendee has scanned a few
|
||||
* sessions. `id` is the tiebreaker so rows cannot shift between pages.
|
||||
*/
|
||||
async function pagedForEvent<T>(table: string, eventId: string, order: { col: string; asc?: boolean }): Promise<T[]> {
|
||||
const rows: T[] = [];
|
||||
for (let offset = 0; ; offset += 500) {
|
||||
let q = supabase.from(table).select('*').eq('event_id', eventId);
|
||||
q = q.order(order.col, { ascending: order.asc ?? true }).order('id', { ascending: true });
|
||||
const { data, error } = await q.range(offset, offset + 499);
|
||||
if (error) throw new ApiError(error.message);
|
||||
rows.push(...(data as T[]));
|
||||
if (data.length < 500) return rows;
|
||||
}
|
||||
}
|
||||
|
||||
// ---- Reads (admin can read all rows via RLS) --------------------------------
|
||||
|
||||
export const getAllContacts = () => all<Contact>('contacts', { col: 'full_name' });
|
||||
@@ -73,6 +93,35 @@ export const getAllSessionSpeakers = () => all<SessionSpeaker>('session_speakers
|
||||
export const getAllConnections = () => all<Connection>('connections', { col: 'created_at', asc: false });
|
||||
export const getAllCheckins = () => all<Checkin>('checkins', { col: 'created_at', asc: false });
|
||||
export const getAllFeedback = () => all<Feedback>('feedback', { col: 'created_at', asc: false });
|
||||
/** Check-ins for one event, paged past the 1000-row PostgREST cap. */
|
||||
export const getEventCheckins = (eventId: string) =>
|
||||
pagedForEvent<Checkin>('checkins', eventId, { col: 'created_at', asc: false });
|
||||
/** Session feedback for one event, paged past the 1000-row cap. */
|
||||
export const getEventFeedbackRows = (eventId: string) =>
|
||||
pagedForEvent<Feedback>('feedback', eventId, { col: 'created_at', asc: false });
|
||||
/**
|
||||
* Speaker links for one event. `session_speakers` has no event_id column, so
|
||||
* this filters through the session FK with an inner join — a plain `all()`
|
||||
* would return every event's links and truncate at 1000 rows.
|
||||
*/
|
||||
export async function getEventSessionSpeakers(eventId: string): Promise<SessionSpeaker[]> {
|
||||
const rows: SessionSpeaker[] = [];
|
||||
for (let offset = 0; ; offset += 500) {
|
||||
const { data, error } = await supabase
|
||||
.from('session_speakers')
|
||||
.select('session_id, contact_email, sessions!inner(event_id)')
|
||||
.eq('sessions.event_id', eventId)
|
||||
.order('session_id', { ascending: true })
|
||||
.order('contact_email', { ascending: true })
|
||||
.range(offset, offset + 499);
|
||||
if (error) throw new ApiError(error.message);
|
||||
for (const r of data as (SessionSpeaker & { sessions?: unknown })[]) {
|
||||
delete r.sessions;
|
||||
rows.push(r);
|
||||
}
|
||||
if (data.length < 500) return rows;
|
||||
}
|
||||
}
|
||||
export const getAllEventFeedback = () => all<EventFeedback>('event_feedback', { col: 'created_at', asc: false });
|
||||
async function eventFeedbackRows<T>(table: 'feedback' | 'event_feedback', eventId: string): Promise<T[]> {
|
||||
const rows: T[] = [];
|
||||
@@ -172,17 +221,23 @@ export async function setRegistrationType(contactEmail: string, type: Registrati
|
||||
}
|
||||
|
||||
/**
|
||||
* Flip an attendee's event check-in state. When turning it OFF, the backend
|
||||
* also removes every point this person earned from check-ins in the event
|
||||
* (see set_registration_checked_in). Returns the number of points removed.
|
||||
* Flip an attendee's event check-in state. Turning it OFF removes every point
|
||||
* this person earned from check-ins in the event; turning it back ON restores the
|
||||
* points their surviving session check-ins justify (see
|
||||
* set_registration_checked_in). Only one of the two is ever non-zero.
|
||||
*/
|
||||
export async function setCheckedIn(registrationId: string, checkedIn: boolean): Promise<number> {
|
||||
const rows = await rpc<{ registration_id: string; checked_in: boolean; points_removed: number }[]>(
|
||||
'set_registration_checked_in',
|
||||
{ p_registration_id: registrationId, p_checked_in: checkedIn },
|
||||
);
|
||||
export async function setCheckedIn(
|
||||
registrationId: string,
|
||||
checkedIn: boolean,
|
||||
): Promise<{ removed: number; added: number }> {
|
||||
const rows = await rpc<{
|
||||
registration_id: string;
|
||||
checked_in: boolean;
|
||||
points_removed: number;
|
||||
points_added?: number;
|
||||
}[]>('set_registration_checked_in', { p_registration_id: registrationId, p_checked_in: checkedIn });
|
||||
if (!rows?.length) throw new ApiError('Registration no longer exists');
|
||||
return rows[0].points_removed;
|
||||
return { removed: rows[0].points_removed ?? 0, added: rows[0].points_added ?? 0 };
|
||||
}
|
||||
|
||||
export const mergeTickets = (sourceId: string, targetId: string) =>
|
||||
@@ -502,6 +557,15 @@ export const getLlmSettings = () => feedbackSidecarFetch<LlmSettings>('/llm-sett
|
||||
export const saveLlmSettings = (input: { endpoint: string; model: string; api_key?: string }) =>
|
||||
feedbackSidecarFetch<LlmSettings>('/llm-settings', { method: 'PUT', body: JSON.stringify(input) });
|
||||
|
||||
/**
|
||||
* Ask the sidecar to make one real chat request with the stored settings and
|
||||
* report a verdict. Returns the verdict rather than throwing on a bad
|
||||
* connection, because the reason (wrong key, unreachable host, model still
|
||||
* thinking) is what the UI has to show. Only throws for transport/auth faults.
|
||||
* Always reads the settings saved in the DB, never the form's current values.
|
||||
*/
|
||||
export const testLlmConnection = () => feedbackSidecarFetch<LlmTestResult>('/llm-test', { method: 'POST' });
|
||||
|
||||
export async function getFeedbackSummaries(eventId: string): Promise<FeedbackSummary[]> {
|
||||
const { data, error } = await supabase.from('feedback_summaries').select('*').eq('event_id', eventId);
|
||||
if (error) throw new ApiError(error.message);
|
||||
|
||||
Reference in new issue
Block a user