Update to typescript 6, strict mode on backend and lint#2156
Open
itamaroryan wants to merge 4 commits into
Open
Update to typescript 6, strict mode on backend and lint#2156itamaroryan wants to merge 4 commits into
itamaroryan wants to merge 4 commits into
Conversation
| import exportRouter from './export'; | ||
|
|
||
| const router = express.Router({ mergeParams: true }); | ||
|
|
Comment on lines
+13
to
+80
|
|
||
| router.use('/:teamSlug/:eventSlug', async (req: Request, res: Response, next: NextFunction) => { | ||
| const { teamSlug, eventSlug } = req.params; | ||
|
|
||
| if (!teamSlug || typeof teamSlug !== 'string') { | ||
| res.status(400).json({ error: 'Invalid team slug' }); | ||
| return; | ||
| } | ||
|
|
||
| if (!eventSlug || typeof eventSlug !== 'string') { | ||
| res.status(400).json({ error: 'Invalid event slug' }); | ||
| return; | ||
| } | ||
|
|
||
| try { | ||
| const token = extractToken(req); | ||
| const tokenData = jwt.verify(token, integrationsJwtSecret) as { | ||
| teamSlug: string; | ||
| divisionId: string; | ||
| }; | ||
|
|
||
| // Validate team and event from token | ||
| const team = await db.teams.bySlug(teamSlug).get(); | ||
| if (!team) { | ||
| throw new Error('Team not found'); | ||
| } | ||
| if (teamSlug !== tokenData.teamSlug) { | ||
| throw new Error('Invalid team slug'); | ||
| } | ||
|
|
||
| const event = await db.events.bySlug(eventSlug).get(); | ||
| if (!event) { | ||
| throw new Error('Event not found'); | ||
| } | ||
| if (event.slug !== eventSlug) { | ||
| throw new Error('Invalid event slug'); | ||
| } | ||
|
|
||
| const teamDivision = await db.teams.bySlug(teamSlug).isInEvent(event.id); | ||
| if (!teamDivision) { | ||
| throw new Error('Team is not part of the event'); | ||
| } | ||
|
|
||
| if (teamDivision !== tokenData.divisionId) { | ||
| throw new Error('Invalid division ID'); | ||
| } | ||
|
|
||
| // Validate that the event is published | ||
| const eventSettings = await db.events.bySlug(eventSlug).getSettings(); | ||
| if (!eventSettings) { | ||
| throw new Error('Event settings not found'); | ||
| } | ||
| if (!eventSettings.published) { | ||
| throw new Error('Event not published'); | ||
| } | ||
|
|
||
| // Attach validated data to request for downstream handlers | ||
| (req as ExportRequest).team = team; | ||
| (req as ExportRequest).event = event; | ||
| (req as ExportRequest).divisionId = teamDivision; | ||
|
|
||
| next(); | ||
| return; | ||
| } catch { | ||
| // Invalid token | ||
| } | ||
|
|
||
| res.status(401).json({ error: 'UNAUTHORIZED' }); |
johnmeshulam
reviewed
Jul 4, 2026
Member
There was a problem hiding this comment.
I think user: null should be valid and we shouldnt fall back to undefined
|
|
||
| const rankingData = await getTeamRankingData(teamDivision, req.teamId); | ||
| const robotGameRank = rankingData?.rank ?? null; | ||
| const robotGameRank = rankingData?.rank ?? 0; |
Member
There was a problem hiding this comment.
This might cause null teams to be at the top of the list -> 0 < 1
|
|
||
| const submittedScoresheets = scoresheets.filter( | ||
| s => s.status === 'submitted' && s.data?.score != null | ||
| (s): s is typeof s & { data: { score: number } } => |
| endDate, | ||
| location: event.location, | ||
| coordinates: event.coordinates, | ||
| coordinates: event.coordinates ?? undefined, |
Member
There was a problem hiding this comment.
Shouod support null - dont fall back to undefined
| type: award.type, | ||
| showPlaces: award.show_places, | ||
| winner: award.type === 'PERSONAL' ? award.winner_name : award.winner_id, | ||
| winner: (award.type === 'PERSONAL' ? award.winner_name : award.winner_id) ?? undefined, |
| import fileUpload from 'express-fileupload'; | ||
| import db from '../../../../../lib/database'; | ||
| import { requirePermission } from '../../../middleware/require-permission'; | ||
| import { AdminDivisionRequest } from '../../../../../types/express';import { asHandler } from '../../../../../types/express-handlers'; |
| place: award.place, | ||
| index: award.index, | ||
| ...(includeWinner && { winner }) | ||
| ...(includeWinner && winner != null && { winner }) |
Member
There was a problem hiding this comment.
winner should be null if included and no winner - this is wrong
| if (timeoutHandle) clearTimeout(timeoutHandle); | ||
| broadcaster.removeListener('event', messageHandler); | ||
| if (resolveWait) resolveWait(); | ||
| const pendingResolve = resolveWait as (() => void) | null; |
| data['missions'][missionId] ??= {}; | ||
| data['missions'][missionId][clauseIndex] = value; | ||
| const points = calculateScore(data['missions']); | ||
| type MissionData = Record<string, Record<number, ScoresheetClauseValue>>; |
Member
There was a problem hiding this comment.
Can we define this top level?
| * Optionally includes isFullySetUp if provided (e.g., from aggregated queries). | ||
| */ | ||
| function buildResult(event: Partial<Event> & { is_fully_set_up?: boolean; official?: boolean }): EventGraphQL { | ||
| function buildResult( |
Member
There was a problem hiding this comment.
Can this check be done in a simpler way? Maybe zod or smth?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2150