factor out SUPPORTED_GAMES

This commit is contained in:
zkldi
2021-06-08 17:34:51 +01:00
parent 2c6eefe5e0
commit 570c7bfa33
6 changed files with 29 additions and 24 deletions
@@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { PrivateUserDocument, ScoreDocument } from "tachi-common";
import { grades, lamps, supportedGames, validPlaytypes } from "tachi-common/js/config";
import { grades, lamps, validPlaytypes } from "tachi-common/js/config";
import db from "../../src/db/db";
import MigrateRecords from "./migrate";
import CreateLogCtx from "../../src/common/logger";
+3 -3
View File
@@ -3,7 +3,7 @@ import { Command } from "commander";
import CreateLogCtx from "../src/lib/logger/logger";
import { IndexOptions } from "mongodb";
import { ValidDatabases } from "tachi-common";
import { supportedGames } from "tachi-common/js/config";
import { CONF_INFO } from "../src/lib/setup/config";
const logger = CreateLogCtx(__filename);
@@ -87,7 +87,7 @@ const staticIndexes: Partial<Record<ValidDatabases, Index[]>> = {
const indexes: Partial<Record<ValidDatabases, Index[]>> = staticIndexes;
for (const game of supportedGames) {
for (const game of CONF_INFO.SUPPORTED_GAMES) {
if (indexes[`charts-${game}` as "charts-iidx"]) {
indexes[`charts-${game}` as "charts-iidx"]!.push(
index({ chartID: 1 }, UNIQUE),
@@ -138,7 +138,7 @@ export async function SetIndexes(dbst: string) {
logger.info("Done.");
}
// if calling this as a script
// if calling this as a script -- similar to pythons if __name__ == "__main__"
if (require.main === module) {
SetIndexes(options.db ?? "ktblackdb").then(process.exit(0));
}
+5 -4
View File
@@ -1,11 +1,12 @@
import Prudence, { PrudenceSchema } from "prudence";
import db from "../src/db/db";
import { PRUDENCE_CHART_SCHEMAS, PRUDENCE_SCORE_SCHEMAS, STATIC_SCHEMAS } from "../src/db/schemas";
import { PRUDENCE_SCORE_SCHEMAS, STATIC_SCHEMAS } from "../src/db/schemas";
import CreateLogCtx from "../src/common/logger";
import fs from "fs";
import path from "path";
import { PrudenceError } from "prudence/js/error";
import { supportedGames, validPlaytypes } from "tachi-common/js/config";
import { validPlaytypes } from "tachi-common/js/config";
import { CONF_INFO } from "../src/lib/setup/config";
const BASE_DIR = path.join(__dirname, "./validate-database-errs");
@@ -62,7 +63,7 @@ async function ValidateScores(): Promise<void> {
let globalTotal = 0;
let globalSuccess = 0;
let globalFail = 0;
for (const game of supportedGames) {
for (const game of CONF_INFO.SUPPORTED_GAMES) {
for (const playtype of validPlaytypes[game]) {
// @ts-expect-error shut up
const schema = PRUDENCE_SCORE_SCHEMAS[game][playtype];
@@ -134,7 +135,7 @@ async function ValidateChartsOrSongs(type: "songs" | "charts"): Promise<void> {
let globalTotal = 0;
let globalSuccess = 0;
let globalFail = 0;
for (const game of supportedGames) {
for (const game of CONF_INFO.SUPPORTED_GAMES) {
const schema = STATIC_SCHEMAS[type]![game];
let successCount = 0;