monkeytype/backend/dao/config.ts
Jack e6982f293d
Small Dao dals (#2927)
* converted preset dao to dal

* psa dao > dal

* typo

* config dao > dal

* public stats dao > dal

* fixed bad merge

* removed this

* removed comment
2022-05-04 00:43:58 +02:00

18 lines
536 B
TypeScript

import { UpdateResult } from "mongodb";
import 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;
}