35 lines
968 B
TypeScript
35 lines
968 B
TypeScript
import { GetSessionResponse } from "../contract";
|
|
import { db } from "./init";
|
|
|
|
export async function getSession(id: string): Promise<GetSessionResponse> {
|
|
// extract the session
|
|
const session = await db
|
|
.selectFrom("session_info")
|
|
.where("id", "=", id)
|
|
.select(["game_name", "version"])
|
|
.executeTakeFirstOrThrow();
|
|
|
|
// get all the connected log entries
|
|
const logEntries = await db
|
|
.selectFrom("log_entries")
|
|
.where("session_info_id", "=", id)
|
|
.select(["id", "message", "timestamp", "category", "metadata"])
|
|
.orderBy("timestamp", "asc")
|
|
.execute();
|
|
|
|
// build the object accordingly
|
|
return {
|
|
game_name: session.game_name,
|
|
version: session.version,
|
|
log_entries: logEntries.map((entry) => ({
|
|
message: entry.message,
|
|
timestamp: entry.timestamp,
|
|
category: entry.category,
|
|
metadata: entry.metadata.reduce(
|
|
(acc, m) => ({ ...acc, [m[0]]: m[1] }),
|
|
{}
|
|
),
|
|
})),
|
|
};
|
|
}
|