From e295bdeb65c29cc94b16dac983c009b68652b80f Mon Sep 17 00:00:00 2001 From: zkldi Date: Tue, 28 Sep 2021 23:19:26 +0100 Subject: [PATCH] Add adjacent above/below query macros --- server/src/utils/queries/pbs.ts | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 server/src/utils/queries/pbs.ts diff --git a/server/src/utils/queries/pbs.ts b/server/src/utils/queries/pbs.ts new file mode 100644 index 000000000..6e8ed50b9 --- /dev/null +++ b/server/src/utils/queries/pbs.ts @@ -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; +}