Add safe mode (#85)
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
# Description Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change. #76 ## Type of change Please delete options that are not relevant. - [x] Bug fix (non-breaking change which fixes an issue) # How Has This Been Tested? Please describe the tests that you ran to verify the changes. Provide instructions so we can reproduce. Please also list any relevant details to your test configuration. # Checklist - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that provde my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged and published in downstream modules Reviewed-on: https://gitea.vylpes.xyz/External/card-drop/pulls/85 Co-authored-by: Ethan Lane <ethan@vylpes.com> Co-committed-by: Ethan Lane <ethan@vylpes.com>
This commit is contained in:
parent
2462ca105a
commit
4a5f624da3
7 changed files with 104 additions and 6 deletions
53
src/database/entities/app/Config.ts
Normal file
53
src/database/entities/app/Config.ts
Normal file
|
@ -0,0 +1,53 @@
|
|||
import { Column, Entity } from "typeorm";
|
||||
import AppBaseEntity from "../../../contracts/AppBaseEntity";
|
||||
import AppDataSource from "../../dataSources/appDataSource";
|
||||
|
||||
@Entity()
|
||||
export default class Config extends AppBaseEntity {
|
||||
constructor(key: string, value: string) {
|
||||
super();
|
||||
|
||||
this.Key = key;
|
||||
this.Value = value;
|
||||
}
|
||||
|
||||
@Column()
|
||||
Key: string;
|
||||
|
||||
@Column()
|
||||
Value: string;
|
||||
|
||||
public SetValue(value: string) {
|
||||
this.Value = value;
|
||||
}
|
||||
|
||||
public static async FetchOneByKey(key: string): Promise<Config | null> {
|
||||
const repository = AppDataSource.getRepository(Config);
|
||||
|
||||
const single = await repository.findOne({ where: { Key: key }});
|
||||
|
||||
return single;
|
||||
}
|
||||
|
||||
public static async GetValue(key: string): Promise<string | undefined> {
|
||||
const config = await Config.FetchOneByKey(key);
|
||||
|
||||
if (!config) return undefined;
|
||||
|
||||
return config.Value;
|
||||
}
|
||||
|
||||
public static async SetValue(key: string, value: string) {
|
||||
const config = await Config.FetchOneByKey(key);
|
||||
|
||||
if (!config) {
|
||||
const newConfig = new Config(key, value);
|
||||
|
||||
await newConfig.Save(Config, newConfig);
|
||||
} else {
|
||||
config.SetValue(value);
|
||||
|
||||
await config.Save(Config, config);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue