tickets_generate function reads the zone configuration from events/{idevent}/setup/zones, iterates every zone and every seat within it, and creates one ticket document per seat. All writes are committed in a single Firestore batch and simultaneously inserted into PostgreSQL.
How it works
Fetch the event document
The function reads
events/{idevent} to obtain event.name, event.description, date_start, and date_end. If the document does not exist, it returns a 400 immediately.Read zone configuration
It reads
events/{idevent}/setup/zones. This sub-document must have status: true; if it is false the function returns without generating any tickets.Iterate zones and seats
For each zone in
datos.zone, it loops from 1 to zone.seats inclusive. Each iteration generates a new Firestore document reference to mint a unique ID.Build ticket data
Each ticket is assembled with the fields below and staged into a Firestore batch write targeting
events/{idevent}/tickets/{ticketDocId}.Request
Parameters
The Firestore document ID of the event for which tickets should be generated. Must match a document in the
events collection.Zone Configuration (Firestore)
Before calling this endpoint, the document atevents/{idevent}/setup/zones must be present and valid.
Generated Ticket Structure
Each ticket written toevents/{idevent}/tickets/{ticketDocId} has the following shape:
Ticket Fields
Composite identifier built as
{event_id}-{firestoreDocId}. This is the canonical ID used across all subsequent operations.Composite seat reference:
{zone.id}{seat_number} (e.g. VIP1, GEN42). Built from the zone id field, not the display name.Display name of the zone (e.g.
"VIP", "General").Hex color string from the zone definition. Used by client apps to colour-code seat maps.
true when the ticket is available for purchase. Set to false after a sale is completed.Row label. Initialised to
"por asignar" (“to be assigned”) at generation time.Firestore document ID of the parent event.
Display name copied from
event.event.name at generation time.Event start time, copied from the parent event document.
Event end time, copied from the parent event document.
Server timestamp recorded when the ticket was generated.
Empty string at creation. Updated to a server timestamp on every subsequent mutation.
Audit trail. Initialised with a single
generated entry. Every subsequent state change appends a new entry.Responses
Human-readable result message, e.g.
"Se Generaron: 300".HTTP-style status code:
200 on success, 400 on failure.true when tickets were generated successfully.