Skip to content

Update to typescript 6, strict mode on backend and lint#2156

Open
itamaroryan wants to merge 4 commits into
mainfrom
chore/typescript-6
Open

Update to typescript 6, strict mode on backend and lint#2156
itamaroryan wants to merge 4 commits into
mainfrom
chore/typescript-6

Conversation

@itamaroryan

Copy link
Copy Markdown
Member

Closes #2150

@itamaroryan itamaroryan requested a review from johnmeshulam July 3, 2026 13:11
@github-project-automation github-project-automation Bot moved this to Backlog in LEMS Jul 3, 2026
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' });
Comment thread apps/backend/src/main.ts

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 } } =>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Terrible type hack

endDate,
location: event.location,
coordinates: event.coordinates,
coordinates: event.coordinates ?? undefined,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should support null

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';

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

enter?

place: award.place,
index: award.index,
...(includeWinner && { winner })
...(includeWinner && winner != null && { winner })

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what

data['missions'][missionId] ??= {};
data['missions'][missionId][clauseIndex] = value;
const points = calculateScore(data['missions']);
type MissionData = Record<string, Record<number, ScoresheetClauseValue>>;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this check be done in a simpler way? Maybe zod or smth?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

Migrate to typescript 6

3 participants