diff --git a/database/0.1.5/1694609771821-CreateClaim/Up/01-CreateClaim.sql b/database/0.1.5/1694609771821-CreateClaim/Up/01-CreateClaim.sql deleted file mode 100644 index bfd8057..0000000 --- a/database/0.1.5/1694609771821-CreateClaim/Up/01-CreateClaim.sql +++ /dev/null @@ -1,8 +0,0 @@ -CREATE TABLE `claim` ( - `Id` varchar(255) NOT NULL, - `WhenCreated` datetime NOT NULL, - `WhenUpdated` datetime NOT NULL, - `ClaimId` varchar(255) NOT NULL, - `InventoryId` varchar(255) NOT NULL, - PRIMARY KEY (`Id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; \ No newline at end of file diff --git a/database/0.1.5/1694609771821-CreateClaim/Up/02-MoveToClaim.sql b/database/0.1.5/1694609771821-CreateClaim/Up/02-MoveToClaim.sql deleted file mode 100644 index c95401a..0000000 --- a/database/0.1.5/1694609771821-CreateClaim/Up/02-MoveToClaim.sql +++ /dev/null @@ -1,14 +0,0 @@ -INSERT INTO claim ( - Id, - WhenCreated, - WhenUpdated, - ClaimId, - InventoryId -) -SELECT - UUID(), - NOW(), - NOW(), - ClaimId, - Id -FROM inventory; \ No newline at end of file diff --git a/database/0.1.5/1694609771821-CreateClaim/Up/03-AlterInventory.sql b/database/0.1.5/1694609771821-CreateClaim/Up/03-AlterInventory.sql deleted file mode 100644 index 7005ca3..0000000 --- a/database/0.1.5/1694609771821-CreateClaim/Up/03-AlterInventory.sql +++ /dev/null @@ -1,2 +0,0 @@ -ALTER TABLE inventory -DROP ClaimId; \ No newline at end of file diff --git a/package.json b/package.json index 505b116..80f753a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "card-drop", - "version": "0.1.5", + "version": "0.1.4", "main": "./dist/bot.js", "typings": "./dist", "scripts": { diff --git a/src/buttonEvents/Claim.ts b/src/buttonEvents/Claim.ts index 6f9ae58..5412db8 100644 --- a/src/buttonEvents/Claim.ts +++ b/src/buttonEvents/Claim.ts @@ -2,7 +2,6 @@ import { ButtonInteraction } from "discord.js"; import { ButtonEvent } from "../type/buttonEvent"; import Inventory from "../database/entities/app/Inventory"; import { CoreClient } from "../client/client"; -import { default as eClaim } from "../database/entities/app/Claim"; export default class Claim extends ButtonEvent { public override async execute(interaction: ButtonInteraction) { @@ -10,36 +9,30 @@ export default class Claim extends ButtonEvent { const cardNumber = interaction.customId.split(' ')[1]; const claimId = interaction.customId.split(' ')[2]; - const droppedBy = interaction.customId.split(' ')[3]; const userId = interaction.user.id; - const claimed = await eClaim.FetchOneByClaimId(claimId); + const claimed = await Inventory.FetchOneByClaimId(claimId); if (claimed) { await interaction.reply('This card has already been claimed'); return; } - if (claimId == CoreClient.ClaimId && userId != droppedBy) { - await interaction.reply('The latest dropped card can only be claimed by the user who dropped it'); + if (claimId != CoreClient.ClaimId) { + await interaction.reply('This card has expired'); return; } let inventory = await Inventory.FetchOneByCardNumberAndUserId(userId, cardNumber); if (!inventory) { - inventory = new Inventory(userId, cardNumber, 1); + inventory = new Inventory(userId, cardNumber, 1, claimId); } else { inventory.SetQuantity(inventory.Quantity + 1); } await inventory.Save(Inventory, inventory); - const claim = new eClaim(claimId); - claim.SetInventory(inventory); - - await claim.Save(eClaim, claim); - await interaction.reply('Card claimed'); } } \ No newline at end of file diff --git a/src/buttonEvents/Reroll.ts b/src/buttonEvents/Reroll.ts index bc91c90..c1a54ea 100644 --- a/src/buttonEvents/Reroll.ts +++ b/src/buttonEvents/Reroll.ts @@ -45,7 +45,7 @@ export default class Reroll extends ButtonEvent { row.addComponents( new ButtonBuilder() - .setCustomId(`claim ${randomCard.CardNumber} ${claimId} ${interaction.user.id}`) + .setCustomId(`claim ${randomCard.CardNumber} ${claimId}`) .setLabel("Claim") .setStyle(ButtonStyle.Primary), new ButtonBuilder() diff --git a/src/commands/drop.ts b/src/commands/drop.ts index 7503bf7..5770903 100644 --- a/src/commands/drop.ts +++ b/src/commands/drop.ts @@ -51,7 +51,7 @@ export default class Drop extends Command { row.addComponents( new ButtonBuilder() - .setCustomId(`claim ${randomCard.CardNumber} ${claimId} ${interaction.user.id}`) + .setCustomId(`claim ${randomCard.CardNumber} ${claimId}`) .setLabel("Claim") .setStyle(ButtonStyle.Primary), new ButtonBuilder() @@ -76,6 +76,7 @@ export default class Drop extends Command { } } + CoreClient.ClaimId = claimId; } } \ No newline at end of file diff --git a/src/database/entities/app/Claim.ts b/src/database/entities/app/Claim.ts deleted file mode 100644 index b4cde5e..0000000 --- a/src/database/entities/app/Claim.ts +++ /dev/null @@ -1,31 +0,0 @@ -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 SetInventory(inventory: Inventory) { - this.Inventory = inventory; - } - - public static async FetchOneByClaimId(claimId: string): Promise { - const repository = AppDataSource.getRepository(Claim); - - const single = await repository.findOne({ where: { ClaimId: claimId }}); - - return single; - } -} \ No newline at end of file diff --git a/src/database/entities/app/Inventory.ts b/src/database/entities/app/Inventory.ts index adec824..c6319a9 100644 --- a/src/database/entities/app/Inventory.ts +++ b/src/database/entities/app/Inventory.ts @@ -1,16 +1,16 @@ -import { Column, Entity, OneToMany } from "typeorm"; +import { Column, Entity } 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) { + constructor(userId: string, cardNumber: string, quantity: number, claimId: string) { super(); this.UserId = userId; this.CardNumber = cardNumber; this.Quantity = quantity; + this.ClaimId = claimId; } @Column() @@ -22,17 +22,13 @@ export default class Inventory extends AppBaseEntity { @Column() Quantity: number; - @OneToMany(() => Claim, x => x.Inventory) - Claims: Claim[]; + @Column() + ClaimId: string; public SetQuantity(quantity: number) { this.Quantity = quantity; } - public AddClaim(claim: Claim) { - this.Claims.push(claim); - } - public static async FetchOneByCardNumberAndUserId(userId: string, cardNumber: string): Promise { const repository = AppDataSource.getRepository(Inventory); @@ -40,4 +36,12 @@ export default class Inventory extends AppBaseEntity { return single; } + + public static async FetchOneByClaimId(claimId: string): Promise { + const repository = AppDataSource.getRepository(Inventory); + + const single = await repository.findOne({ where: { ClaimId: claimId }}); + + return single; + } } \ No newline at end of file diff --git a/src/database/migrations/app/0.1.5/1694609771821-CreateClaim.ts b/src/database/migrations/app/0.1.5/1694609771821-CreateClaim.ts deleted file mode 100644 index 22fe74c..0000000 --- a/src/database/migrations/app/0.1.5/1694609771821-CreateClaim.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { MigrationInterface, QueryRunner } from "typeorm" -import MigrationHelper from "../../../../helpers/MigrationHelper" - -export class CreateClaim1694609771821 implements MigrationInterface { - - public async up(queryRunner: QueryRunner): Promise { - MigrationHelper.Up('1694609771821-CreateClaim', '0.1.5', [ - '01-CreateClaim', - '02-MoveToClaim', - '03-AlterInventory', - ], queryRunner); - } - - public async down(queryRunner: QueryRunner): Promise { - } - -}