Create goal-core and add new util to session-core

This commit is contained in:
zkldi
2021-05-07 17:35:23 +01:00
parent 2d67d79c35
commit d83a233f74
2 changed files with 17 additions and 1 deletions
View File
+17 -1
View File
@@ -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<SessionScoreInfo>,
});
}