Feature/48 database #114

Merged
Vylpes merged 12 commits from feature/48-database into develop 2022-03-29 18:19:54 +01:00
2 changed files with 37 additions and 14 deletions
Showing only changes of commit 8b2da347b1 - Show all commits

View file

@ -31,18 +31,4 @@ export default class Setting extends BaseEntity {
return single; return single;
} }
public static async FetchValueByKeyOrDefault(key: string): Promise<string | undefined> {
const connection = getConnection();
const repository = connection.getRepository(Setting);
const single = await repository.findOne({ Key: key });
if (!single) {
return DefaultValues.GetValue(key);
}
return single.Value;
}
} }

View file

@ -0,0 +1,37 @@
import { getConnection } from "typeorm";
import DefaultValues from "../constants/DefaultValues";
import Setting from "../entity/Setting";
export default class SettingsHelper {
public static async GetSetting(key: string): Promise<string | undefined> {
const connection = getConnection();
const repository = connection.getRepository(Setting);
const single = await repository.findOne({ Key: key });
if (!single) {
return DefaultValues.GetValue(key);
}
return single.Value;
}
public static async SetSetting(key: string, value: string): Promise<void> {
const connection = getConnection();
const repository = connection.getRepository(Setting);
const setting = await repository.findOne({ Key: key });
if (setting) {
setting.UpdateBasicDetails(key, value);
await setting.Save(Setting, setting);
} else {
const newSetting = new Setting(key, value);
await newSetting.Save(Setting, newSetting);
}
}
}