Fix users being able to claim a card twice if the user has multiple of it already

This commit is contained in:
Ethan Lane 2023-09-13 14:37:17 +01:00
parent 74cdf818d1
commit ad505b3ea2
7 changed files with 87 additions and 15 deletions

View file

@ -0,0 +1,27 @@
import { Column, Entity, ManyToOne } from "typeorm";
import AppBaseEntity from "../../../contracts/AppBaseEntity";
import Inventory from "./Inventory";
import AppDataSource from "../../dataSources/appDataSource";
@Entity()
export default class Claim extends AppBaseEntity {
constructor(claimId: string) {
super();
this.ClaimId = claimId;
}
@Column()
ClaimId: string;
@ManyToOne(() => Inventory, x => x.Claims)
Inventory: Inventory;
public static async FetchOneByClaimId(claimId: string): Promise<Claim | null> {
const repository = AppDataSource.getRepository(Claim);
const single = await repository.findOne({ where: { ClaimId: claimId }});
return single;
}
}