Add support for saving custom tables.

This commit is contained in:
zkldi
2022-01-30 21:20:08 +00:00
parent 43f0c7d209
commit 4533cd8bfa
2 changed files with 18 additions and 2 deletions
@@ -1,10 +1,10 @@
import { Router } from "express";
import db from "external/mongo/db";
import { SYMBOL_TachiData } from "lib/constants/tachi";
import { GetTableFromParam } from "./middleware";
import { GetFoldersFromTable } from "utils/folder";
import { FilterQuery } from "mongodb";
import { TableDocument } from "tachi-common";
import { GetFoldersFromTable } from "utils/folder";
import { GetTableFromParam } from "./middleware";
const router: Router = Router({ mergeParams: true });
@@ -35,6 +35,7 @@ router.patch(
preferredScoreAlg: p.optional(p.nullable(p.isIn(gptConfig.scoreRatingAlgs))),
preferredSessionAlg: p.optional(p.nullable(p.isIn(gptConfig.sessionRatingAlgs))),
preferredProfileAlg: p.optional(p.nullable(p.isIn(gptConfig.profileRatingAlgs))),
defaultTable: "*?string",
// This is a pretty stupid IIFE level hack, ah well.
gameSpecific: p.any,
scoreBucket: optNull(p.isIn("grade", "lamp")),
@@ -71,6 +72,21 @@ router.patch(
}
}
if (typeof req.body.preferredTable === "string") {
const table = await db.tables.findOne({
game,
playtype,
tableID: req.body.preferredTable,
});
if (!table) {
return res.status(400).json({
success: false,
description: `The requested table (${req.body.preferredTable}) does not exist.`,
});
}
}
const updateQuery: Record<string, string> = {};
// @warning Slightly icky dynamic prop assignment instead of copypasta.