Create concept of currency in the database #209

Merged
Vylpes merged 4 commits from feature/200-currency-db into develop 2024-04-26 18:35:03 +01:00
2 changed files with 1 additions and 14 deletions
Showing only changes of commit d7412cb71a - Show all commits

View file

@ -2,7 +2,6 @@ CREATE TABLE `user` (
`Id` varchar(255) NOT NULL, `Id` varchar(255) NOT NULL,
`WhenCreated` datetime NOT NULL, `WhenCreated` datetime NOT NULL,
`WhenUpdated` datetime NOT NULL, `WhenUpdated` datetime NOT NULL,
`UserId` varchar(255) NOT NULL,
`Currency` int NOT NULL, `Currency` int NOT NULL,
PRIMARY KEY (`Id`) PRIMARY KEY (`Id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

View file

@ -1,31 +1,19 @@
import { Column, Entity } from "typeorm"; import { Column, Entity } from "typeorm";
import AppBaseEntity from "../../../contracts/AppBaseEntity"; import AppBaseEntity from "../../../contracts/AppBaseEntity";
import AppDataSource from "../../dataSources/appDataSource";
@Entity() @Entity()
export default class User extends AppBaseEntity { export default class User extends AppBaseEntity {
constructor(userId: string, currency: number) { constructor(userId: string, currency: number) {
super(); super();
this.UserId = userId; this.Id = userId;
this.Currency = currency; this.Currency = currency;
Vylpes marked this conversation as resolved
Review

Would it be worth having this as the main primary key ID? I can't see that not being unique

Would it be worth having this as the main primary key ID? I can't see that not being unique
} }
@Column()
UserId: string;
@Column() @Column()
Currency: number; Currency: number;
public UpdateCurrency(currency: number) { public UpdateCurrency(currency: number) {
this.Currency = currency; 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;
}
} }