app -> ts

This commit is contained in:
Alex Holliday committed 2026-01-21 11:18:13 -08:00
1 parent 147eff3ede
commit 2a8d2cb06a
10 files changed
+152 -89

No files matched your search

@@ -1,4 +1,3 @@
import { config } from "@/config/index.js";
import type { Check } from "@/types/index.js";
const SERVICE_NAME = "BufferService";
@@ -12,8 +11,9 @@ class BufferService {
private bufferTimer: NodeJS.Timeout | null = null;
private checksService: any;
constructor({ logger, checkService }: { logger: any; checkService: any }) {
this.BUFFER_TIMEOUT = config.NODE_ENV === "development" ? 10 : 1000 * 60 * 1; // 1 minute
constructor({ logger, checkService, settingsService }: { logger: any; checkService: any; settingsService: any }) {
this.BUFFER_TIMEOUT = settingsService.getSettings().nodeEnv === "development" ? 10 : 1000 * 60 * 1; // 1 minute
console.log(this.BUFFER_TIMEOUT);
this.logger = logger;
this.checksService = checkService;
this.SERVICE_NAME = SERVICE_NAME;
@@ -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");