vylbot-app/src/database/entities/Setting.ts
Vylpes e6c845e3b2
Some checks failed
continuous-integration/drone/push Build is failing
Switch to TypeORM's DataSource API (#299)
- Switch to TypeORM's DataSource API, rather than using the now deprecated ormconfig.json
- This will fix stage deployment not knowing how to deploy the database migrations

#297

> **NOTE:** This change requires the deployment scripts to be updated, please update them on the server before merging

Co-authored-by: Ethan Lane <ethan@vylpes.com>
Reviewed-on: https://gitea.vylpes.xyz/RabbitLabs/vylbot-app/pulls/299
2023-05-26 17:59:22 +01:00

36 lines
930 B
TypeScript

import { Column, Entity, ManyToOne } from "typeorm";
import BaseEntity from "../../contracts/BaseEntity";
import Server from "./Server";
import AppDataSource from "../dataSources/appDataSource";
@Entity()
export default class Setting extends BaseEntity {
constructor(key: string, value: string) {
super();
this.Key = key;
this.Value = value;
}
@Column()
Key: string;
@Column()
Value: string;
@ManyToOne(() => Server, x => x.Settings)
Server: Server;
public UpdateBasicDetails(key: string, value: string) {
this.Key = key;
this.Value = value;
}
public static async FetchOneByKey(key: string, relations?: string[]): Promise<Setting | null> {
const repository = AppDataSource.getRepository(Setting);
const single = await repository.findOne({ where: { Key: key }, relations: relations || {} });
return single;
}
}