summary refs log tree commit diff
path: root/src/util/Config.ts
diff options
context:
space:
mode:
authorFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-02-13 14:15:59 +0100
committerFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-02-13 14:15:59 +0100
commita44da1024dc39e2d2fef296fc1d4e5894090fce0 (patch)
tree0e9338baa9e64e8a8841913d18eddc5a2bb1a333 /src/util/Config.ts
parent:sparkles: mongoose Schemas (diff)
downloadserver-a44da1024dc39e2d2fef296fc1d4e5894090fce0.tar.xz
:zap: Config and database update
Diffstat (limited to 'src/util/Config.ts')
-rw-r--r--src/util/Config.ts37
1 files changed, 22 insertions, 15 deletions
diff --git a/src/util/Config.ts b/src/util/Config.ts

index 91ffda01..ad70d37a 100644 --- a/src/util/Config.ts +++ b/src/util/Config.ts
@@ -1,31 +1,38 @@ +import { Schema, model, Types, Document } from "mongoose"; import "missing-native-js-functions"; -import db from "./Database"; -import { ProviderCache } from "lambert-db"; -var Config: ProviderCache; +import db, { MongooseCache } from "./Database"; + +var Config = new MongooseCache(db.collection("config"), [], { onlyEvents: false }); export default { - init: async function init(opts: DefaultOptions = DefaultOptions) { - await db.collection("config").findOne({}); - Config = await db.data.config({}).cache(); + init: async function init() { await Config.init(); - await Config.set(opts.merge(Config.cache || {})); + return this.setAll(Config.data.merge(DefaultOptions)); }, getAll: function get() { - return <DefaultOptions>Config.get(); + return <DefaultOptions>Config.data; }, setAll: function set(val: any) { - return Config.set(val); + return db.collection("config").updateOne({}, { $set: val }); }, }; -export interface DefaultOptions { +export const DefaultOptions = { + api: {}, + gateway: {}, + voice: {}, +}; + +export interface DefaultOptions extends Document { api?: any; gateway?: any; voice?: any; } -export const DefaultOptions: DefaultOptions = { - api: {}, - gateway: {}, - voice: {}, -}; +export const ConfigSchema = new Schema({ + api: Object, + gateway: Object, + voice: Object, +}); + +export const ConfigModel = model<DefaultOptions>("Config", ConfigSchema, "config");