fix: ensure helminth shard operations don't produce a null shard (#2176)
Reviewed-on: #2176 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
This commit is contained in:
parent
2e8fe799d7
commit
01e490768c
@ -30,8 +30,9 @@ export const infestedFoundryController: RequestHandler = async (req, res) => {
|
|||||||
const request = getJSONfromString<IShardInstallRequest>(String(req.body));
|
const request = getJSONfromString<IShardInstallRequest>(String(req.body));
|
||||||
const inventory = await getInventory(account._id.toString());
|
const inventory = await getInventory(account._id.toString());
|
||||||
const suit = inventory.Suits.id(request.SuitId.$oid)!;
|
const suit = inventory.Suits.id(request.SuitId.$oid)!;
|
||||||
if (!suit.ArchonCrystalUpgrades || suit.ArchonCrystalUpgrades.length != 5) {
|
suit.ArchonCrystalUpgrades ??= [];
|
||||||
suit.ArchonCrystalUpgrades = [{}, {}, {}, {}, {}];
|
while (suit.ArchonCrystalUpgrades.length < request.Slot) {
|
||||||
|
suit.ArchonCrystalUpgrades.push({});
|
||||||
}
|
}
|
||||||
suit.ArchonCrystalUpgrades[request.Slot] = {
|
suit.ArchonCrystalUpgrades[request.Slot] = {
|
||||||
UpgradeType: request.UpgradeType,
|
UpgradeType: request.UpgradeType,
|
||||||
@ -92,7 +93,8 @@ export const infestedFoundryController: RequestHandler = async (req, res) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// remove from suit
|
// remove from suit
|
||||||
suit.ArchonCrystalUpgrades![request.Slot] = {};
|
suit.ArchonCrystalUpgrades![request.Slot].UpgradeType = undefined;
|
||||||
|
suit.ArchonCrystalUpgrades![request.Slot].Color = undefined;
|
||||||
|
|
||||||
await inventory.save();
|
await inventory.save();
|
||||||
|
|
||||||
|
@ -251,12 +251,6 @@ const ArchonCrystalUpgradeSchema = new Schema<IArchonCrystalUpgrade>(
|
|||||||
{ _id: false }
|
{ _id: false }
|
||||||
);
|
);
|
||||||
|
|
||||||
ArchonCrystalUpgradeSchema.set("toJSON", {
|
|
||||||
transform(_document, returnedObject) {
|
|
||||||
delete returnedObject.__v;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
const boosterSchema = new Schema<IBooster>(
|
const boosterSchema = new Schema<IBooster>(
|
||||||
{
|
{
|
||||||
ExpiryDate: Number,
|
ExpiryDate: Number,
|
||||||
@ -1079,6 +1073,11 @@ EquipmentSchema.set("toJSON", {
|
|||||||
if (db.UmbraDate) {
|
if (db.UmbraDate) {
|
||||||
client.UmbraDate = toMongoDate(db.UmbraDate);
|
client.UmbraDate = toMongoDate(db.UmbraDate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (client.ArchonCrystalUpgrades) {
|
||||||
|
// For some reason, mongoose turns empty objects here into nulls, so we have to fix it.
|
||||||
|
client.ArchonCrystalUpgrades = client.ArchonCrystalUpgrades.map(x => (x as unknown) ?? {});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user