Archived
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>
115 lines
6.9 KiB
TypeScript
115 lines
6.9 KiB
TypeScript
/**
|
|
* Corrections (1.52.0): see services/corrections.ts. Admins only, except "Fill in later" for
|
|
* staff at the door and in Manual registrations.
|
|
*/
|
|
import { z } from 'zod';
|
|
import type { Request } from 'express';
|
|
import { defineRoute, type ApiUser } from '../route';
|
|
import { single } from '../paging';
|
|
import { id, idParams } from '../schemas';
|
|
import * as corrections from '../../services/corrections';
|
|
|
|
/* eslint-disable @typescript-eslint/no-explicit-any -- campus scope middleware is JavaScript */
|
|
const campusScope = require('../../utils/campusScope') as {
|
|
scopeEvent(opts?: { need?: 'view' | 'manage'; resolve?: string }): any;
|
|
};
|
|
|
|
const audit = (req: Request, user: ApiUser | null) => {
|
|
const { getClientIp } = require('../../utils/requestUtils') as { getClientIp(req: unknown): string };
|
|
return { actor: { id: user!.id, role: user!.role }, ip: getClientIp(req) };
|
|
};
|
|
|
|
const reason = z.string().trim().max(500).nullish().describe('Why — kept in the audit log');
|
|
const send = z.boolean().optional().describe('Send the new tickets to the attendee (off by default)');
|
|
|
|
const ticketRow = z.object({
|
|
id,
|
|
qrCode: z.string(),
|
|
label: z.string().describe('Ticket option, variant and (a picked session) the session'),
|
|
isMainTicket: z.boolean(),
|
|
name: z.string().describe('Who it\'s for'),
|
|
quantity: z.number().int(),
|
|
sessionIds: z.array(z.string()).describe(`The sessions it covers (\`${corrections.WHOLE_EVENT}\` on a single-date event)`),
|
|
checkedIn: z.record(z.string(), z.number().int()).describe('People checked in, per session'),
|
|
});
|
|
const registrationRow = z.object({
|
|
id,
|
|
status: z.string(),
|
|
createdAt: z.coerce.date(),
|
|
user: z.object({ id, name: z.string(), email: z.string().nullable(), phoneNumber: z.string().nullable() }),
|
|
totalDue: z.number(),
|
|
paid: z.number(),
|
|
balance: z.number(),
|
|
places: z.number().int().describe('Places booked (every line)'),
|
|
ticketPlaces: z.number().int().describe('Places with a ticket'),
|
|
missingTickets: z.boolean().describe('Paid (or released unpaid) but not every place has a ticket'),
|
|
formsNeeded: z.number().int().describe('Attendee forms still holding the tickets back'),
|
|
formWaived: z.boolean().describe('The form was left for later'),
|
|
ticketsReleased: z.boolean().describe('Tickets issued before it was paid'),
|
|
complimentary: z.number().describe('Balance written off'),
|
|
tickets: z.array(ticketRow),
|
|
});
|
|
|
|
export const eventCorrections = defineRoute({
|
|
method: 'get', path: '/corrections/events/:id', tag: 'Corrections', summary: 'An event\'s registrations, with what needs putting right',
|
|
description: 'Every registration that isn\'t cancelled — closed and past events too — with its balance, forms still to fill in, tickets and check-ins.',
|
|
access: 'admin', params: idParams,
|
|
response: single(z.object({
|
|
event: z.object({
|
|
id, title: z.string(), startDate: z.coerce.date(), endDate: z.coerce.date(), closed: z.boolean(),
|
|
formRequired: z.boolean(), sessions: z.array(z.object({ id, label: z.string(), startsAt: z.coerce.date() })),
|
|
}),
|
|
registrations: z.array(registrationRow),
|
|
})),
|
|
async handler({ params }) { return { data: await corrections.eventCorrections(params.id) }; },
|
|
});
|
|
|
|
export const issueMissing = defineRoute({
|
|
method: 'post', path: '/corrections/events/:id/issue-missing', tag: 'Corrections', summary: 'Issue every missing ticket at an event',
|
|
description: 'For each paid registration (or one released unpaid) without all its tickets. Attendee forms still outstanding are left for later.',
|
|
access: 'admin', params: idParams, body: z.object({ send }),
|
|
response: single(z.object({ registrations: z.number().int(), tickets: z.number().int(), failed: z.array(z.object({ id, name: z.string(), message: z.string() })) })),
|
|
async handler({ params, body, user, req }) { return { data: await corrections.issueMissingTickets(params.id, audit(req, user), body) }; },
|
|
});
|
|
|
|
export const issueTickets = defineRoute({
|
|
method: 'post', path: '/corrections/registrations/:id/tickets', tag: 'Corrections', summary: 'Issue a registration\'s tickets now',
|
|
description: '`skipForm` leaves the attendee form for later; `payLater` issues them before it\'s paid (the balance is still owed).',
|
|
access: 'admin', params: idParams,
|
|
body: z.object({ skipForm: z.boolean().optional(), payLater: z.boolean().optional(), send, reason }),
|
|
response: single(z.object({ ticketsIssued: z.number().int(), registration: registrationRow })),
|
|
async handler({ params, body, user, req }) { return { data: await corrections.issueTickets(params.id, audit(req, user), body) }; },
|
|
});
|
|
|
|
export const complimentary = defineRoute({
|
|
method: 'post', path: '/corrections/registrations/:id/complimentary', tag: 'Corrections', summary: 'Make it free',
|
|
description: 'What\'s still owed is written off as a complimentary discount (income stays what was really paid), it\'s marked paid and its tickets are issued. Not on a closed event.',
|
|
access: 'admin', params: idParams,
|
|
body: z.object({ skipForm: z.boolean().optional(), send, reason }),
|
|
response: single(z.object({ amount: z.number(), ticketsIssued: z.number().int(), registration: registrationRow })),
|
|
async handler({ params, body, user, req }) { return { data: await corrections.makeComplimentary(params.id, audit(req, user), body) }; },
|
|
});
|
|
|
|
export const checkIn = defineRoute({
|
|
method: 'post', path: '/corrections/tickets/:id/check-in', tag: 'Corrections', summary: 'Check a ticket in (or undo it) after the fact',
|
|
description: 'Any time — after the event or session, or once the event is closed. `present: false` undoes the check-in for that session. Recorded as a manual check-in; no message is sent.',
|
|
access: 'admin', params: idParams,
|
|
body: z.object({
|
|
sessionId: id.nullish().describe('Multi-day events: the session'),
|
|
people: z.number().int().min(1).max(1000).nullish().describe('How many (default: everyone left on the ticket)'),
|
|
present: z.boolean().optional().describe('false undoes it'),
|
|
reason,
|
|
}),
|
|
response: single(z.object({ checkedIn: z.number().int(), quantity: z.number().int() })),
|
|
async handler({ params, body, user, req }) { return { data: await corrections.correctCheckIn(params.id, audit(req, user), body) }; },
|
|
});
|
|
|
|
export const formLater = defineRoute({
|
|
method: 'post', path: '/registrations/:id/form-later', tag: 'Registrations', summary: 'Fill in the attendee form later',
|
|
description: 'At the door: the tickets stop waiting for the required attendee form (issued now if it\'s paid) and the payer is sent a link to fill it in (`notify: false` to not).',
|
|
access: 'staff', campusScope: 'scopeEvent(registration)', middleware: [campusScope.scopeEvent({ resolve: 'registration' })], params: idParams,
|
|
body: z.object({ notify: z.boolean().optional() }),
|
|
response: single(z.object({ ticketsIssued: z.number().int(), sentTo: z.array(z.string()) })),
|
|
async handler({ params, body, user, req }) { return { data: await corrections.leaveFormForLater(params.id, audit(req, user), body) }; },
|
|
});
|