Skip to content

Commit 10db91f

Browse files
committed
D7: Docker files, bug fixes
1 parent 50fc62b commit 10db91f

File tree

6 files changed

+33
-10
lines changed

6 files changed

+33
-10
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,13 @@
11
#!/bin/sh
2+
3+
# Drizzle will handle its own logic to remove conflicts
4+
npm run db:prod:migrate
5+
6+
# Checks admin table and will not seed if data exists
7+
npm run db:prod:seed
8+
9+
rm -rf drizzle src tsconfig.json
10+
11+
npm uninstall tsx drizzle-kit
12+
213
npm run start

backend/collaboration/express.Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ RUN npm ci --omit=dev
1515

1616
RUN sed -i 's|./ws|ws|g' ./dist/ws.js
1717

18+
# For migration
19+
RUN npm install tsx drizzle-kit
20+
COPY drizzle ./drizzle
21+
COPY src/lib/db/ ./src/lib/db
22+
COPY src/config.ts ./src
23+
COPY tsconfig.json .
1824
COPY entrypoint.sh .
1925

2026
ARG port

backend/collaboration/src/controller/room-auth-controller.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { eq } from 'drizzle-orm';
1+
import { sql } from 'drizzle-orm';
22
import type { Request, Response } from 'express';
33
import { StatusCodes } from 'http-status-codes';
44

@@ -7,8 +7,9 @@ import { db, rooms } from '@/lib/db';
77
export async function authCheck(req: Request, res: Response) {
88
const roomId = req.query.roomId as string | undefined;
99
const userId = req.query.userId as string | undefined;
10+
const questionId = req.query.questionId as string | undefined;
1011

11-
if (!roomId || !userId) {
12+
if (!roomId || !userId || !questionId) {
1213
return {
1314
code: StatusCodes.UNPROCESSABLE_ENTITY,
1415
error: {
@@ -18,7 +19,11 @@ export async function authCheck(req: Request, res: Response) {
1819
}
1920

2021
try {
21-
const room = await db.select().from(rooms).where(eq(rooms.roomId, roomId)).limit(1);
22+
const room = await db
23+
.select()
24+
.from(rooms)
25+
.where(sql`${rooms.roomId} = ${roomId} and ${rooms.questionId} = ${questionId}`)
26+
.limit(1);
2227

2328
if (room.length === 0) {
2429
return res.status(StatusCodes.NOT_FOUND).json({

frontend/src/routes/interview/[room]/main.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,10 @@ export const InterviewRoomContainer = () => {
2828
const { userId } = useAuthedRoute();
2929

3030
const safeRoomId = roomId ?? '';
31-
const safeUserId = userId ?? '';
3231

3332
const { data: authResult, error } = useSuspenseQuery({
34-
queryKey: ['checkRoomAuthorization', safeRoomId, safeUserId],
35-
queryFn: () => checkRoomAuthorization(safeRoomId!, safeUserId!),
33+
queryKey: ['checkRoomAuthorization', safeRoomId, userId, questionId],
34+
queryFn: () => checkRoomAuthorization(safeRoomId!, userId!, questionId),
3635
});
3736

3837
if (error || !authResult?.isAuthed || !roomId) {

frontend/src/services/collab-service.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import { collabApiGetClient } from './api-clients';
22

33
const COLLAB_SERVICE_ROUTES = {
4-
CHECK_ROOM_AUTH: '/room/auth?roomId=<roomId>&userId=<userId>',
4+
CHECK_ROOM_AUTH: '/room/auth?roomId=<roomId>&userId=<userId>&questionId=<questionId>',
55
};
66

7-
export const checkRoomAuthorization = (roomId: string, userId: string) => {
7+
export const checkRoomAuthorization = (roomId: string, userId: string, questionId: number) => {
88
return collabApiGetClient
99
.get(
10-
COLLAB_SERVICE_ROUTES.CHECK_ROOM_AUTH.replace(/<roomId>/, roomId).replace(/<userId>/, userId)
10+
COLLAB_SERVICE_ROUTES.CHECK_ROOM_AUTH.replace(/<roomId>/, roomId)
11+
.replace(/<userId>/, userId)
12+
.replace(/<questionId>/, questionId.toString())
1113
)
1214
.then((response) => {
1315
return { isAuthed: response.status < 400 };

scripts/migrate-seed-databases.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22

33
# Migrate Services
4-
migrate_services=("question" "user" "chat")
4+
migrate_services=("question" "user" "chat" "collaboration")
55
for service in "${migrate_services[@]}"; do
66
cd "backend/$service"
77
npm run db:migrate

0 commit comments

Comments
 (0)