Skip to content

Commit 46a1e66

Browse files
authored
Merge pull request #55 from DataScience-GT/refactor/routes
Refactor/routes
2 parents c38ece6 + 4580afb commit 46a1e66

File tree

6 files changed

+22
-12
lines changed

6 files changed

+22
-12
lines changed

packages/api/src/context.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ export async function createContext(
2222
) {
2323
let session = null;
2424

25-
// Extract request from opts if available (priority to explicit req)
26-
const req = opts?.req || opts?.req;
25+
// Extract request from opts if available
26+
const req = opts?.req;
2727

2828
// Only attempt auth if database is available
2929
if (db) {

packages/api/src/middleware/cache.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,13 @@ export class CacheService {
6767
}
6868

6969
/**
70-
* Delete all keys matching a pattern
70+
* Delete all keys matching a pattern (glob-style with * wildcard)
7171
*/
7272
deletePattern(pattern: string): number {
7373
let count = 0;
74-
const regex = new RegExp(pattern.replace(/\*/g, '.*'));
74+
// Escape regex special chars, then convert * to .*
75+
const escaped = pattern.replace(/[.+?^${}()|[\]\\]/g, '\\$&');
76+
const regex = new RegExp(`^${escaped.replace(/\*/g, '.*')}$`);
7577

7678
for (const key of this.cache.keys()) {
7779
if (regex.test(key)) {

packages/api/src/routers/judge.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@ import {
1414
import { eq, and, asc, desc, sql } from "drizzle-orm";
1515
import { CacheKeys } from "../middleware/cache";
1616

17+
// Fisher-Yates shuffle for unbiased randomization
18+
function shuffleArray<T>(array: T[]): T[] {
19+
const result = [...array];
20+
for (let i = result.length - 1; i > 0; i--) {
21+
const j = Math.floor(Math.random() * (i + 1));
22+
[result[i], result[j]] = [result[j], result[i]];
23+
}
24+
return result;
25+
}
26+
1727
// Middleware to check if user is a judge
1828
const isJudge = protectedProcedure.use(async ({ ctx, next }) => {
1929
const judge = await ctx.db!.query.judges.findFirst({
@@ -631,9 +641,9 @@ export const judgeRouter = createTRPCRouter({
631641
orderBy: [asc(judgingProjects.tableNumber)],
632642
});
633643

634-
// Optionally shuffle
644+
// Optionally shuffle using Fisher-Yates algorithm
635645
if (input.shuffle) {
636-
projects = projects.sort(() => Math.random() - 0.5);
646+
projects = shuffleArray(projects);
637647
}
638648

639649
// Create queue entries

sites/mainweb/components/Background/index.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import React from "react";
44

55
interface BackgroundProps extends React.HTMLAttributes<HTMLDivElement> {}
66

7-
const Background: React.FC<BackgroundProps> = (props) => {
7+
export default function Background(props: BackgroundProps) {
88
return (
99
<div
1010
{...props}
@@ -19,6 +19,4 @@ const Background: React.FC<BackgroundProps> = (props) => {
1919
<div className="absolute w-full h-full"></div>
2020
</div>
2121
);
22-
};
23-
24-
export default Background;
22+
}

sites/mainweb/eslint.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { nextJsConfig } from "@query/eslint-config/next-js";
1+
import nextJsConfig from "@query/eslint-config/next-js";
22

33
/** @type {import("eslint").Linter.Config} */
44
export default nextJsConfig;

tooling/eslint/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"type": "module",
66
"exports": {
77
"./base": "./base.js",
8-
"./nextjs": "./nextjs.js",
8+
"./next-js": "./next.js",
99
"./react": "./react.js"
1010
},
1111
"scripts": {

0 commit comments

Comments
 (0)