Files
zkldi_Tachi/server/src/core/session.ts
T
2021-05-13 09:33:51 +01:00

25 lines
863 B
TypeScript

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<SessionScoreInfo>,
});
}