Skip to content

Local Development

Prerequisites

Step 1 — Clone and Install

bash
git clone https://github.com/haflidif/chior-tickets.git
cd chior-tickets

# Install API dependencies
cd api
npm install

# Install frontend dependencies
cd ../frontend
npm install

Step 2 — Start Cosmos DB Emulator

Start the Azure Cosmos DB Emulator on your machine. The default connection settings are already configured in api/local.settings.json.

Step 3 — Run Locally

bash
# Terminal 1: Start API
cd api
npm start

# Terminal 2: Start Frontend
cd frontend
npm run dev

Open http://localhost:5173 in your browser.

Step 4 — Setup Database and Create Initial Super Admin

Run the setup scripts to create database containers and seed the first super admin:

bash
cd api

# Create all containers with proper indexes and TTL
npx ts-node scripts/setup-database.ts

# Create super admin user
npx ts-node scripts/seed-admin.ts your@email.com "Your Name"

This creates:

  • All required containers (users, organizations, organizationMemberships, events, registrations, etc.)
  • A super admin user who can create organizations and manage the entire system

Step 5 — First-Time Setup Checklist

After installation and database setup, complete these steps:

  1. Login as Super Admin:

    • Navigate to http://localhost:5173/login
    • Enter the email you used in seed-admin.ts
    • Check console for magic link (if RESEND_API_KEY not set)
  2. Create Your First Organization:

    • Navigate to Organizations → Create Organization
    • Enter organization name and details
    • You'll be automatically added as admin
  3. Add Members:

    • Option A: Create invitation code → Share link with members
    • Option B: Import members via CSV (email, name, role columns)
    • Option C: Add members individually in Members view
  4. Create Your First Event:

    • Navigate to Events → Create Event
    • Set event name, date, location, venue capacity
    • Add showtimes (multiple dates/times)
    • Add ticket types with prices
  5. Configure Settings (Optional):

    • Lock sales if needed
    • Set up allocations for members
    • Configure external sales tracking

Testing

API Tests

bash
cd api
npm test

# Run specific test pattern
npm test -- orders

E2E Tests

bash
cd frontend
npx playwright test

# Run specific test file
npx playwright test login.spec.ts

Development Notes

Grace Period for Registrations

Registrations have a 1-hour grace period for edits/deletions:

  • Within 1 hour: Admin can edit or delete registration freely
  • After 1 hour: Registration is locked to prevent accidental data loss
  • This protects historical data while allowing quick corrections

Database Cleanup (Development Only)

DANGER

A database cleanup endpoint exists for development purposes only.

  • Endpoint: DELETE /api/db-cleanup
  • Requires: Super Admin authentication
  • Action: Deletes ALL data across ALL choirs
  • NEVER run in production — no undo available

Production Safety Recommendations:

  • Disable this endpoint in production via environment variables
  • Use Azure Functions' deployment slots to exclude it from production code
  • Implement additional safeguards (e.g., require specific development-only header)
  • Monitor audit logs for any attempts to access this endpoint in production

To safely reset development data:

bash
cd api
npx ts-node scripts/setup-database.ts
npx ts-node scripts/seed-admin.ts your@email.com "Your Name"

Impersonation Best Practices

When using impersonation:

  • Always stop impersonation when done (ends audit session)
  • Review audit logs regularly
  • Impersonation is for debugging user issues, not data manipulation
  • All impersonation sessions are permanently logged

Next: Troubleshooting · See also: Environment Variables · Azure Deployment

Built with VitePress