chore: do addItem on inventory document, not accountId #699
@ -1,5 +1,5 @@
|
|||||||
import { getAccountIdForRequest } from "@/src/services/loginService";
|
import { getAccountIdForRequest } from "@/src/services/loginService";
|
||||||
import { updateCurrencyByAccountId } from "@/src/services/inventoryService";
|
import { getInventory, updateCurrency } from "@/src/services/inventoryService";
|
||||||
import { RequestHandler } from "express";
|
import { RequestHandler } from "express";
|
||||||
import { updateSlots } from "@/src/services/inventoryService";
|
import { updateSlots } from "@/src/services/inventoryService";
|
||||||
import { InventorySlot } from "@/src/types/inventoryTypes/inventoryTypes";
|
import { InventorySlot } from "@/src/types/inventoryTypes/inventoryTypes";
|
||||||
@ -26,8 +26,10 @@ export const inventorySlotsController: RequestHandler = async (req, res) => {
|
|||||||
|
|
||||||
//TODO: check which slot was purchased because pvpBonus is also possible
|
//TODO: check which slot was purchased because pvpBonus is also possible
|
||||||
|
|
||||||
const currencyChanges = await updateCurrencyByAccountId(20, true, accountId);
|
const inventory = await getInventory(accountId);
|
||||||
await updateSlots(accountId, InventorySlot.PVE_LOADOUTS, 1, 1);
|
const currencyChanges = updateCurrency(inventory, 20, true);
|
||||||
|
updateSlots(inventory, InventorySlot.PVE_LOADOUTS, 1, 1);
|
||||||
|
await inventory.save();
|
||||||
|
|
||||||
//console.log({ InventoryChanges: currencyChanges }, " added loadout changes:");
|
//console.log({ InventoryChanges: currencyChanges }, " added loadout changes:");
|
||||||
|
|
||||||
|
@ -215,8 +215,8 @@ export const addItem = async (
|
|||||||
default: {
|
default: {
|
||||||
const inventory = await getInventory(accountId);
|
const inventory = await getInventory(accountId);
|
||||||
const inventoryChanges = addPowerSuit(inventory, typeName);
|
const inventoryChanges = addPowerSuit(inventory, typeName);
|
||||||
|
updateSlots(inventory, InventorySlot.SUITS, 0, 1);
|
||||||
await inventory.save();
|
await inventory.save();
|
||||||
await updateSlots(accountId, InventorySlot.SUITS, 0, 1);
|
|
||||||
return {
|
return {
|
||||||
InventoryChanges: {
|
InventoryChanges: {
|
||||||
...inventoryChanges,
|
...inventoryChanges,
|
||||||
@ -231,8 +231,8 @@ export const addItem = async (
|
|||||||
case "Archwing": {
|
case "Archwing": {
|
||||||
const inventory = await getInventory(accountId);
|
const inventory = await getInventory(accountId);
|
||||||
const inventoryChanges = addSpaceSuit(inventory, typeName);
|
const inventoryChanges = addSpaceSuit(inventory, typeName);
|
||||||
|
updateSlots(inventory, InventorySlot.SPACESUITS, 0, 1);
|
||||||
await inventory.save();
|
await inventory.save();
|
||||||
await updateSlots(accountId, InventorySlot.SPACESUITS, 0, 1);
|
|
||||||
return {
|
return {
|
||||||
InventoryChanges: {
|
InventoryChanges: {
|
||||||
...inventoryChanges,
|
...inventoryChanges,
|
||||||
@ -247,8 +247,8 @@ export const addItem = async (
|
|||||||
case "EntratiMech": {
|
case "EntratiMech": {
|
||||||
const inventory = await getInventory(accountId);
|
const inventory = await getInventory(accountId);
|
||||||
const inventoryChanges = addMechSuit(inventory, typeName);
|
const inventoryChanges = addMechSuit(inventory, typeName);
|
||||||
|
updateSlots(inventory, InventorySlot.MECHSUITS, 0, 1);
|
||||||
await inventory.save();
|
await inventory.save();
|
||||||
await updateSlots(accountId, InventorySlot.MECHSUITS, 0, 1);
|
|
||||||
return {
|
return {
|
||||||
InventoryChanges: {
|
InventoryChanges: {
|
||||||
...inventoryChanges,
|
...inventoryChanges,
|
||||||
@ -266,8 +266,8 @@ export const addItem = async (
|
|||||||
const inventory = await getInventory(accountId);
|
const inventory = await getInventory(accountId);
|
||||||
const weaponType = getWeaponType(typeName);
|
const weaponType = getWeaponType(typeName);
|
||||||
const inventoryChanges = addEquipment(inventory, weaponType, typeName);
|
const inventoryChanges = addEquipment(inventory, weaponType, typeName);
|
||||||
|
updateSlots(inventory, InventorySlot.WEAPONS, 0, 1);
|
||||||
await inventory.save();
|
await inventory.save();
|
||||||
await updateSlots(accountId, InventorySlot.WEAPONS, 0, 1);
|
|
||||||
return {
|
return {
|
||||||
InventoryChanges: {
|
InventoryChanges: {
|
||||||
...inventoryChanges,
|
...inventoryChanges,
|
||||||
@ -297,8 +297,8 @@ export const addItem = async (
|
|||||||
case "Sentinels": {
|
case "Sentinels": {
|
||||||
const inventory = await getInventory(accountId);
|
const inventory = await getInventory(accountId);
|
||||||
const inventoryChanges = addSentinel(inventory, typeName);
|
const inventoryChanges = addSentinel(inventory, typeName);
|
||||||
|
updateSlots(inventory, InventorySlot.SENTINELS, 0, 1);
|
||||||
await inventory.save();
|
await inventory.save();
|
||||||
await updateSlots(accountId, InventorySlot.SENTINELS, 0, 1);
|
|
||||||
return {
|
return {
|
||||||
InventoryChanges: {
|
InventoryChanges: {
|
||||||
...inventoryChanges,
|
...inventoryChanges,
|
||||||
@ -485,22 +485,18 @@ export const addSpaceSuit = (
|
|||||||
return inventoryChanges;
|
return inventoryChanges;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const updateSlots = async (
|
export const updateSlots = (
|
||||||
accountId: string,
|
inventory: TInventoryDatabaseDocument,
|
||||||
slotName: SlotNames,
|
slotName: SlotNames,
|
||||||
slotAmount: number,
|
slotAmount: number,
|
||||||
extraAmount: number
|
extraAmount: number
|
||||||
): Promise<void> => {
|
): void => {
|
||||||
const inventory = await getInventory(accountId);
|
|
||||||
|
|
||||||
inventory[slotName].Slots += slotAmount;
|
inventory[slotName].Slots += slotAmount;
|
||||||
if (inventory[slotName].Extra === undefined) {
|
if (inventory[slotName].Extra === undefined) {
|
||||||
inventory[slotName].Extra = extraAmount;
|
inventory[slotName].Extra = extraAmount;
|
||||||
} else {
|
} else {
|
||||||
inventory[slotName].Extra += extraAmount;
|
inventory[slotName].Extra += extraAmount;
|
||||||
}
|
}
|
||||||
|
|
||||||
await inventory.save();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const isCurrencyTracked = (usePremium: boolean): boolean => {
|
const isCurrencyTracked = (usePremium: boolean): boolean => {
|
||||||
|
@ -248,7 +248,9 @@ const handleSlotPurchase = async (
|
|||||||
const slotName = slotPurchaseNameToSlotName[slotPurchaseName].name;
|
const slotName = slotPurchaseNameToSlotName[slotPurchaseName].name;
|
||||||
const slotsPerPurchase = slotPurchaseNameToSlotName[slotPurchaseName].slotsPerPurchase;
|
const slotsPerPurchase = slotPurchaseNameToSlotName[slotPurchaseName].slotsPerPurchase;
|
||||||
|
|
||||||
await updateSlots(accountId, slotName, slotsPerPurchase, slotsPerPurchase);
|
const inventory = await getInventory(accountId);
|
||||||
|
updateSlots(inventory, slotName, slotsPerPurchase, slotsPerPurchase);
|
||||||
|
await inventory.save();
|
||||||
|
|
||||||
logger.debug(`added ${slotsPerPurchase} slot ${slotName}`);
|
logger.debug(`added ${slotsPerPurchase} slot ${slotName}`);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user