Skip to content

Commit 5efb46d

Browse files
authored
Merge pull request #95 from techstartucalgary/backend
Backend to main - uptodate
2 parents 69e67a6 + 6bce274 commit 5efb46d

28 files changed

Lines changed: 2397 additions & 707 deletions

‎.github/workflows/cd-backend.yml‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,5 @@ jobs:
5252
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID_BACKEND }}
5353
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID_BACKEND }}
5454
run: |
55-
cd output
5655
vercel pull --yes --environment=production --token=$VERCEL_TOKEN
57-
vercel deploy --prod --token=$VERCEL_TOKEN --force
56+
vercel deploy --prod --token=$VERCEL_TOKEN --force

‎shatter-backend/api/index.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import 'dotenv/config';
22
import mongoose from 'mongoose';
3-
import app from '../src/app';
3+
import app from '../src/app.js';
44

55
const MONGODB_URI = process.env.MONGO_URI;
66

@@ -56,7 +56,7 @@ async function connectDB() {
5656

5757
connectDB().catch(console.error);
5858

59-
app.use(async (req, res, next) => {
59+
app.use(async (req: any, res: any, next: any) => {
6060
try {
6161
await connectDB();
6262
next();

‎shatter-backend/docs/API_REFERENCE.md‎

Lines changed: 160 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,61 @@
11
# Shatter Backend — API Reference
22

3-
**Last updated:** 2026-03-01
3+
**Last updated:** 2026-03-08
44
**Base URL:** `http://localhost:4000/api`
55

66
---
77

88
## Table of Contents
99

10-
- [General Information](#general-information)
11-
- [Endpoint Summary](#endpoint-summary)
12-
- [Authentication (`/api/auth`)](#authentication-apiauth)
13-
- [POST /api/auth/signup](#post-apiauthsignup)
14-
- [POST /api/auth/login](#post-apiauthlogin)
15-
- [GET /api/auth/linkedin](#get-apiauthlinkedin)
16-
- [GET /api/auth/linkedin/callback](#get-apiauthlinkedincallback)
17-
- [POST /api/auth/exchange](#post-apiauthexchange)
18-
- [Users (`/api/users`)](#users-apiusers)
19-
- [GET /api/users](#get-apiusers)
20-
- [POST /api/users](#post-apiusers)
21-
- [GET /api/users/me](#get-apiusersme)
22-
- [GET /api/users/:userId](#get-apiusersuserid)
23-
- [GET /api/users/:userId/events](#get-apiusersuseриdevents)
24-
- [PUT /api/users/:userId](#put-apiusersuserid)
25-
- [Events (`/api/events`)](#events-apievents)
26-
- [POST /api/events/createEvent](#post-apieventscreateevent)
27-
- [GET /api/events/event/:joinCode](#get-apieventseventjoincode)
28-
- [GET /api/events/:eventId](#get-apieventseventid)
29-
- [PUT /api/events/:eventId/status](#put-apieventseventidstatus)
30-
- [POST /api/events/:eventId/join/user](#post-apieventseventиdjoinuser)
31-
- [POST /api/events/:eventId/join/guest](#post-apieventseventиdjoinguest)
32-
- [GET /api/events/createdEvents/user/:userId](#get-apieventscreatedeventsuseriduserid)
33-
- [Bingo (`/api/bingo`)](#bingo-apibingo)
34-
- [POST /api/bingo/createBingo](#post-apibingocreatebingo)
35-
- [GET /api/bingo/getBingo/:eventId](#get-apibingogetbingoeventid)
36-
- [PUT /api/bingo/updateBingo](#put-apibingoupdatebingo)
37-
- [Participant Connections (`/api/participantConnections`)](#participant-connections-apiparticipantconnections)
38-
- [POST /api/participantConnections/](#post-apiparticipantconnections)
39-
- [POST /api/participantConnections/by-emails](#post-apiparticipantconnectionsby-emails)
40-
- [DELETE /api/participantConnections/delete](#delete-apiparticipantconnectionsdelete)
41-
- [GET /api/participantConnections/getByParticipantAndEvent](#get-apiparticipantconnectionsgetbyparticipantandevent)
42-
- [GET /api/participantConnections/getByUserEmailAndEvent](#get-apiparticipantconnectionsgetbyuseremailandevent)
43-
- [GET /api/participantConnections/connected-users](#get-apiparticipantconnectionsconnected-users)
44-
- [Planned Endpoints](#planned-endpoints-)
45-
- [Quick Start Examples](#quick-start-examples)
10+
- [Shatter Backend — API Reference](#shatter-backend--api-reference)
11+
- [Table of Contents](#table-of-contents)
12+
- [Endpoint Summary](#endpoint-summary)
13+
- [General Information](#general-information)
14+
- [Authentication](#authentication)
15+
- [Response Format](#response-format)
16+
- [Common Status Codes](#common-status-codes)
17+
- [Authentication (`/api/auth`)](#authentication-apiauth)
18+
- [POST `/api/auth/signup`](#post-apiauthsignup)
19+
- [POST `/api/auth/login`](#post-apiauthlogin)
20+
- [GET `/api/auth/linkedin`](#get-apiauthlinkedin)
21+
- [GET `/api/auth/linkedin/callback`](#get-apiauthlinkedincallback)
22+
- [POST `/api/auth/exchange`](#post-apiauthexchange)
23+
- [Users (`/api/users`)](#users-apiusers)
24+
- [GET `/api/users`](#get-apiusers)
25+
- [POST `/api/users`](#post-apiusers)
26+
- [GET `/api/users/me`](#get-apiusersme)
27+
- [GET `/api/users/:userId`](#get-apiusersuserid)
28+
- [GET `/api/users/:userId/events`](#get-apiusersuseridevents)
29+
- [PUT `/api/users/:userId`](#put-apiusersuserid)
30+
- [Events (`/api/events`)](#events-apievents)
31+
- [POST `/api/events/createEvent`](#post-apieventscreateevent)
32+
- [GET `/api/events/event/:joinCode`](#get-apieventseventjoincode)
33+
- [GET `/api/events/:eventId`](#get-apieventseventid)
34+
- [PUT `/api/events/:eventId/status`](#put-apieventseventidstatus)
35+
- [POST `/api/events/:eventId/join/user`](#post-apieventseventidjoinuser)
36+
- [POST `/api/events/:eventId/join/guest`](#post-apieventseventidjoinguest)
37+
- [GET `/api/events/createdEvents/user/:userId`](#get-apieventscreatedeventsuseruserid)
38+
- [Bingo (`/api/bingo`)](#bingo-apibingo)
39+
- [POST `/api/bingo/createBingo`](#post-apibingocreatebingo)
40+
- [GET `/api/bingo/getBingo/:eventId`](#get-apibingogetbingoeventid)
41+
- [PUT `/api/bingo/updateBingo`](#put-apibingoupdatebingo)
42+
- [POST `/api/bingo/generate`](#post-apibingogenerate)
43+
- [Participant Connections (`/api/participantConnections`)](#participant-connections-apiparticipantconnections)
44+
- [POST `/api/participantConnections/`](#post-apiparticipantconnections)
45+
- [POST `/api/participantConnections/by-emails`](#post-apiparticipantconnectionsby-emails)
46+
- [DELETE `/api/participantConnections/delete`](#delete-apiparticipantconnectionsdelete)
47+
- [GET `/api/participantConnections/getByParticipantAndEvent`](#get-apiparticipantconnectionsgetbyparticipantandevent)
48+
- [GET `/api/participantConnections/getByUserEmailAndEvent`](#get-apiparticipantconnectionsgetbyuseremailandevent)
49+
- [GET `/api/participantConnections/connected-users`](#get-apiparticipantconnectionsconnected-users)
50+
- [Planned Endpoints ⏳](#planned-endpoints-)
51+
- [Quick Start Examples](#quick-start-examples)
52+
- [1. Sign up](#1-sign-up)
53+
- [2. Log in](#2-log-in)
54+
- [3. Create an event](#3-create-an-event)
55+
- [4. Join the event (as authenticated user)](#4-join-the-event-as-authenticated-user)
56+
- [5. Join the event (as guest)](#5-join-the-event-as-guest)
57+
- [6. Create a bingo game for the event](#6-create-a-bingo-game-for-the-event)
58+
- [7. Get the bingo game](#7-get-the-bingo-game)
4659

4760
---
4861

@@ -169,7 +182,8 @@ Create a new user account.
169182
| 400 | `"name, email and password are required"` |
170183
| 400 | `"Invalid email format"` |
171184
| 400 | `"Password must be at least 8 characters long"` |
172-
| 409 | `"Email already exists"` |
185+
| 409 | `"Email already exists"` (local account) |
186+
| 409 | `"This email is associated with a LinkedIn account. Please log in with LinkedIn."` (LinkedIn account) |
173187

174188
---
175189

@@ -420,12 +434,18 @@ Get all events a user has joined (populates event details).
420434
"joinCode": "12345678",
421435
"startDate": "2025-02-01T18:00:00.000Z",
422436
"endDate": "2025-02-01T21:00:00.000Z",
423-
"currentState": "In Progress"
437+
"currentState": "In Progress",
438+
"participantIds": [
439+
{ "_id": "666b...", "name": "John Doe", "userId": "664f..." },
440+
{ "_id": "666c...", "name": "Jane Smith", "userId": "664e..." }
441+
]
424442
}
425443
]
426444
}
427445
```
428446

447+
**Note:** Each event's `participantIds` is populated with participant `name` and `userId` fields, enabling the frontend to load participant connections.
448+
429449
**Error Responses:**
430450

431451
| Status | Error |
@@ -456,6 +476,8 @@ Update a user's profile. Users can only update their own profile.
456476
| `bio` | string | |
457477
| `profilePhoto` | string | URL |
458478
| `socialLinks` | object | `{ linkedin?, github?, other? }` |
479+
| `organization` | string | Where the user works/studies |
480+
| `title` | string | Job title or role |
459481

460482
**Success Response (200):**
461483

@@ -716,13 +738,13 @@ Join an event as a registered (authenticated) user.
716738
| 404 | `"User not found"` |
717739
| 404 | `"Event not found"` |
718740
| 409 | `"User already joined"` |
719-
| 409 | `"This name is already taken in this event"` |
720741

721742
**Special Behavior:**
722743
- Creates a Participant record linking user to event
744+
- If the display name is already taken in the event, a `#XXX` suffix is automatically appended (e.g., `John` becomes `John#472`). The response `participant.name` reflects the final display name.
723745
- Adds participant to event's `participantIds` array
724746
- Adds event to user's `eventHistoryIds` array
725-
- Triggers Pusher event `participant-joined` on channel `event-{eventId}` with payload `{ participantId, name }`
747+
- Triggers Pusher event `participant-joined` on channel `event-{eventId}` with payload `{ participantId, name }` (using the final display name)
726748

727749
---
728750

@@ -740,9 +762,18 @@ Join an event as a guest (no account required).
740762

741763
**Request Body:**
742764

743-
| Field | Type | Required |
744-
|--------|--------|----------|
745-
| `name` | string | Yes |
765+
| Field | Type | Required | Description |
766+
|--------|--------|----------|-------------|
767+
| `name` | string | Yes | Display name |
768+
| `email` | string | No* | Email address |
769+
| `socialLinks` | object | No* | Social links |
770+
| `socialLinks.linkedin` | string | No | LinkedIn URL |
771+
| `socialLinks.github` | string | No | GitHub URL |
772+
| `socialLinks.other` | string | No | Other URL |
773+
| `organization` | string | No* | Where the guest works/studies |
774+
| `title` | string | No | Job title or role |
775+
776+
\* At least one of the following is required: `email`, a non-empty field in `socialLinks`, or `organization`.
746777

747778
**Success Response (200):**
748779

@@ -765,15 +796,18 @@ Join an event as a guest (no account required).
765796
| Status | Error |
766797
|--------|-------|
767798
| 400 | `"Missing fields: guest name and eventId are required"` |
799+
| 400 | `"At least one contact method (email or social link) or organization is required"` |
800+
| 400 | `"Invalid email format"` |
768801
| 400 | `"Event is full"` |
769802
| 404 | `"Event not found"` |
770-
| 409 | `"This name is already taken in this event"` |
803+
| 409 | `"A user with this email already exists"` |
771804

772805
**Special Behavior:**
773-
- Creates a guest User (`authProvider: 'guest'`, no email/password)
806+
- Creates a guest User (`authProvider: 'guest'`) with the provided contact info (email, social links, and/or organization)
807+
- If the display name is already taken in the event, a `#XXX` suffix is automatically appended (e.g., `John` becomes `John#472`). The response `participant.name` reflects the final display name, and the guest User's name is updated to match.
774808
- Returns a JWT so the guest can make authenticated requests
775809
- Guest can later upgrade to a full account via `PUT /api/users/:userId`
776-
- Triggers Pusher event `participant-joined` on channel `event-{eventId}` with payload `{ participantId, name }`
810+
- Triggers Pusher event `participant-joined` on channel `event-{eventId}` with payload `{ participantId, name }` (using the final display name)
777811

778812
---
779813

@@ -827,9 +861,9 @@ Create a bingo game for an event.
827861

828862
| Field | Type | Required | Notes |
829863
|---------------|------------|----------|-------|
830-
| `_eventId` | ObjectId | Yes | Must reference an existing event |
831-
| `description` | string | No | |
832-
| `grid` | string[][] | No | 2D array of strings |
864+
| `_eventId` | ObjectId | Yes | Must reference an existing event |
865+
| `description` | string | No | |
866+
| `grid` | BingoTile\[\]\[\] | No | 2D array of `{ question: string, shortQuestion: string }` |
833867

834868
**Success Response (201):**
835869

@@ -842,9 +876,16 @@ Create a bingo game for an event.
842876
"_eventId": "665a...",
843877
"description": "Networking Bingo",
844878
"grid": [
845-
["Has a pet", "Speaks 3 languages", "Loves hiking"],
846-
["Works remotely", "Free space", "Plays guitar"],
847-
["From another country", "Has a blog", "Codes in Rust"]
879+
[
880+
{ "question": "Has a pet", "shortQuestion": "Has pet" },
881+
{ "question": "Speaks 3 languages", "shortQuestion": "Speaks languages" },
882+
{ "question": "Loves hiking outdoors", "shortQuestion": "Loves hiking" }
883+
],
884+
[
885+
{ "question": "Works remotely full-time", "shortQuestion": "Works remotely" },
886+
{ "question": "Free space", "shortQuestion": "Free space" },
887+
{ "question": "Plays guitar regularly", "shortQuestion": "Plays guitar" }
888+
]
848889
]
849890
}
850891
}
@@ -856,7 +897,7 @@ Create a bingo game for an event.
856897
|--------|-------|
857898
| 400 | `"_eventId is required"` |
858899
| 400 | `"_eventId must be a valid ObjectId"` |
859-
| 400 | `"grid must be a 2D array of strings"` |
900+
| 400 | `"grid must be a 2D array of { question: string, shortQuestion: string }"` |
860901
| 404 | `"Event not found"` |
861902

862903
---
@@ -882,7 +923,12 @@ Get bingo by event ID (or bingo ID).
882923
"_id": "bingo_a1b2c3d4",
883924
"_eventId": "665a...",
884925
"description": "Networking Bingo",
885-
"grid": [["Has a pet", "Speaks 3 languages", ...], ...]
926+
"grid": [
927+
[
928+
{ "question": "Has a pet", "shortQuestion": "Has pet" },
929+
{ "question": "Speaks 3 languages", "shortQuestion": "Speaks languages" }
930+
]
931+
]
886932
}
887933
}
888934
```
@@ -905,9 +951,9 @@ Update a bingo game.
905951

906952
| Field | Type | Required | Notes |
907953
|---------------|------------|----------|-------|
908-
| `id` | string | Yes | Bingo `_id` or event `_eventId` |
909-
| `description` | string | No | |
910-
| `grid` | string[][] | No | 2D array of strings |
954+
| `id` | string | Yes | Bingo `_id` or event `_eventId` |
955+
| `description` | string | No | |
956+
| `grid` | BingoTile\[\]\[\] | No | 2D array of `{ question: string, shortQuestion: string }` |
911957

912958
**Success Response (200):**
913959

@@ -924,14 +970,67 @@ Update a bingo game.
924970
|--------|-------|
925971
| 400 | `"id is required"` |
926972
| 400 | `"description must be a string"` |
927-
| 400 | `"grid must be a 2D array of strings"` |
973+
| 400 | `"grid must be a 2D array of { question: string, shortQuestion: string }"` |
928974
| 400 | `"Nothing to update: provide description and/or grid"` |
929975
| 404 | `"Bingo not found"` |
930976

931977
**Special Behavior:** Tries to find by `_id` first, then falls back to `_eventId`.
932978

933979
---
934980

981+
### POST `/api/bingo/generate`
982+
983+
Generate an AI-powered bingo grid based on a given context.
984+
985+
- **Auth:** Protected
986+
987+
**Request Body:**
988+
989+
| Field | Type | Required | Notes |
990+
|-----------|--------|----------|-------|
991+
| `context` | string | Yes | Context used to generate bingo content |
992+
| `n_rows` | number | Yes | Number of rows (1–5) |
993+
| `n_cols` | number | Yes | Number of columns (1–5) |
994+
995+
**Example Request:**
996+
997+
```json
998+
{
999+
"context": "Software engineer networking event where developers meet, discuss tech stacks, exchange ideas, talk about startups, open source, AI, and career opportunities",
1000+
"n_rows": 2,
1001+
"n_cols": 2
1002+
}
1003+
```
1004+
1005+
**Example Response:**
1006+
```
1007+
{
1008+
"status": true,
1009+
"bingo_grid": [
1010+
[
1011+
{
1012+
"question": "Sketches architecture on a napkin",
1013+
"shortQuestion": "Napkin architecture"
1014+
},
1015+
{
1016+
"question": "Shows a product demo on phone",
1017+
"shortQuestion": "Phone product demo"
1018+
}
1019+
],
1020+
[
1021+
{
1022+
"question": "Explains their open-source contribution",
1023+
"shortQuestion": "Open-source contribution"
1024+
},
1025+
{
1026+
"question": "Asks 'What's your current stack?'",
1027+
"shortQuestion": "Current stack question"
1028+
}
1029+
]
1030+
]
1031+
}
1032+
```
1033+
9351034
## Participant Connections (`/api/participantConnections`)
9361035

9371036
### POST `/api/participantConnections/`
@@ -1242,7 +1341,8 @@ curl -X POST http://localhost:4000/api/events/<eventId>/join/user \
12421341
curl -X POST http://localhost:4000/api/events/<eventId>/join/guest \
12431342
-H "Content-Type: application/json" \
12441343
-d '{
1245-
"name": "Guest User"
1344+
"name": "Guest User",
1345+
"email": "guest@example.com"
12461346
}'
12471347
```
12481348

0 commit comments

Comments
 (0)