Fix users being able to claim a card twice if the user has multiple of it already
This commit is contained in:
parent
74cdf818d1
commit
ad505b3ea2
7 changed files with 87 additions and 15 deletions
27
src/database/entities/app/Claim.ts
Normal file
27
src/database/entities/app/Claim.ts
Normal 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;
|
||||
}
|
||||
}
|
|
@ -1,16 +1,16 @@
|
|||
import { Column, Entity } from "typeorm";
|
||||
import { Column, Entity, OneToMany } from "typeorm";
|
||||
import AppBaseEntity from "../../../contracts/AppBaseEntity";
|
||||
import AppDataSource from "../../dataSources/appDataSource";
|
||||
import Claim from "./Claim";
|
||||
|
||||
@Entity()
|
||||
export default class Inventory extends AppBaseEntity {
|
||||
constructor(userId: string, cardNumber: string, quantity: number, claimId: string) {
|
||||
constructor(userId: string, cardNumber: string, quantity: number) {
|
||||
super();
|
||||
|
||||
this.UserId = userId;
|
||||
this.CardNumber = cardNumber;
|
||||
this.Quantity = quantity;
|
||||
this.ClaimId = claimId;
|
||||
}
|
||||
|
||||
@Column()
|
||||
|
@ -22,13 +22,17 @@ export default class Inventory extends AppBaseEntity {
|
|||
@Column()
|
||||
Quantity: number;
|
||||
|
||||
@Column()
|
||||
ClaimId: string;
|
||||
@OneToMany(() => Claim, x => x.Inventory)
|
||||
Claims: Claim[];
|
||||
|
||||
public SetQuantity(quantity: number) {
|
||||
this.Quantity = quantity;
|
||||
}
|
||||
|
||||
public AddClaim(claim: Claim) {
|
||||
this.Claims.push(claim);
|
||||
}
|
||||
|
||||
public static async FetchOneByCardNumberAndUserId(userId: string, cardNumber: string): Promise<Inventory | null> {
|
||||
const repository = AppDataSource.getRepository(Inventory);
|
||||
|
||||
|
@ -36,12 +40,4 @@ export default class Inventory extends AppBaseEntity {
|
|||
|
||||
return single;
|
||||
}
|
||||
|
||||
public static async FetchOneByClaimId(claimId: string): Promise<Inventory | null> {
|
||||
const repository = AppDataSource.getRepository(Inventory);
|
||||
|
||||
const single = await repository.findOne({ where: { ClaimId: claimId }});
|
||||
|
||||
return single;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue