Skip to content

Commit c62889e

Browse files
committed
feat: flight audit log stats for cephie
1 parent 852fff5 commit c62889e

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

server/db/flightLogs.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,19 @@ export interface FlightLogData {
1313
ipAddress?: string | null;
1414
}
1515

16+
export async function getFlightLogsCount(): Promise<number> {
17+
try {
18+
const row = await mainDb
19+
.selectFrom('flight_logs')
20+
.select(({ fn }) => fn.countAll().as('count'))
21+
.executeTakeFirst();
22+
return Number(row?.count) || 0;
23+
} catch (error) {
24+
console.error('Error counting flight logs:', error);
25+
throw error;
26+
}
27+
}
28+
1629
export async function logFlightAction(logData: FlightLogData) {
1730
const {
1831
userId,

server/routes/data.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { getActiveNotifications } from '../db/notifications.js';
77
import { mainDb, flightsDb, redisConnection } from '../db/connection.js';
88
import { getTopUsers, STATS_KEYS, getUserRank } from '../db/leaderboard.js';
99
import { getUserById } from '../db/users.js';
10+
import { getFlightLogsCount } from '../db/flightLogs.js';
1011
import { getWaypointData } from '../utils/getData.js';
1112
import { findPath } from '../utils/findRoute.js';
1213
import { sql } from 'kysely';
@@ -440,6 +441,8 @@ router.get('/statistics', async (req, res) => {
440441
.select(({ fn }) => fn.countAll().as('count'))
441442
.executeTakeFirst();
442443

444+
const flightLogsCount = await getFlightLogsCount();
445+
443446
const sessions = await mainDb
444447
.selectFrom('sessions')
445448
.select(['session_id'])
@@ -468,6 +471,7 @@ router.get('/statistics', async (req, res) => {
468471
sessionsCreated: Number(sessionsCreated?.count) || 0,
469472
registeredUsers: Number(registeredUsers?.count) || 0,
470473
flightsLogged,
474+
flightLogs: flightLogsCount,
471475
};
472476

473477
try {

0 commit comments

Comments
 (0)