mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-02-27 16:24:41 +08:00
added code that will unset any legacy values that are still in the db config
This commit is contained in:
parent
0960d32a1a
commit
4cbcf6a96b
1 changed files with 18 additions and 1 deletions
|
@ -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> {
|
||||
|
|
Loading…
Reference in a new issue