chore: fix garbage typings for inventory response
This commit is contained in:
parent
de02dadfc6
commit
819dcae91d
@ -1,11 +1,10 @@
|
||||
import { RequestHandler } from "express";
|
||||
import { getAccountForRequest } from "@/src/services/loginService";
|
||||
import { toInventoryResponse } from "@/src/helpers/inventoryHelpers";
|
||||
import { Inventory, TInventoryDatabaseDocument } from "@/src/models/inventoryModels/inventoryModel";
|
||||
import { Inventory } from "@/src/models/inventoryModels/inventoryModel";
|
||||
import { config } from "@/src/services/configService";
|
||||
import allDialogue from "@/static/fixed_responses/allDialogue.json";
|
||||
import { ILoadoutDatabase } from "@/src/types/saveLoadoutTypes";
|
||||
import { IShipInventory, equipmentKeys } from "@/src/types/inventoryTypes/inventoryTypes";
|
||||
import { IInventoryResponse, IShipInventory, equipmentKeys } from "@/src/types/inventoryTypes/inventoryTypes";
|
||||
import { IPolarity, ArtifactPolarity } from "@/src/types/inventoryTypes/commonInventoryTypes";
|
||||
import {
|
||||
ExportCustoms,
|
||||
@ -26,9 +25,7 @@ export const inventoryController: RequestHandler = async (request, response) =>
|
||||
return;
|
||||
}
|
||||
|
||||
const inventory = await Inventory.findOne({ accountOwnerId: account._id.toString() })
|
||||
.populate<{ LoadOutPresets: ILoadoutDatabase }>("LoadOutPresets")
|
||||
.populate<{ Ships: IShipInventory }>("Ships");
|
||||
const inventory = await Inventory.findOne({ accountOwnerId: account._id.toString() });
|
||||
|
||||
if (!inventory) {
|
||||
response.status(400).json({ error: "inventory was undefined" });
|
||||
@ -63,14 +60,17 @@ export const inventoryController: RequestHandler = async (request, response) =>
|
||||
inventory.InfestedFoundry.AbilityOverrideUnlockCooldown &&
|
||||
new Date() >= inventory.InfestedFoundry.AbilityOverrideUnlockCooldown
|
||||
) {
|
||||
handleSubsumeCompletion(inventory as unknown as TInventoryDatabaseDocument);
|
||||
handleSubsumeCompletion(inventory);
|
||||
await inventory.save();
|
||||
}
|
||||
|
||||
//TODO: make a function that converts from database representation to client
|
||||
const inventoryJSON = inventory.toJSON();
|
||||
|
||||
const inventoryResponse = toInventoryResponse(inventoryJSON);
|
||||
const inventoryWithLoadOutPresets = await inventory.populate<{ LoadOutPresets: ILoadoutDatabase }>(
|
||||
"LoadOutPresets"
|
||||
);
|
||||
const inventoryWithLoadOutPresetsAndShips = await inventoryWithLoadOutPresets.populate<{ Ships: IShipInventory }>(
|
||||
"Ships"
|
||||
);
|
||||
const inventoryResponse = inventoryWithLoadOutPresetsAndShips.toJSON<IInventoryResponse>();
|
||||
|
||||
if (config.infiniteCredits) {
|
||||
inventoryResponse.RegularCredits = 999999999;
|
||||
|
@ -1,14 +1,6 @@
|
||||
import { IMongoDate, IOid } from "@/src/types/commonTypes";
|
||||
import { IInventoryResponse } from "@/src/types/inventoryTypes/inventoryTypes";
|
||||
import { Types } from "mongoose";
|
||||
|
||||
//TODO: this needs to be addressed: a schema's toJSON is responsible for changing Oid and Date to their corresponding Response versions __id to "ItemId":{"$oid":"6450f720bc562ebf030222d4"}, and a Date to "date":{"$date":{"$numberLong":"unix timestamp"})
|
||||
export const toInventoryResponse = (inventoryDatabase: { accountOwnerId: Types.ObjectId }): IInventoryResponse => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const { accountOwnerId, ...inventoryResponse } = inventoryDatabase;
|
||||
return inventoryResponse as unknown as IInventoryResponse;
|
||||
};
|
||||
|
||||
export const toOid = (objectId: Types.ObjectId): IOid => {
|
||||
return { $oid: objectId.toString() } satisfies IOid;
|
||||
};
|
||||
|
@ -1061,6 +1061,7 @@ inventorySchema.set("toJSON", {
|
||||
transform(_document, returnedObject) {
|
||||
delete returnedObject._id;
|
||||
delete returnedObject.__v;
|
||||
delete returnedObject.accountOwnerId;
|
||||
|
||||
const inventoryDatabase = returnedObject as IInventoryDatabase;
|
||||
const inventoryResponse = returnedObject as IInventoryResponse;
|
||||
|
Loading…
x
Reference in New Issue
Block a user