diff --git a/server/src/core/goal-core.ts b/server/src/core/goal-core.ts new file mode 100644 index 000000000..e69de29bb diff --git a/server/src/core/session-core.ts b/server/src/core/session-core.ts index 11725eeba..7c1fca6e7 100644 --- a/server/src/core/session-core.ts +++ b/server/src/core/session-core.ts @@ -1,8 +1,24 @@ -import { SessionDocument } from "kamaitachi-common"; +import { SessionDocument, ScoreDocument, SessionScoreInfo } from "kamaitachi-common"; +import { Condition } from "mongodb"; import db from "../db/db"; +/** + * Returns all the score documents inside a session. + * @param session The session to retrieve the score documents of. + */ export function GetScoresFromSession(session: SessionDocument) { return db.scores.find({ scoreID: { $in: session.scoreInfo.map((e) => e.scoreID) }, }); } + +/** + * Returns the session a score belongs to, if there is one. A score can only be part of one session implicitly. + * @param score The score to return the associated session of. + */ +export function GetSessionFromScore(score: ScoreDocument) { + return db.sessions.findOne({ + // ??? another bug in monks types i think + scoreInfo: { scoreID: score.scoreID } as Condition, + }); +}