From b990b5a7e5fda1bd433648dd2425d477107fcbdb Mon Sep 17 00:00:00 2001 From: zkldi <20380519+zkldi@users.noreply.github.com> Date: Sun, 27 Feb 2022 18:51:45 +0000 Subject: [PATCH] Make destroy-chart use DeleteMultipleScores --- .../src/server/router/api/v1/admin/router.ts | 45 ++----------------- 1 file changed, 4 insertions(+), 41 deletions(-) diff --git a/server/src/server/router/api/v1/admin/router.ts b/server/src/server/router/api/v1/admin/router.ts index c3dff12f5..fc0c6f750 100644 --- a/server/src/server/router/api/v1/admin/router.ts +++ b/server/src/server/router/api/v1/admin/router.ts @@ -9,7 +9,7 @@ import { ONE_MINUTE } from "lib/constants/time"; import { ServerConfig, TachiConfig } from "lib/setup/config"; import { Game, UserAuthLevels } from "tachi-common"; import db from "external/mongo/db"; -import { DeleteScore } from "lib/score-mutation/delete-scores"; +import { DeleteMultipleScores, DeleteScore } from "lib/score-mutation/delete-scores"; import { RecalcAllScores, UpdateAllPBs } from "utils/calculations/recalc-scores"; import DestroyUserGamePlaytypeData from "utils/reset-state/destroy-ugpt"; import { RecalcSessions } from "utils/calculations/recalc-sessions"; @@ -210,58 +210,21 @@ router.post( async (req, res) => { const game: Game = req.body.game; const chartID: string = req.body.chartID; - await db.charts[game].remove({ - chartID, - }); const scores = await db.scores.find({ chartID, }); - const scoreIDs = scores.map((e) => e.scoreID); + await DeleteMultipleScores(scores); - await db.scores.remove({ - scoreID: { $in: scoreIDs }, + await db.charts[game].remove({ + chartID, }); await db["personal-bests"].remove({ chartID, }); - const sessions = await db.sessions.find({ - "scoreInfo.scoreID": { $in: scoreIDs }, - }); - - for (const session of sessions) { - await db.sessions.update( - { - sessionID: session.sessionID, - }, - { - $set: { - scoreInfo: session.scoreInfo.filter((e) => !scoreIDs.includes(e.scoreID)), - }, - } - ); - } - - const imports = await db.imports.find({ - scoreIDs: { $in: scoreIDs }, - }); - - for (const imp of imports) { - await db.imports.update( - { - importID: imp.importID, - }, - { - $set: { - scoreIDs: imp.scoreIDs.filter((e) => !scoreIDs.includes(e)), - }, - } - ); - } - return res.status(200).json({ success: true, description: `Obliterated chart.`,