Fix: door and manual registrations get their tickets; admin Corrections (1.52.0)
On events with a required attendee form, tickets waited for the forms, but
At the door and Manual registration never asked for them: payment was
recorded and nobody could be checked in.
- The form pops up at the door and in Manual registration; "Fill in later"
(any staff) issues the tickets once paid and sends the payer a link
(Registration.formWaivedAt, POST /api/v2/registrations/{id}/form-later).
- One form per person on picked-session bookings; a required form with no
questions no longer holds tickets back; every caller asks the ticket
generator (formsOutstanding).
- Kiosk asks for the forms the server says are missing; headings show as text.
- Admin Corrections page and /api/v2/corrections: issue missing tickets,
pay later (ticketsReleasedAt), make it free (complimentaryDiscount),
check in or undo after the event.
- Migration 20261102120000_corrections; unit and e2e tests.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -2,8 +2,55 @@ const prisma = require('../config/db');
|
||||
const { v4: uuidv4 } = require('uuid');
|
||||
const { planLineTickets } = require('./attendees');
|
||||
|
||||
/** Form fields that are only text to read (a statement, a heading). */
|
||||
const DISPLAY_FIELDS = ['statement', 'paragraph'];
|
||||
|
||||
/** A required form with at least one question to answer — the only kind tickets wait for. */
|
||||
const formNeedsAnswers = (form) => !!(form && form.isRequired && (form.fields || []).some(f => !DISPLAY_FIELDS.includes(f.type)));
|
||||
|
||||
/**
|
||||
* Generate tickets for a registration when payment status is "paid".
|
||||
* How many attendee forms a registration's places need: one per main-ticket place. A picked-
|
||||
* session booking has a line per session for the same people, so it counts once (its biggest
|
||||
* line), not once per session.
|
||||
*/
|
||||
function formPlaces(registrationOptions) {
|
||||
let total = 0;
|
||||
const picked = new Map();
|
||||
for (const ro of registrationOptions || []) {
|
||||
if (!ro.eventOption?.isMainTicket) continue;
|
||||
const qty = ro.quantity || 0;
|
||||
if (!ro.sessionId) { total += qty; continue; }
|
||||
const key = `${ro.eventOptionId}::${ro.variantId || ''}`;
|
||||
picked.set(key, Math.max(picked.get(key) || 0, qty));
|
||||
}
|
||||
for (const qty of picked.values()) total += qty;
|
||||
return total;
|
||||
}
|
||||
|
||||
/**
|
||||
* The attendee forms a registration still needs before its tickets can be issued: 0 when the
|
||||
* event's form isn't required (or has no questions), when the form was left for later
|
||||
* (`formWaivedAt`), or when enough are in. `registration` is an id or a record with
|
||||
* registrationOptions[].eventOption.
|
||||
*/
|
||||
async function formsOutstanding(registration) {
|
||||
try {
|
||||
const reg = typeof registration === 'string'
|
||||
? await prisma.registration.findUnique({ where: { id: registration }, include: { registrationOptions: { include: { eventOption: true } } } })
|
||||
: registration;
|
||||
if (!reg || reg.formWaivedAt) return 0;
|
||||
const form = await prisma.eventForm.findUnique({ where: { eventId: reg.eventId }, include: { fields: true } });
|
||||
if (!formNeedsAnswers(form)) return 0;
|
||||
const submitted = await prisma.formResponse.count({ where: { registrationId: reg.id } });
|
||||
return Math.max(0, formPlaces(reg.registrationOptions) - submitted);
|
||||
} catch (_) {
|
||||
return 0; // form models unavailable — don't block
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate tickets for a registration when payment status is "paid" (or an admin released
|
||||
* them unpaid) and no required attendee form is outstanding (see formsOutstanding).
|
||||
*
|
||||
* Rules:
|
||||
* - Each named attendee (group tickets) gets their own quantity-1 ticket; the rest of a
|
||||
@@ -34,19 +81,11 @@ const generateTicketsForRegistration = async (registrationId) => {
|
||||
});
|
||||
|
||||
if (!registration) throw new Error('Registration not found');
|
||||
if (registration.status !== 'paid') return [];
|
||||
// Paid, or an admin issued the tickets before payment ("pay later", 1.52.0).
|
||||
if (registration.status !== 'paid' && !(registration.ticketsReleasedAt && registration.status !== 'cancelled')) return [];
|
||||
|
||||
// If event has a required form, ensure sufficient responses exist
|
||||
try {
|
||||
const form = await prisma.eventForm.findUnique({ where: { eventId: registration.eventId } });
|
||||
if (form && form.isRequired) {
|
||||
const requiredCount = (registration.registrationOptions || [])
|
||||
.filter(ro => ro.eventOption?.isMainTicket)
|
||||
.reduce((s, ro) => s + (ro.quantity || 0), 0);
|
||||
const responsesCount = await prisma.formResponse.count({ where: { registrationId } });
|
||||
if (responsesCount < requiredCount) return [];
|
||||
}
|
||||
} catch (_) { /* form models unavailable — don't block */ }
|
||||
// A required attendee form comes first, unless it's been left for later.
|
||||
if ((await formsOutstanding(registration)) > 0) return [];
|
||||
|
||||
// ── Step 1: Consolidate duplicate registrationOptions for the same (eventOptionId, variantId, session) ──
|
||||
// Key on both fields so that different variants of the same option are never merged
|
||||
@@ -133,4 +172,4 @@ const generateTicketsForRegistration = async (registrationId) => {
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = { generateTicketsForRegistration };
|
||||
module.exports = { generateTicketsForRegistration, formsOutstanding, formPlaces, formNeedsAnswers, DISPLAY_FIELDS };
|
||||
Reference in New Issue
Block a user