feat: handle client setting InfestationDate on equipment
All checks were successful
Build / build (push) Successful in 47s
Build / build (pull_request) Successful in 1m30s

This commit is contained in:
Sainan 2025-04-29 22:21:20 +02:00
parent 9468768947
commit e3309f8d96
4 changed files with 19 additions and 12 deletions

View File

@ -1,4 +1,4 @@
import { addGearExpByCategory, getInventory } from "@/src/services/inventoryService"; import { applyClientEquipmentUpdates, getInventory } from "@/src/services/inventoryService";
import { getAccountIdForRequest } from "@/src/services/loginService"; import { getAccountIdForRequest } from "@/src/services/loginService";
import { IEquipmentClient } from "@/src/types/inventoryTypes/commonInventoryTypes"; import { IEquipmentClient } from "@/src/types/inventoryTypes/commonInventoryTypes";
import { TEquipmentKey } from "@/src/types/inventoryTypes/inventoryTypes"; import { TEquipmentKey } from "@/src/types/inventoryTypes/inventoryTypes";
@ -20,7 +20,7 @@ export const addXpController: RequestHandler = async (req, res) => {
} }
} }
} }
addGearExpByCategory(inventory, gear, category as TEquipmentKey); applyClientEquipmentUpdates(inventory, gear, category as TEquipmentKey);
} }
await inventory.save(); await inventory.save();
res.end(); res.end();

View File

@ -10,6 +10,10 @@ export const toMongoDate = (date: Date): IMongoDate => {
return { $date: { $numberLong: date.getTime().toString() } }; return { $date: { $numberLong: date.getTime().toString() } };
}; };
export const fromMongoData = (date: IMongoDate): Date => {
return new Date(parseInt(date.$date.$numberLong));
};
export const kubrowWeights: Record<TRarity, number> = { export const kubrowWeights: Record<TRarity, number> = {
COMMON: 6, COMMON: 6,
UNCOMMON: 4, UNCOMMON: 4,

View File

@ -69,6 +69,7 @@ import {
import { createShip } from "./shipService"; import { createShip } from "./shipService";
import { import {
catbrowDetails, catbrowDetails,
fromMongoData,
kubrowDetails, kubrowDetails,
kubrowFurPatternsWeights, kubrowFurPatternsWeights,
kubrowWeights, kubrowWeights,
@ -1471,21 +1472,20 @@ export const addEmailItem = async (
return inventoryChanges; return inventoryChanges;
}; };
//TODO: wrong id is not erroring export const applyClientEquipmentUpdates = (
export const addGearExpByCategory = (
inventory: TInventoryDatabaseDocument, inventory: TInventoryDatabaseDocument,
gearArray: IEquipmentClient[], gearArray: IEquipmentClient[],
categoryName: TEquipmentKey categoryName: TEquipmentKey
): void => { ): void => {
const category = inventory[categoryName]; const category = inventory[categoryName];
gearArray.forEach(({ ItemId, XP }) => { gearArray.forEach(({ ItemId, XP, InfestationDate }) => {
if (!XP) { const item = category.id(ItemId.$oid);
return; if (!item) {
throw new Error(`No item with id ${ItemId.$oid} in ${categoryName}`);
} }
const item = category.id(ItemId.$oid); if (XP) {
if (item) {
item.XP ??= 0; item.XP ??= 0;
item.XP += XP; item.XP += XP;
@ -1500,6 +1500,10 @@ export const addGearExpByCategory = (
}); });
} }
} }
if (InfestationDate) {
item.InfestationDate = fromMongoData(InfestationDate);
}
}); });
}; };

View File

@ -21,7 +21,6 @@ import {
addFocusXpIncreases, addFocusXpIncreases,
addFusionPoints, addFusionPoints,
addFusionTreasures, addFusionTreasures,
addGearExpByCategory,
addItem, addItem,
addLevelKeys, addLevelKeys,
addLoreFragmentScans, addLoreFragmentScans,
@ -32,6 +31,7 @@ import {
addShipDecorations, addShipDecorations,
addSkin, addSkin,
addStanding, addStanding,
applyClientEquipmentUpdates,
combineInventoryChanges, combineInventoryChanges,
generateRewardSeed, generateRewardSeed,
getCalendarProgress, getCalendarProgress,
@ -670,9 +670,8 @@ export const addMissionInventoryUpdates = async (
} }
break; break;
default: default:
// Equipment XP updates
if (equipmentKeys.includes(key as TEquipmentKey)) { if (equipmentKeys.includes(key as TEquipmentKey)) {
addGearExpByCategory(inventory, value as IEquipmentClient[], key as TEquipmentKey); applyClientEquipmentUpdates(inventory, value as IEquipmentClient[], key as TEquipmentKey);
} }
break; break;
// if ( // if (