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.

GrupoService is the single Angular service responsible for all communication between the frontend and the Node.js backend. It lives at src/app/servicios/grupo.ts, is provided at the root level, and is injected by both the Grupo and Sorteo components. Every method returns a cold Observable from Angular’s HttpClient, so callers must .subscribe() to trigger the request.

Service Source

import { Injectable } from "@angular/core";
import { HttpClient } from "@angular/common/http";
import { Observable } from "rxjs";

@Injectable({
  providedIn: 'root',
})
export class GrupoService {
  private apiUrl = 'https://amigo-invisible-node-87yz.vercel.app/api/sorteos';

  constructor(private http: HttpClient) {}

  crearSorteo(datosGrupo: any): Observable<any> {
    return this.http.post(this.apiUrl, datosGrupo);
  }

  getGrupo(adminToken: string): Observable<any> {
    return this.http.get(`${this.apiUrl}/${adminToken}`);
  }

  lanzarSorteo(adminToken: string): Observable<any> {
    return this.http.post(`${this.apiUrl}/${adminToken}/lanzar`, {})
  }
}

Method Reference

crearSorteo(datosGrupo)

POSTs the group payload to /api/sorteos to create a new Secret Santa draw on the backend.Parameters
NameTypeDescription
datosGrupoanyObject containing nombreGrupo, presupuesto, and participantes[].
Returns Observable<{ mensaje: string; adminToken: string; enlaceAdmin: string }>The adminToken in the response is used immediately by the Grupo component to navigate to /sorteo/:adminToken.Example
this.grupoService.crearSorteo(datosGrupo).subscribe({
  next: (res) => {
    this.router.navigate(['/sorteo', res.adminToken]);
  },
  error: (error) => {
    console.error('Error con el servidor: ', error);
  },
});

Changing the API URL

For local development, the apiUrl must point to your locally running Node.js server. Open src/app/servicios/grupo.ts and update the private property:
// Change this line:
private apiUrl = 'https://amigo-invisible-node-87yz.vercel.app/api/sorteos';

// To this for local development:
private apiUrl = 'http://localhost:3000/api/sorteos';
Once you are ready to deploy, revert the URL to the production Vercel endpoint before running npm run build.
GrupoService is decorated with @Injectable({ providedIn: 'root' }), which means Angular registers it in the root injector and creates exactly one instance for the entire application lifetime. You do not need to add it to any providers array in a module or component — it is available everywhere as a true singleton the moment it is first injected.

Build docs developers (and LLMs) love