From 4cbcf6a96ba469f65ea4f12631e581ffb6a8f2ae Mon Sep 17 00:00:00 2001 From: Miodec Date: Mon, 7 Aug 2023 01:28:18 +0200 Subject: [PATCH] added code that will unset any legacy values that are still in the db config --- backend/src/dal/config.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/backend/src/dal/config.ts b/backend/src/dal/config.ts index a8bf854f9..47b323cd1 100644 --- a/backend/src/dal/config.ts +++ b/backend/src/dal/config.ts @@ -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 { const configChanges = _.mapKeys(config, (_value, key) => `config.${key}`); + + const unset = _.fromPairs( + _.map(configLegacyProperties, (key) => [`config.${key}`, ""]) + ); + return await db .collection("configs") - .updateOne({ uid }, { $set: configChanges }, { upsert: true }); + .updateOne( + { uid }, + { $set: configChanges, $unset: unset }, + { upsert: true } + ); } export async function getConfig(uid: string): Promise {