feature/5-drop-command (#17)
#5 Reviewed-on: https://gitea.vylpes.xyz/External/card-drop/pulls/17 Co-authored-by: Ethan Lane <ethan@vylpes.com> Co-committed-by: Ethan Lane <ethan@vylpes.com>
This commit is contained in:
parent
51d97bacd5
commit
58d1541e47
21 changed files with 382 additions and 48 deletions
47
src/database/entities/app/Inventory.ts
Normal file
47
src/database/entities/app/Inventory.ts
Normal file
|
@ -0,0 +1,47 @@
|
|||
import { Column, Entity } from "typeorm";
|
||||
import AppBaseEntity from "../../../contracts/AppBaseEntity";
|
||||
import AppDataSource from "../../dataSources/appDataSource";
|
||||
|
||||
@Entity()
|
||||
export default class Inventory extends AppBaseEntity {
|
||||
constructor(userId: string, cardNumber: string, quantity: number, claimId: string) {
|
||||
super();
|
||||
|
||||
this.UserId = userId;
|
||||
this.CardNumber = cardNumber;
|
||||
this.Quantity = quantity;
|
||||
this.ClaimId = claimId;
|
||||
}
|
||||
|
||||
@Column()
|
||||
UserId: string;
|
||||
|
||||
@Column()
|
||||
CardNumber: string;
|
||||
|
||||
@Column()
|
||||
Quantity: number;
|
||||
|
||||
@Column()
|
||||
ClaimId: string;
|
||||
|
||||
public SetQuantity(quantity: number) {
|
||||
this.Quantity = quantity;
|
||||
}
|
||||
|
||||
public static async FetchOneByCardNumberAndUserId(userId: string, cardNumber: string): Promise<Inventory | null> {
|
||||
const repository = AppDataSource.getRepository(Inventory);
|
||||
|
||||
const single = await repository.findOne({ where: { UserId: userId, CardNumber: cardNumber }});
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
|
@ -1,17 +1,18 @@
|
|||
import { Column, Entity, OneToMany } from "typeorm";
|
||||
import { Column, Entity, ManyToOne } from "typeorm";
|
||||
import CardBaseEntity from "../../../contracts/CardBaseEntity";
|
||||
import { CardRarity } from "../../../constants/CardRarity";
|
||||
import Series from "./Series";
|
||||
import CardDataSource from "../../dataSources/cardDataSource";
|
||||
|
||||
@Entity()
|
||||
export default class Card extends CardBaseEntity {
|
||||
constructor(cardNumber: string, name: string, rarity: CardRarity) {
|
||||
constructor(cardNumber: string, name: string, rarity: CardRarity, path: string, series: Series) {
|
||||
super();
|
||||
|
||||
this.CardNumber = cardNumber;
|
||||
this.Name = name;
|
||||
this.Rarity = rarity;
|
||||
this.Path = path;
|
||||
this.Series = series;
|
||||
}
|
||||
|
||||
@Column()
|
||||
|
@ -23,14 +24,9 @@ export default class Card extends CardBaseEntity {
|
|||
@Column()
|
||||
Rarity: CardRarity;
|
||||
|
||||
@OneToMany(() => Series, x => x.Cards)
|
||||
@Column()
|
||||
Path: string
|
||||
|
||||
@ManyToOne(() => Series, x => x.Cards)
|
||||
Series: Series;
|
||||
|
||||
public static async FetchAllByRarity(rarity: CardRarity): Promise<Card[]> {
|
||||
const repository = CardDataSource.getRepository(Card);
|
||||
|
||||
const all = await repository.find({ where: { Rarity: rarity }});
|
||||
|
||||
return all;
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
import { Column, Entity, ManyToOne } from "typeorm";
|
||||
import { Column, Entity, OneToMany } from "typeorm";
|
||||
import CardBaseEntity from "../../../contracts/CardBaseEntity";
|
||||
import Card from "./Card";
|
||||
|
||||
|
@ -18,12 +18,6 @@ export default class Series extends CardBaseEntity {
|
|||
@Column()
|
||||
Path: string;
|
||||
|
||||
@ManyToOne(() => Card, x => x.Series)
|
||||
@OneToMany(() => Card, x => x.Series)
|
||||
Cards: Card[];
|
||||
|
||||
public async AddCard(card: Card) {
|
||||
if (!this.Cards) return;
|
||||
|
||||
this.Cards.push(card);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue