Fix Trade command not giving a card if they don't already have it in their inventory
All checks were successful
Test / build (push) Successful in 9s

This commit is contained in:
Ethan Lane 2024-10-12 20:51:22 +01:00
parent 65a55895e7
commit ffdf2eb04c
2 changed files with 10 additions and 6 deletions

View file

@ -72,8 +72,8 @@ export default class Trade extends ButtonEvent {
return; return;
} }
user1UserInventory1.SetQuantity(user1UserInventory1.Quantity - 1); user1UserInventory1.RemoveQuantity(1);
user2UserInventory1.SetQuantity(user2UserInventory1.Quantity - 1); user2UserInventory1.RemoveQuantity(1);
await user1UserInventory1.Save(Inventory, user1UserInventory1); await user1UserInventory1.Save(Inventory, user1UserInventory1);
await user2UserInventory1.Save(Inventory, user2UserInventory1); await user2UserInventory1.Save(Inventory, user2UserInventory1);
@ -82,15 +82,15 @@ export default class Trade extends ButtonEvent {
let user2UserInventory2 = await Inventory.FetchOneByCardNumberAndUserId(user2UserId, user1CardNumber); let user2UserInventory2 = await Inventory.FetchOneByCardNumberAndUserId(user2UserId, user1CardNumber);
if (!user1UserInventory2) { if (!user1UserInventory2) {
user1UserInventory2 = new Inventory(user1UserId, user1CardNumber, 1); user1UserInventory2 = new Inventory(user1UserId, user2CardNumber, 1);
} else { } else {
user1UserInventory2.SetQuantity(user1UserInventory2.Quantity + 1); user1UserInventory2.AddQuantity(1);
} }
if (!user2UserInventory2) { if (!user2UserInventory2) {
user2UserInventory2 = new Inventory(user2UserId, user2CardNumber, 1); user2UserInventory2 = new Inventory(user2UserId, user1CardNumber, 1);
} else { } else {
user2UserInventory2.SetQuantity(user2UserInventory2.Quantity + 1); user2UserInventory2.AddQuantity(1);
} }
await user1UserInventory2.Save(Inventory, user1UserInventory2); await user1UserInventory2.Save(Inventory, user1UserInventory2);

View file

@ -29,6 +29,10 @@ export default class Inventory extends AppBaseEntity {
this.Quantity = quantity; this.Quantity = quantity;
} }
public AddQuantity(amount: number) {
this.Quantity += amount;
}
public RemoveQuantity(amount: number) { public RemoveQuantity(amount: number) {
if (this.Quantity < amount) return; if (this.Quantity < amount) return;