Create concept of currency in the database #209
2 changed files with 1 additions and 14 deletions
|
@ -2,7 +2,6 @@ CREATE TABLE `user` (
|
|||
`Id` varchar(255) NOT NULL,
|
||||
`WhenCreated` datetime NOT NULL,
|
||||
`WhenUpdated` datetime NOT NULL,
|
||||
`UserId` varchar(255) NOT NULL,
|
||||
`Currency` int NOT NULL,
|
||||
PRIMARY KEY (`Id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
@ -1,31 +1,19 @@
|
|||
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;
|
||||
this.Id = userId;
|
||||
this.Currency = currency;
|
||||
Vylpes marked this conversation as resolved
|
||||
}
|
||||
|
||||
@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