update config
This commit is contained in:
1 parent
f43b7584a6
commit
1defa52ae8
3 files changed
+115
-34
No files matched your search
@@ -25,10 +25,9 @@ export interface ISettingsService {
|
||||
export class SettingsService implements ISettingsService {
|
||||
static SERVICE_NAME = SERVICE_NAME;
|
||||
private settings: EnvConfig;
|
||||
private settingsRepository: ISettingsRepository;
|
||||
private settingsRepository: ISettingsRepository | null = null;
|
||||
|
||||
constructor(settingsRepository: ISettingsRepository, env: ValidatedEnv) {
|
||||
this.settingsRepository = settingsRepository;
|
||||
constructor(env: ValidatedEnv) {
|
||||
this.settings = {
|
||||
jwtSecret: env.JWT_SECRET,
|
||||
jwtTTL: env.TOKEN_TTL as StringValue,
|
||||
@@ -39,6 +38,10 @@ export class SettingsService implements ISettingsService {
|
||||
};
|
||||
}
|
||||
|
||||
setRepository(settingsRepository: ISettingsRepository) {
|
||||
this.settingsRepository = settingsRepository;
|
||||
}
|
||||
|
||||
get serviceName() {
|
||||
return SettingsService.SERVICE_NAME;
|
||||
}
|
||||
@@ -54,18 +57,30 @@ export class SettingsService implements ISettingsService {
|
||||
return this.settings;
|
||||
}
|
||||
|
||||
private getRepository(): ISettingsRepository {
|
||||
if (!this.settingsRepository) {
|
||||
throw new AppError({
|
||||
message: "Settings repository not initialized. Call setRepository() after DB connect.",
|
||||
status: 500,
|
||||
service: SERVICE_NAME,
|
||||
});
|
||||
}
|
||||
return this.settingsRepository;
|
||||
}
|
||||
|
||||
updateDbSettings = async (newSettings: SettingsUpdate) => {
|
||||
return await this.settingsRepository.update(newSettings);
|
||||
return await this.getRepository().update(newSettings);
|
||||
};
|
||||
|
||||
getDBSettings = async () => {
|
||||
const repo = this.getRepository();
|
||||
// Remove any old settings
|
||||
await this.settingsRepository.deleteLegacy();
|
||||
await repo.deleteLegacy();
|
||||
|
||||
let settings = await this.settingsRepository.findSingleton();
|
||||
let settings = await repo.findSingleton();
|
||||
if (settings === null) {
|
||||
await this.settingsRepository.create({});
|
||||
settings = await this.settingsRepository.findSingleton();
|
||||
await repo.create({});
|
||||
settings = await repo.findSingleton();
|
||||
}
|
||||
|
||||
if (!settings) {
|
||||
|
||||
Reference in new issue
Block a user