vylbot-app/src/database/entities/Audit.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

53 lines
1.5 KiB
TypeScript

import { Column, Entity } from "typeorm";
import { AuditType } from "../../constants/AuditType";
import BaseEntity from "../../contracts/BaseEntity";
import StringTools from "../../helpers/StringTools";
import AppDataSource from "../dataSources/appDataSource";
@Entity()
export default class Audit extends BaseEntity {
constructor(userId: string, auditType: AuditType, reason: string, moderatorId: string, serverId: string) {
super();
this.AuditId = StringTools.RandomString(5).toUpperCase();
this.UserId = userId;
this.AuditType = auditType;
this.Reason = reason;
this.ModeratorId = moderatorId;
this.ServerId = serverId;
}
@Column()
AuditId: string;
@Column()
UserId: string;
@Column()
AuditType: AuditType;
@Column()
Reason: string;
@Column()
ModeratorId: string;
@Column()
ServerId: string;
public static async FetchAuditsByUserId(userId: string, serverId: string): Promise<Audit[] | null> {
const repository = AppDataSource.getRepository(Audit);
const all = await repository.find({ where: { UserId: userId, ServerId: serverId } });
return all;
}
public static async FetchAuditByAuditId(auditId: string, serverId: string): Promise<Audit | null> {
const repository = AppDataSource.getRepository(Audit);
const single = await repository.findOne({ where: { AuditId: auditId, ServerId: serverId } });
return single;
}
}