Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfiCVCgCVJZq4NDEqZs
109 lines
4.4 KiB
TypeScript
109 lines
4.4 KiB
TypeScript
import { apiDelete, apiGet, apiPost, apiPut } from "@/app/lib/clientApi";
|
|
|
|
// add-event-ticket-orders: an event's ticket settings, ticket types and orders (BO_EVENT_TICKETS).
|
|
export interface TicketSettings {
|
|
ticketsEnabled: boolean;
|
|
paymentInstructions: string | null;
|
|
holdDays: number | null;
|
|
}
|
|
export interface TicketTypeInput {
|
|
name: string;
|
|
priceSen: number;
|
|
quantity: number;
|
|
salesEndDate: string | null;
|
|
sort: number;
|
|
enabled: boolean;
|
|
}
|
|
export interface TicketType extends TicketTypeInput {
|
|
id: number;
|
|
held: number;
|
|
left: number;
|
|
}
|
|
export type OrderStatus = "AWAITING" | "PAID" | "CANCELLED" | "EXPIRED";
|
|
export const ORDER_STATUSES: OrderStatus[] = ["AWAITING", "PAID", "CANCELLED", "EXPIRED"];
|
|
export interface OrderRow {
|
|
id: number;
|
|
reference: string;
|
|
buyerName: string;
|
|
buyerEmail: string;
|
|
tickets: number;
|
|
totalSen: number;
|
|
status: OrderStatus;
|
|
createdAt: string;
|
|
}
|
|
export interface OrderPage {
|
|
content: OrderRow[];
|
|
totalElements: number;
|
|
totalPages: number;
|
|
number: number;
|
|
size: number;
|
|
}
|
|
export interface OrderDetail {
|
|
order: {
|
|
id: number;
|
|
reference: string;
|
|
status: OrderStatus;
|
|
buyerName: string;
|
|
buyerEmail: string;
|
|
buyerMobileE164: string | null;
|
|
buyerCompany: string | null;
|
|
totalSen: number;
|
|
holdUntil: string | null;
|
|
paidAt: string | null;
|
|
paidBy: string | null;
|
|
paymentRef: string | null;
|
|
cancelledAt: string | null;
|
|
cancelledBy: string | null;
|
|
expiredAt: string | null;
|
|
createdAt: string;
|
|
};
|
|
lines: { id: number; name: string; unitPriceSen: number; quantity: number }[];
|
|
tickets: { id: number; typeName: string | null; status: "ACTIVE" | "CANCELLED"; cancelledAt: string | null; cancelledBy: string | null }[];
|
|
}
|
|
|
|
const base = (uuid: string) => `/api/events/${encodeURIComponent(uuid)}`;
|
|
|
|
export const getTicketSettings = (uuid: string) => apiGet<TicketSettings>(`${base(uuid)}/tickets/settings`);
|
|
export const saveTicketSettings = (uuid: string, s: TicketSettings) => apiPut<unknown>(`${base(uuid)}/tickets/settings`, s);
|
|
export const listTicketTypes = (uuid: string) => apiGet<TicketType[]>(`${base(uuid)}/ticket-types`);
|
|
export const saveTicketType = (uuid: string, t: TicketTypeInput, id?: number) =>
|
|
id == null ? apiPost<unknown>(`${base(uuid)}/ticket-types`, t) : apiPut<unknown>(`${base(uuid)}/ticket-types/${id}`, t);
|
|
export const deleteTicketType = (uuid: string, id: number) => apiDelete<unknown>(`${base(uuid)}/ticket-types/${id}`);
|
|
export const listOrders = (uuid: string, f: { status?: string; q?: string; page?: number }) => {
|
|
const p = new URLSearchParams();
|
|
if (f.status) p.set("status", f.status);
|
|
if (f.q) p.set("q", f.q);
|
|
p.set("page", String(f.page ?? 0));
|
|
return apiGet<OrderPage>(`${base(uuid)}/orders?${p}`);
|
|
};
|
|
export const getOrder = (uuid: string, id: string) => apiGet<OrderDetail>(`${base(uuid)}/orders/${encodeURIComponent(id)}`);
|
|
export const markOrderPaid = (uuid: string, id: string, paymentRef: string) =>
|
|
apiPost<unknown>(`${base(uuid)}/orders/${encodeURIComponent(id)}/paid`, { paymentRef });
|
|
export const cancelOrder = (uuid: string, id: string) => apiPost<unknown>(`${base(uuid)}/orders/${encodeURIComponent(id)}/cancel`);
|
|
export const cancelTicket = (uuid: string, id: string, ticketId: number) =>
|
|
apiPost<unknown>(`${base(uuid)}/orders/${encodeURIComponent(id)}/tickets/${ticketId}/cancel`);
|
|
export const resendOrderEmail = (uuid: string, id: string) => apiPost<unknown>(`${base(uuid)}/orders/${encodeURIComponent(id)}/resend`);
|
|
|
|
/** RM 1,000.00 from whole sen; RM 0 reads "Free" where a caller wants it. */
|
|
export const money = (sen: number) =>
|
|
`RM ${(sen / 100).toLocaleString("en-MY", { minimumFractionDigits: 2, maximumFractionDigits: 2 })}`;
|
|
|
|
/** The label for a refusal code from the ticket endpoints, else null (the caller shows its generic text). */
|
|
export const TICKET_ERRORS: Record<string, string> = {
|
|
PAYMENT_INSTRUCTIONS_REQUIRED: "TktErrInstructionsRequired",
|
|
PAYMENT_INSTRUCTIONS_TOO_LONG: "TktErrInstructionsTooLong",
|
|
HOLD_DAYS_INVALID: "TktErrHoldDays",
|
|
NAME_INVALID: "TktErrName",
|
|
NAME_TAKEN: "TktErrNameTaken",
|
|
PRICE_INVALID: "TktErrPrice",
|
|
QUANTITY_INVALID: "TktErrQuantity",
|
|
QUANTITY_BELOW_HELD: "TktErrQuantityBelowHeld",
|
|
DATE_INVALID: "TktErrDate",
|
|
TYPE_HAS_ORDERS: "TktErrTypeHasOrders",
|
|
NOT_PAYABLE: "TktErrNotPayable",
|
|
SEATS_GONE: "TktErrSeatsGone",
|
|
PAYMENT_REF_TOO_LONG: "TktErrPaymentRef",
|
|
NOT_CANCELLABLE: "TktErrNotCancellable",
|
|
LAST_TICKET: "TktErrLastTicket",
|
|
};
|