Add lobby entity to database
This commit is contained in:
parent
5c00601e16
commit
5de2b4bd45
3 changed files with 67 additions and 39 deletions
45
src/entity/501231711271780357/Lobby.ts
Normal file
45
src/entity/501231711271780357/Lobby.ts
Normal file
|
@ -0,0 +1,45 @@
|
|||
import { Column, Entity, getConnection } from "typeorm";
|
||||
import BaseEntity from "../../contracts/BaseEntity";
|
||||
|
||||
@Entity()
|
||||
export default class Lobby extends BaseEntity {
|
||||
constructor(channelId: string, roleId: string, cooldown: number, name: string) {
|
||||
super();
|
||||
|
||||
this.ChannelId = channelId;
|
||||
this.RoleId = roleId;
|
||||
this.Cooldown = cooldown;
|
||||
this.Name = name;
|
||||
|
||||
this.LastUsed = new Date(0);
|
||||
}
|
||||
|
||||
@Column()
|
||||
public ChannelId: string;
|
||||
|
||||
@Column()
|
||||
public RoleId: string;
|
||||
|
||||
@Column()
|
||||
public Cooldown: number;
|
||||
|
||||
@Column()
|
||||
public LastUsed: Date;
|
||||
|
||||
@Column()
|
||||
public Name: string;
|
||||
|
||||
public MarkAsUsed() {
|
||||
this.LastUsed = new Date();
|
||||
}
|
||||
|
||||
public static async FetchOneByChannelId(channelId: string, relations?: string[]): Promise<Lobby | undefined> {
|
||||
const connection = getConnection();
|
||||
|
||||
const repository = connection.getRepository(Lobby);
|
||||
|
||||
const single = await repository.findOne({ ChannelId: channelId }, { relations: relations || [] });
|
||||
|
||||
return single;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue