Add adjacent above/below query macros

This commit is contained in:
zkldi
2021-09-28 23:19:26 +01:00
parent 3ef51f9743
commit e295bdeb65
+32
View File
@@ -0,0 +1,32 @@
import db from "external/mongo/db";
import { PBScoreDocument } from "tachi-common";
export async function GetAdjacentAbove(userPB: PBScoreDocument, size = 5) {
const adjAbove = (await db["personal-bests"].find(
{
chartID: userPB.chartID,
"rankingData.rank": { $lt: userPB.rankingData.rank },
},
{
limit: size,
sort: { "rankingData.rank": -1 },
}
)) as PBScoreDocument<"usc:Single">[];
return adjAbove;
}
export async function GetAdjacentBelow(userPB: PBScoreDocument, size = 5) {
const adjAbove = (await db["personal-bests"].find(
{
chartID: userPB.chartID,
"rankingData.rank": { $gt: userPB.rankingData.rank },
},
{
limit: size,
sort: { "rankingData.rank": 1 },
}
)) as PBScoreDocument<"usc:Single">[];
return adjAbove;
}