mirror of
https://github.com/zkldi/Tachi.git
synced 2026-10-06 22:07:58 +03:00
Create goal-core and add new util to session-core
This commit is contained in:
@@ -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>,
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user