Skip to content

Commit 063b2a9

Browse files
authored
feat: polish applications (#42)
1 parent 328dbea commit 063b2a9

File tree

38 files changed

+1250
-992
lines changed

38 files changed

+1250
-992
lines changed

.github/workflows/api.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ jobs:
100100
env:
101101
DATABASE_URL: postgres://postgres:postgres@localhost:5432/test_db
102102
run: pnpm test
103-
103+
104104
push:
105105
name: Pushes container to docker container hub
106106
runs-on: ubuntu-latest
@@ -121,6 +121,3 @@ jobs:
121121
docker tag events-api $IMAGE_ID:${{ github.sha }}
122122
docker push $IMAGE_ID:${{ github.sha }}
123123
docker push $IMAGE_ID:latest
124-
125-
126-

apps/api/.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ DATABASE_URL="postgresql://user:[email protected]/neondb?sslmode
55
# Get these from https://dashboard.clerk.com
66
CLERK_PUBLISHABLE_KEY=pk_test_your_publishable_key
77
CLERK_SECRET_KEY=sk_test_your_secret_key
8+
9+
CLERK_WEBHOOK_SECRET=whsec_your_webhook_secret

apps/api/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"nanoid": "^5.1.6",
3030
"nodemon": "^3.1.11",
3131
"pg": "^8.16.3",
32+
"svix": "^1.84.1",
3233
"zod": "^4.2.1"
3334
},
3435
"devDependencies": {

apps/api/src/db/schema.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ export const registrationsTable = pgTable(
7373
eventId: text("event_id")
7474
.notNull()
7575
.references(() => eventsTable.id, { onDelete: "cascade" }),
76-
status: registrationStatus("status").default("pending"),
76+
status: registrationStatus("status").notNull().default("pending"),
7777
answers: json("form_data").$type<RegistrationFormAnswer>(),
78-
createdAt: timestamp("created_at").defaultNow(),
78+
createdAt: timestamp("created_at").notNull().defaultNow(),
7979
updatedAt: timestamp("updated_at")
8080
.defaultNow()
8181
.$onUpdate(() => new Date()),

apps/api/src/lib/auth-guard.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { getAuth } from "@clerk/fastify";
2+
import { FastifyReply, FastifyRequest } from "fastify";
3+
4+
const requireAuth = async (request: FastifyRequest, reply: FastifyReply) => {
5+
const { userId, sessionClaims } = getAuth(request);
6+
const role = sessionClaims?.metadata?.role;
7+
8+
if (!userId || !role) {
9+
return reply.status(401).send({ message: "Unauthorised" });
10+
}
11+
12+
request.user = { userId, role };
13+
};
14+
15+
const requireCommittee = async (request: FastifyRequest, reply: FastifyReply) => {
16+
await requireAuth(request, reply);
17+
18+
if (request.user.role !== "committee") {
19+
return reply.status(401).send({ message: "Unauthorised" });
20+
}
21+
};
22+
23+
export { requireAuth, requireCommittee };
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { z } from "zod";
2+
3+
export const QueryFilterSchema = z.object({
4+
page: z.coerce.number().min(1).default(1),
5+
limit: z.coerce.number().min(1).max(100).default(20),
6+
});

0 commit comments

Comments
 (0)