added code that will unset any legacy values that are still in the db config

This commit is contained in:
Miodec 2023-08-07 01:28:18 +02:00
parent 0960d32a1a
commit 4cbcf6a96b

View file

@ -2,14 +2,31 @@ import { UpdateResult } from "mongodb";
import * as db from "../init/db";
import _ from "lodash";
const configLegacyProperties = [
"swapEscAndTab",
"quickTab",
"chartStyle",
"chartAverage10",
"chartAverage100",
];
export async function saveConfig(
uid: string,
config: object
): Promise<UpdateResult> {
const configChanges = _.mapKeys(config, (_value, key) => `config.${key}`);
const unset = _.fromPairs(
_.map(configLegacyProperties, (key) => [`config.${key}`, ""])
);
return await db
.collection<any>("configs")
.updateOne({ uid }, { $set: configChanges }, { upsert: true });
.updateOne(
{ uid },
{ $set: configChanges, $unset: unset },
{ upsert: true }
);
}
export async function getConfig(uid: string): Promise<any> {