Skip to content

Commit 0821040

Browse files
committed
fixes (final)
1 parent bd70c1a commit 0821040

11 files changed

Lines changed: 1591 additions & 1566 deletions

File tree

nodemon.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"watch": ["server"],
3+
"ext": "ts,json",
4+
"exec": "tsx server/main.ts"
5+
}

package-lock.json

Lines changed: 45 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"version": "0.0.0",
55
"type": "module",
66
"scripts": {
7-
"dev": "set NODE_ENV=development && concurrently \"vite\" \"npx tsx server/main.ts\"",
7+
"dev": "set NODE_ENV=development && concurrently \"vite\" \"npx nodemon\"",
88
"prod": "cross-env NODE_ENV=production node server/dist/server.js",
99
"build": "vite build --mode production",
1010
"build:dev": "vite build --mode development",
@@ -19,7 +19,6 @@
1919
"@dnd-kit/sortable": "^10.0.0",
2020
"@dnd-kit/utilities": "^3.2.2",
2121
"@tailwindcss/vite": "^4.1.13",
22-
"@types/node": "^24.7.2",
2322
"axios": "^1.12.2",
2423
"chalk": "^5.6.2",
2524
"chart.js": "^4.5.0",
@@ -58,6 +57,7 @@
5857
"@types/express": "^5.0.3",
5958
"@types/jsonwebtoken": "^9.0.10",
6059
"@types/multer": "^2.0.0",
60+
"@types/node": "^24.7.2",
6161
"@types/pg": "^8.15.5",
6262
"@types/react": "^19.1.13",
6363
"@types/react-dom": "^19.1.9",
@@ -70,6 +70,7 @@
7070
"nodemon": "^3.1.10",
7171
"prettier": "^3.6.2",
7272
"ts-node": "^10.9.2",
73+
"tsx": "^4.20.6",
7374
"typescript": "~5.8.3",
7475
"typescript-eslint": "^8.44.0",
7576
"vite": "^7.1.7"

server/db/admin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ export async function getAllUsers(page = 1, limit = 50, search = '', filterAdmin
209209
}
210210
}
211211

212-
const countQuery = query.clearSelect().select(({ fn }) => fn.countAll().as('count'));
212+
const countQuery = query.clearSelect().clearOrderBy().select(({ fn }) => fn.countAll().as('count'));
213213
const countResult = await countQuery.executeTakeFirst();
214214
totalUsers = Number(countResult?.count) || 0;
215215

server/db/flights.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,15 @@ export async function addFlight(sessionId: string, flightData: AddFlightData) {
299299
flightData.sid = sidResult.sid;
300300
}
301301

302+
if (flightData.cruisingFL !== undefined) {
303+
flightData.cruisingfl = flightData.cruisingFL;
304+
delete flightData.cruisingFL;
305+
}
306+
if (flightData.clearedFL !== undefined) {
307+
flightData.clearedfl = flightData.clearedFL;
308+
delete flightData.clearedFL;
309+
}
310+
302311
const { icao, ...flightDataForDb } = flightData;
303312

304313
const result = await flightsDb
@@ -367,7 +376,13 @@ export async function updateFlight(
367376
throw new Error('No valid fields to update');
368377
}
369378

370-
dbUpdates.updated = new Date().toISOString();
379+
dbUpdates.updated_at = new Date();
380+
381+
try {
382+
await sql`ALTER TABLE ${sql.table(tableName)} ADD COLUMN IF NOT EXISTS "updated_at" TIMESTAMP;`.execute(flightsDb);
383+
} catch (err) {
384+
console.error('Could not ensure column exists:', 'updated_at', String(err));
385+
}
371386

372387
const result = await flightsDb
373388
.updateTable(tableName)

server/routes/atis.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,16 @@ router.post('/generate', requireAuth, async (req, res) => {
8484

8585
const atisTimestamp = new Date().toISOString();
8686

87-
const updatedSession = await updateSession(sessionId, { atis: generatedAtis });
87+
const atisData = {
88+
letter: ident,
89+
text: generatedAtis,
90+
timestamp: atisTimestamp,
91+
};
92+
const updatedSession = await updateSession(sessionId, { atis: JSON.stringify(atisData) });
8893
if (!updatedSession) {
8994
throw new Error('Failed to update session with ATIS data');
9095
}
96+
console.log('ATIS updated successfully. Session atis:', updatedSession.atis);
9197

9298
res.json({
9399
atisText: generatedAtis,

server/routes/flights.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ router.post('/:sessionId', optionalAuth, flightCreationLimiter, async (req, res)
3535

3636
await recordNewFlight();
3737

38-
// Remove sensitive fields before broadcasting
39-
const sanitizedFlight = flight ? Object.fromEntries(Object.entries(flight).filter(([k]) => !['acars_token', 'user_id', 'ip_address'].includes(k))) : {};
40-
broadcastFlightEvent(req.params.sessionId, 'flightAdded', sanitizedFlight);
38+
const sanitizedFlight = flight ? Object.fromEntries(Object.entries(flight).filter(([k]) => !['acars_token', 'user_id', 'ip_address'].includes(k))) : {};
39+
broadcastFlightEvent(req.params.sessionId, 'flightAdded', sanitizedFlight);
4140
res.status(201).json(flight);
42-
} catch {
41+
} catch (err) {
42+
console.error('Failed to add flight:', err);
4343
res.status(500).json({ error: 'Failed to add flight' });
4444
}
4545
});

server/routes/sessions.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import { sanitizeAlphanumeric } from '../utils/sanitization';
1818

1919
import { Request, Response } from 'express';
2020
import { JwtPayloadClient } from '../types/JwtPayload';
21-
import { decrypt } from '../utils/encryption';
2221

2322
function isJwtPayloadClient(user: unknown): user is JwtPayloadClient {
2423
return (
@@ -142,8 +141,9 @@ router.get('/:sessionId', requireSessionAccess, async (req, res) => {
142141
let atis = { letter: 'A', text: '', timestamp: new Date().toISOString() };
143142
if (session.atis) {
144143
try {
145-
atis = decrypt(JSON.parse(session.atis));
146-
} catch {
144+
atis = JSON.parse(session.atis);
145+
} catch (e) {
146+
console.log('parse error:', e);
147147
// fallback to default atis
148148
}
149149
}
@@ -176,7 +176,7 @@ router.put('/:sessionId', requireSessionAccess, async (req, res) => {
176176
let decryptedAtis = { letter: 'A', text: '', timestamp: new Date().toISOString() };
177177
if (session.atis) {
178178
try {
179-
decryptedAtis = decrypt(JSON.parse(session.atis));
179+
decryptedAtis = JSON.parse(session.atis);
180180
} catch {
181181
// fallback to default atis
182182
}

0 commit comments

Comments
 (0)