mirror of
https://github.com/zkldi/Tachi.git
synced 2026-10-10 00:08:22 +03:00
Add stats to the /recent router.
This commit is contained in:
+5
-2
@@ -2,7 +2,7 @@ import { Router } from "express";
|
||||
import db from "external/mongo/db";
|
||||
import { SYMBOL_TachiData } from "lib/constants/tachi";
|
||||
import { SearchCollection } from "lib/search/search";
|
||||
import { GetGradeDistributionForFolders, GetRecentlyViewedFolders } from "utils/folder";
|
||||
import { GetGradeLampDistributionForFolders, GetRecentlyViewedFolders } from "utils/folder";
|
||||
import { IsString } from "utils/misc";
|
||||
import folderIDRouter from "./_folderID/router";
|
||||
|
||||
@@ -39,7 +39,7 @@ router.get("/", async (req, res) => {
|
||||
20
|
||||
);
|
||||
|
||||
const stats = await GetGradeDistributionForFolders(user.id, folders);
|
||||
const stats = await GetGradeLampDistributionForFolders(user.id, folders);
|
||||
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
@@ -66,12 +66,15 @@ router.get("/recent", async (req, res) => {
|
||||
|
||||
const { views, folders } = await GetRecentlyViewedFolders(user.id, game, playtype);
|
||||
|
||||
const stats = await GetGradeLampDistributionForFolders(user.id, folders);
|
||||
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
description: `Returned ${views.length} recently interacted with folders.`,
|
||||
body: {
|
||||
views,
|
||||
folders,
|
||||
stats,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
import { Router } from "express";
|
||||
import { SYMBOL_TachiData } from "lib/constants/tachi";
|
||||
import { GetFoldersFromTable, GetGradeDistributionForFolders } from "utils/folder";
|
||||
import { GetFoldersFromTable, GetGradeLampDistributionForFolders } from "utils/folder";
|
||||
// @todo maybe refactor where middleware is stored to avoid paths this ugly.
|
||||
import { GetTableFromParam } from "../../../../../../games/_game/_playtype/tables/middleware";
|
||||
|
||||
@@ -19,7 +19,7 @@ router.get("/:tableID", GetTableFromParam, async (req, res) => {
|
||||
|
||||
// @optimisable - Requests a lot of charts we don't care about
|
||||
// could be cached too, i guess.
|
||||
const stats = await GetGradeDistributionForFolders(user.id, folders);
|
||||
const stats = await GetGradeLampDistributionForFolders(user.id, folders);
|
||||
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
|
||||
@@ -220,7 +220,7 @@ export function CalculateGradeDistribution(pbs: PBScoreDocument[]) {
|
||||
|
||||
return gradeDist;
|
||||
}
|
||||
export async function GetGradeDistributionForFolder(userID: integer, folder: FolderDocument) {
|
||||
export async function GetGradeLampDistributionForFolder(userID: integer, folder: FolderDocument) {
|
||||
const pbData = await GetPBsOnFolder(userID, folder);
|
||||
|
||||
return {
|
||||
@@ -231,8 +231,8 @@ export async function GetGradeDistributionForFolder(userID: integer, folder: Fol
|
||||
};
|
||||
}
|
||||
|
||||
export function GetGradeDistributionForFolders(userID: integer, folders: FolderDocument[]) {
|
||||
return Promise.all(folders.map((f) => GetGradeDistributionForFolder(userID, f)));
|
||||
export function GetGradeLampDistributionForFolders(userID: integer, folders: FolderDocument[]) {
|
||||
return Promise.all(folders.map((f) => GetGradeLampDistributionForFolder(userID, f)));
|
||||
}
|
||||
|
||||
export function CreateFolderID(
|
||||
|
||||
Reference in New Issue
Block a user