Add app settings model, routes, db ops, service, use settings for issueToken

This commit is contained in:
Alex Holliday committed 2024-09-26 13:41:50 +08:00
1 parent b2bc441c7f
commit 992bf099fa
12 files changed
+210 -19

No files matched your search

+33
View File
@@ -0,0 +1,33 @@
const AppSettings = require("../models/AppSettings");
const SERVICE_NAME = "SettingsService";
class SettingsService {
constructor() {
this.settings = null;
}
async loadSettings() {
if (!this.settings) {
try {
this.settings = await AppSettings.findOne();
if (!this.settings) {
throw new Error("Settings not found");
}
return this.settings;
} catch (error) {
error.service === undefined ? (error.service = SERVICE_NAME) : null;
error.method === undefined ? (error.method = "loadSettings") : null;
throw error;
}
}
}
getSettings() {
if (!this.settings) {
throw new Error("Settings have not been loaded");
}
return this.settings;
}
}
module.exports = SettingsService;