validation
This commit is contained in:
1 parent
a1858e8302
commit
09534757a2
5 files changed
+98
-23
No files matched your search
@@ -1,29 +1,17 @@
|
||||
import { ISettingsRepository } from "@/repositories/index.js";
|
||||
import { Settings } from "@/types/index.js";
|
||||
import { AppError } from "@/utils/AppError.js";
|
||||
import { ValidatedEnv } from "@/validation/envValidation.js";
|
||||
|
||||
const SERVICE_NAME = "SettingsService";
|
||||
|
||||
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,
|
||||
nodeEnv: process.env.NODE_ENV,
|
||||
logLevel: process.env.LOG_LEVEL,
|
||||
clientHost: process.env.CLIENT_HOST,
|
||||
dbConnectionString: process.env.DB_CONNECTION_STRING,
|
||||
port: process.env.PORT,
|
||||
jwtSecret: string;
|
||||
jwtTTL: string;
|
||||
nodeEnv: string;
|
||||
logLevel: string;
|
||||
clientHost: string;
|
||||
dbConnectionString: string;
|
||||
};
|
||||
|
||||
export interface ISettingsService {
|
||||
@@ -38,9 +26,16 @@ class SettingsService implements ISettingsService {
|
||||
private settings: EnvConfig;
|
||||
private settingsRepository: ISettingsRepository;
|
||||
|
||||
constructor(settingsRepository: ISettingsRepository) {
|
||||
constructor(settingsRepository: ISettingsRepository, env: ValidatedEnv) {
|
||||
this.settingsRepository = settingsRepository;
|
||||
this.settings = { ...envConfig };
|
||||
this.settings = {
|
||||
jwtSecret: env.JWT_SECRET,
|
||||
jwtTTL: env.TOKEN_TTL,
|
||||
nodeEnv: env.NODE_ENV,
|
||||
logLevel: env.LOG_LEVEL,
|
||||
clientHost: env.CLIENT_HOST,
|
||||
dbConnectionString: env.DB_CONNECTION_STRING,
|
||||
};
|
||||
}
|
||||
|
||||
get serviceName() {
|
||||
|
||||
Reference in new issue
Block a user