monkeytype/backend/dal/config.ts
Bruce Berrios e5c295cfe4
Remove class syntax from db client (#2940) Bruception
Co-authored-by: Jack <jack@monkeytype.com>
2022-05-05 01:57:51 +02:00

18 lines
541 B
TypeScript

import { UpdateResult } from "mongodb";
import * as db from "../init/db";
import _ from "lodash";
export async function saveConfig(
uid: string,
config: object
): Promise<UpdateResult> {
const configChanges = _.mapKeys(config, (_value, key) => `config.${key}`);
return await db
.collection<any>("configs")
.updateOne({ uid }, { $set: configChanges }, { upsert: true });
}
export async function getConfig(uid: string): Promise<any> {
const config = await db.collection<any>("configs").findOne({ uid });
return config;
}