mirror of
https://github.com/zkldi/Tachi.git
synced 2026-09-30 02:48:01 +03:00
25 lines
847 B
TypeScript
25 lines
847 B
TypeScript
import db from "external/mongo/db";
|
|
import type { Condition } from "mongodb";
|
|
import type { ScoreDocument, SessionDocument, SessionScoreInfo } from "tachi-common";
|
|
|
|
/**
|
|
* 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>,
|
|
});
|
|
}
|