Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/Sufianeh7/AmigoInvisible/llms.txt

Use this file to discover all available pages before exploring further.

Amigo Invisible stores all group and draw data in a single MongoDB collection using the Sorteo Mongoose model defined in Node/modelos/Sorteo.js. One Sorteo document represents one Secret Santa group — it holds the group metadata, the full list of participants, and the schema fields for tracking draw state and history.

Schema Source

const mongoose = require('mongoose');

const SorteoSchema = new mongoose.Schema({
    nombreGrupo: { type: String, required: true, trim: true},
    presupuesto: { type: String, trim: true },
    fechaEntrega: { type: Date},

    // Token para la URL de administración
    adminToken: { type: String, required: true, unique: true},
    estado: { type: String, enum: ['borrador', 'completado'], default: 'borrador'},

    // Lista de amigos
    participantes: [{
        nombre: { type: String, required: true },
        email: { type: String, required: true },
        exclusiones: [{ type: String}]
    }],

    // Historial para reutilizar
    emparejamientosPasados: [{
        fechaSorteo: { type: Date, default: Date.now},
        parejas: [{
            de: { type: String },
            para: { type: String }
        }]
    }]
}, { timestamps: true});

module.exports = mongoose.model('Sorteo', SorteoSchema);
The schema also enables Mongoose’s timestamps option, which automatically adds createdAt and updatedAt fields to every document.

Field Reference

nombreGrupo
String
required
The display name of the Secret Santa group (e.g. "Oficina 2024"). Required and automatically trimmed of leading/trailing whitespace.
presupuesto
String
An optional free-text description of the gift budget (e.g. "20€ máximo"). Trimmed but not validated for format — any string is accepted.
fechaEntrega
Date
The planned date on which gifts will be exchanged. Optional. Stored as a native MongoDB Date type.
adminToken
String
required
A UUID generated by crypto.randomUUID() at group creation time. Serves as both the secret identifier and the authentication credential for the group organizer. Marked unique — no two groups can share the same token. The admin dashboard URL is constructed as /admin/{adminToken}.
estado
String
The current draw status. Accepted values are borrador and completado. Defaults to borrador when a group is first created. Transitions to completado when lanzarSorteo is called successfully and emails have been dispatched.
participantes
Array
An array of embedded participant sub-documents. See the Participant Sub-document section below for the full field breakdown.
emparejamientosPasados
Array
An array of embedded past-draw sub-documents intended to store the results of each draw run for history tracking. The schema defines its structure (see Past Pairings Sub-document below), though the current controller writes the generated pairings to sorteo.emparejamientosActuales rather than pushing into this array.

Participant Sub-document

Each entry in the participantes array represents one person in the group.
nombre
String
required
The participant’s display name. Used in email greetings and as the identifier inside exclusion lists.
email
String
required
The participant’s email address. Used both as a unique identifier within the draw algorithm (pairs are stored as { de: email, para: email }) and as the delivery address for the reveal email.
exclusiones
Array of Strings
An optional list of participant names (not emails) that this person must not be assigned as a recipient. For example, if Alice should never give a gift to Bob, "Bob" would appear in Alice’s exclusiones array. Exclusions are one-directional.

Past Pairings Sub-document

The emparejamientosPasados array is defined in the schema to capture the full result of each draw run. Each entry in the array has the following structure:
fechaSorteo
Date
The timestamp when the draw was run. Defaults to Date.now at the time the sub-document is created.
parejas
Array
An array of { de: String, para: String } objects. Each object records one giver-recipient pair using email addresses as identifiers.

Status Lifecycle

A Sorteo document moves through two states:
  • borrador — The default state. The group has been created and participants have been added, but the draw has not yet been run. The organizer can still review the group via their admin link.
  • completado — The draw has been executed successfully and all reveal emails have been sent. The lanzarSorteo controller sets estado = 'completado' and saves the document after the algorithm produces valid pairings and before the emails are dispatched.
Once a group’s estado is completado, there is no built-in API endpoint to reset the status or re-run the draw. The current implementation is intentionally one-shot — calling POST /:adminToken/lanzar again on a completed group will re-run the algorithm and re-send emails. There is no guard against this, so organizers should treat the draw action as final.

Build docs developers (and LLMs) love