Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion backend/src/drizzle/0002_add_events_system.sql
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ ALTER TABLE "event_contests" ADD CONSTRAINT "event_contests_event_id_events_id_f
ALTER TABLE "event_contests_score" ADD CONSTRAINT "event_contests_score_participant_id_event_participants_id_fk" FOREIGN KEY ("participant_id") REFERENCES "public"."event_participants"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "event_contests_score" ADD CONSTRAINT "event_contests_score_contest_id_event_contests_id_fk" FOREIGN KEY ("contest_id") REFERENCES "public"."event_contests"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "event_groups" ADD CONSTRAINT "event_groups_event_id_events_id_fk" FOREIGN KEY ("event_id") REFERENCES "public"."events"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "event_participants" ADD CONSTRAINT "event_participants_group_id_event_groups_id_fk" FOREIGN KEY ("group_id") REFERENCES "public"."event_groups"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "event_participants" ADD CONSTRAINT "event_participants_group_id_event_groups_id_fk" FOREIGN KEY ("group_id") REFERENCES "public"."event_groups"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "event_participants" ADD CONSTRAINT "event_participants_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "event_participants" ADD CONSTRAINT "event_participants_event_id_events_id_fk" FOREIGN KEY ("event_id") REFERENCES "public"."events"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
CREATE UNIQUE INDEX "event_contests_event_participant_unique" ON "event_contests_score" USING btree ("participant_id","contest_id");--> statement-breakpoint
Expand Down
4 changes: 2 additions & 2 deletions backend/src/drizzle/meta/0002_snapshot.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"id": "aa1e8a8d-7508-414e-ad75-e9329e2d6f2e",
"id": "172bd506-499c-40cd-bb45-f307f9582d77",
"prevId": "335e119b-5faa-46ca-8651-5f40253d9945",
"version": "7",
"dialect": "postgresql",
Expand Down Expand Up @@ -394,7 +394,7 @@
"columnsTo": [
"id"
],
"onDelete": "set null",
"onDelete": "cascade",
"onUpdate": "no action"
},
"event_participants_user_id_users_id_fk": {
Expand Down
2 changes: 1 addition & 1 deletion backend/src/drizzle/meta/_journal.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
{
"idx": 2,
"version": "7",
"when": 1781094244694,
"when": 1782063027883,
"tag": "0002_add_events_system",
"breakpoints": true
}
Expand Down
2 changes: 1 addition & 1 deletion backend/src/drizzle/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ export const eventParticipants = pgTable(
"event_participants",
{
id: serial("id").primaryKey(),
groupId: integer("group_id").references(() => eventGroups.id, {onDelete: "set null",}),
groupId: integer("group_id").references(() => eventGroups.id, {onDelete: "cascade",}),
userId: text("user_id").notNull().references(() => users.id),
eventId: integer("event_id").notNull().references(() => events.id, { onDelete: "cascade" }),
participantScore: integer("participant_score").notNull().default(0),
Expand Down
13 changes: 12 additions & 1 deletion backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { client, db } from "./drizzle/db";
import { users } from "./drizzle/schema";
import { eq } from "drizzle-orm";
import { startCronJobs } from "./cron";
import {cruxMembers} from "./middlewares/auth"
import {
fetchContests,
fetchProblems,
Expand Down Expand Up @@ -115,11 +116,21 @@ passport.deserializeUser(async (userId: string, done) => {
.where(eq(users.id, userId))
.limit(1)
.then((rows) => rows[0]);
done(null, user);

if (user) {
const userwithisCruxMemberProperty= {
...user,
isCruxMember: cruxMembers.has(user.cfHandle ?? ''),
};

return done(null, userwithisCruxMemberProperty);
}
done(null, null);
} catch (error) {
console.error("Error deserializing user:", error);
done(new Error("Could not deserialize user"), null);
}

});

const limiter = rateLimit({
Expand Down
3 changes: 2 additions & 1 deletion backend/src/middlewares/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ export function requireAuth(req: Request, res: Response, next: NextFunction) {
next();
}

const cruxMembers = new Set<string>([
export const cruxMembers = new Set<string>([
"cwswastik",
"Rittin_Sehgal",
"manjot1151",
"aten2005",
"Yash_Kejriwal",
"Ellufino",
"chicubed",
]);

export const requireCruxMember: RequestHandler = async (
Expand Down
2 changes: 1 addition & 1 deletion backend/src/routes/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ router.get("/:id", async (req, res) => {
res.status(404).json({ message: "not found" });
return;
}
const contests = await db.select().from(eventContests).where(eq(eventContests.eventId, id));
const contests = await db.select().from(eventContests).where(eq(eventContests.eventId, id)).orderBy(desc(eventContests.startTime));;
res.status(200).json({ ...event, contests });
} catch (err) {
console.error(`error: ${err}`);
Expand Down
22 changes: 19 additions & 3 deletions frontend/src/routes/events/$slug/admin.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React, { useState, useEffect, useCallback } from 'react';
import { createFileRoute } from '@tanstack/react-router';
import { createFileRoute, useParams, Navigate } from '@tanstack/react-router';
import axios from 'axios';
import {
Trash2, Pencil, Users, UserPlus, Trophy, Mail, CheckCircle, History, RefreshCw
} from 'lucide-react';
import { useParams } from '@tanstack/react-router'

const emailRegex = /^f\d{8}@hyderabad\.bits-pilani\.ac\.in$/;
import { useAuth } from "../../../context/AuthContext.tsx";

interface GroupMember {
email: string;
participantId: number;
Expand All @@ -25,13 +25,29 @@ interface PastContest {
duration: string;
}

const emailRegex = /^f\d{8}@hyderabad\.bits-pilani\.ac\.in$/;
const scrollbar = "[&::-webkit-scrollbar]:w-1.5 [&::-webkit-scrollbar-thumb]:bg-slate-700 [&::-webkit-scrollbar-thumb]:rounded-full";

export const Route = createFileRoute('/events/$slug/admin')({
component: AdminEventsComponent,
});

function AdminEventsComponent() {
const { user, loading } = useAuth();

if (loading) {
return (
<div className="min-h-screen flex items-center justify-center bg-slate-900 text-slate-300">
Loading admin dashboard...
</div>
);
}

// Kick out non crux guys
if (!user || !user.isCruxMember) {
return <Navigate to="/events" replace />;
}

const [contestId, setContestId] = useState('');
const [isContestSaved, setIsContestSaved] = useState(false);

Expand Down
1 change: 1 addition & 0 deletions frontend/src/types/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export interface User {
id: string;
email: string;
name: string;
isCruxMember?: boolean;
pfpUrl: string;
cfHandle: string | null;
cfRating: number | null;
Expand Down