app -> ts
This commit is contained in:
1 parent
147eff3ede
commit
2a8d2cb06a
10 files changed
+152
-89
No files matched your search
+25
-22
@@ -1,6 +1,17 @@
|
||||
const SERVICE_NAME = "SettingsService";
|
||||
|
||||
const envConfig = {
|
||||
export type EnvConfig = {
|
||||
jwtSecret: string | undefined;
|
||||
jwtTTL: string | undefined;
|
||||
systemEmailHost: string | undefined;
|
||||
nodeEnv: string | undefined;
|
||||
logLevel: string | undefined;
|
||||
clientHost: string | undefined;
|
||||
dbConnectionString: string | undefined;
|
||||
port: string | undefined;
|
||||
};
|
||||
|
||||
const envConfig: EnvConfig = {
|
||||
jwtSecret: process.env.JWT_SECRET,
|
||||
jwtTTL: process.env.TOKEN_TTL,
|
||||
systemEmailHost: process.env.SYSTEM_EMAIL_HOST,
|
||||
@@ -10,19 +21,20 @@ const envConfig = {
|
||||
dbConnectionString: process.env.DB_CONNECTION_STRING,
|
||||
port: process.env.PORT,
|
||||
};
|
||||
/**
|
||||
* SettingsService
|
||||
*
|
||||
* This service is responsible for loading and managing the application settings.
|
||||
*/
|
||||
class SettingsService {
|
||||
static SERVICE_NAME = "SettingsService";
|
||||
|
||||
/**
|
||||
* Constructs a new SettingsService
|
||||
* @constructor
|
||||
* @throws {Error}
|
||||
*/ constructor(AppSettings) {
|
||||
export interface ISettingsService {
|
||||
readonly serviceName: string;
|
||||
loadSettings(): EnvConfig;
|
||||
getSettings(): EnvConfig;
|
||||
getDBSettings(): Promise<Record<string, any>>;
|
||||
}
|
||||
|
||||
class SettingsService implements ISettingsService {
|
||||
static SERVICE_NAME = "SettingsService";
|
||||
private AppSettings: any;
|
||||
private settings: EnvConfig;
|
||||
|
||||
constructor(AppSettings: any) {
|
||||
this.AppSettings = AppSettings;
|
||||
this.settings = { ...envConfig };
|
||||
}
|
||||
@@ -31,19 +43,10 @@ class SettingsService {
|
||||
return SettingsService.SERVICE_NAME;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load settings from env settings
|
||||
* @returns {Object>} The settings.
|
||||
*/
|
||||
loadSettings() {
|
||||
return this.settings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current settings.
|
||||
* @returns {Object} The current settings.
|
||||
* @throws Will throw an error if settings have not been loaded.
|
||||
*/
|
||||
getSettings() {
|
||||
if (!this.settings) {
|
||||
throw new Error("Settings have not been loaded");
|
||||
Reference in new issue
Block a user