Create concept of currency in the database #209
1 changed files with 31 additions and 0 deletions
31
src/database/entities/app/User.ts
Normal file
31
src/database/entities/app/User.ts
Normal file
|
@ -0,0 +1,31 @@
|
|||
import { Column, Entity } from "typeorm";
|
||||
import AppBaseEntity from "../../../contracts/AppBaseEntity";
|
||||
import AppDataSource from "../../dataSources/appDataSource";
|
||||
|
||||
@Entity()
|
||||
export default class User extends AppBaseEntity {
|
||||
constructor(userId: string, currency: number) {
|
||||
super();
|
||||
|
||||
this.UserId = userId;
|
||||
Vylpes marked this conversation as resolved
|
||||
this.Currency = currency;
|
||||
}
|
||||
|
||||
@Column()
|
||||
UserId: string;
|
||||
|
||||
@Column()
|
||||
Currency: number;
|
||||
|
||||
public UpdateCurrency(currency: number) {
|
||||
this.Currency = currency;
|
||||
}
|
||||
|
||||
public static async FetchOneByUserId(userId: string): Promise<User | null> {
|
||||
const repository = AppDataSource.getRepository(User);
|
||||
|
||||
const single = await repository.findOne({ where: { UserId: userId }});
|
||||
|
||||
return single;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue
Would it be worth having this as the main primary key ID? I can't see that not being unique