NestJS + Prisma/Postgres API shared by the site, admin and attendee app. Ports the site's D1 application flow and review, stores every inquiry form, sells tickets with discount codes (manual payment confirmation), and runs booth/startup/mystery-investee QR scans with derived points and raffles. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
58 lines
3.3 KiB
Markdown
58 lines
3.3 KiB
Markdown
# GRV Backend
|
||
|
||
One API for the GRV Summit: startup applications, website inquiries, ticket sales and discounts, merch,
|
||
and the event game (booth / startup / mystery-investee QR scans, points, raffles).
|
||
Used by the site ([GRVSummit](../GRVSummit)), the admin portal ([GRV-Admin](../GRV-Admin)) and the attendee app ([GRV-Application](../GRV-Application)).
|
||
|
||
**Contract:** [`API.md`](API.md). Swagger UI runs at `/docs`.
|
||
|
||
Stack: NestJS 12, Prisma 7 + Postgres, zod, jose (JWT), Resend (email over HTTP), qrcode.
|
||
|
||
## Run locally
|
||
|
||
```bash
|
||
pnpm install
|
||
cp .env.example .env # set JWT_SECRET and ADMIN_EMAILS to your email
|
||
docker compose up -d # Postgres on :5432
|
||
# no Docker? `pnpm db:dev` (PGlite on :5433), then in .env:
|
||
# DATABASE_URL=postgresql://postgres:postgres@127.0.0.1:5433/postgres and DATABASE_POOL_MAX=1
|
||
pnpm db:migrate
|
||
pnpm db:seed # sectors + ticket tiers; `pnpm db:seed --demo` adds sample checkpoints, merch and a raffle
|
||
pnpm start:dev # http://localhost:4000
|
||
pnpm test # discounts, orders, scans, raffle (in-memory Postgres, no setup needed)
|
||
```
|
||
|
||
With `RESEND_API_KEY` empty, every email, including sign-in codes, is printed to the console instead of sent.
|
||
|
||
## Rules worth knowing
|
||
|
||
- **Money:** integer minor units (cents). **Times:** UTC.
|
||
- **Logins:** email OTP for everyone. Role comes from `ADMIN_EMAILS` / `STAFF_EMAILS` on each login; everyone else is an `ATTENDEE`. Removing an email from the list demotes them at their next login.
|
||
- **Points** are never stored. They are `SUM(scans.points_awarded)`, and each user/checkpoint pair is unique, so a repeat scan can't earn twice. A mystery investee awards `points × 2`.
|
||
- **Discount uses** are counted from PAID/FULFILLED orders, so abandoned orders don't burn a code.
|
||
- **Payments:** ticket orders are created PENDING with manual/bank instructions (`PAYMENT_INSTRUCTIONS`). Staff confirm with *Mark paid* in the admin, which issues one QR ticket per seat and emails them. A gateway webhook should call `CommerceService.markPaid`.
|
||
- **QR codes:** they encode `SITE_URL/q/<token>` for checkpoints and `SITE_URL/t/<token>` for tickets, so a normal phone camera opens the site, and the app scans the same URL.
|
||
- **Applications:** the field definitions and validation in `src/shared/` are copied from the site (`GRVSummit/content/apply.ts`, `lib/apply-validation.ts`). Keep both copies in sync when the form changes. Step answers outside step 1 and documents are stored as JSON, so new questions need no migration.
|
||
|
||
## Moving the site's existing applications
|
||
|
||
```bash
|
||
cd ../GRVSummit && npx wrangler d1 export grv-summit --remote --no-schema --output d1.sql
|
||
cd ../GRV-Backend && pnpm db:import-d1 ../GRVSummit/d1.sql # safe to re-run
|
||
```
|
||
|
||
## Deploy (VPS)
|
||
|
||
```bash
|
||
pnpm install --frozen-lockfile && pnpm build && pnpm db:migrate && pnpm db:seed
|
||
pm2 start dist/src/main.js --name grv-backend # NODE_ENV=production, env from .env
|
||
```
|
||
|
||
Put it behind HTTPS (e.g. `api.grv.ethiopiatrustfund.org`). Set `CORS_ORIGINS` to the site and admin origins and `ADMIN_URL` to the admin's URL (used in staff emails).
|
||
|
||
## Not built yet
|
||
|
||
- Payment gateway (Chapa/Telebirr/Stripe): add it when the provider is chosen.
|
||
- Push notifications and SMS.
|
||
- Document uploads: applications still take Drive/Dropbox links.
|