monkeytype/backend/dao/config.ts
Bruce Berrios 2f70d1ab8a
Add ApeKeys CRUD (#2606)
* Add ApeKeys CRUD

* Fix

* Omit ape key data

* Encode id + key
2022-03-01 11:11:01 -05:00

20 lines
647 B
TypeScript

import { UpdateResult } from "mongodb";
import db from "../init/db";
import _ from "lodash";
class ConfigDAO {
static async 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 });
}
static async getConfig(uid: string): Promise<any> {
const config = await db.collection<any>("configs").findOne({ uid });
// if (!config) throw new MonkeyError(404, "Config not found");
return config;
}
}
export default ConfigDAO;