diff --git a/src/models/inventoryModels/inventoryModel.ts b/src/models/inventoryModels/inventoryModel.ts index 7dae8540..8aa2bc42 100644 --- a/src/models/inventoryModels/inventoryModel.ts +++ b/src/models/inventoryModels/inventoryModel.ts @@ -781,9 +781,25 @@ const loreFragmentScansSchema = new Schema( { _id: false } ); -const lotusCustomizationSchema = new Schema().add(ItemConfigSchema).add({ - Persona: String -}); +// const lotusCustomizationSchema = new Schema().add(ItemConfigSchema).add({ +// Persona: String +// }); + +// Laxer schema for cleanupInventory +const lotusCustomizationSchema = new Schema( + { + Skins: [String], + pricol: colorSchema, + attcol: Schema.Types.Mixed, + sigcol: Schema.Types.Mixed, + eyecol: Schema.Types.Mixed, + facial: Schema.Types.Mixed, + cloth: Schema.Types.Mixed, + syancol: Schema.Types.Mixed, + Persona: String + }, + { _id: false } +); const evolutionProgressSchema = new Schema( { diff --git a/src/services/importService.ts b/src/services/importService.ts index a3141073..7fb88619 100644 --- a/src/services/importService.ts +++ b/src/services/importService.ts @@ -2,6 +2,7 @@ import { Types } from "mongoose"; import { IEquipmentClient, IEquipmentDatabase, + IItemConfig, IOperatorConfigClient, IOperatorConfigDatabase } from "../types/inventoryTypes/commonInventoryTypes"; @@ -174,6 +175,20 @@ const convertNemesis = (client: INemesisClient): INemesisDatabase => { }; }; +// Empty objects from live may have been encoded as empty arrays because of PHP. +const convertItemConfig = (client: T): T => { + return { + ...client, + pricol: Array.isArray(client.pricol) ? {} : client.pricol, + attcol: Array.isArray(client.attcol) ? {} : client.attcol, + sigcol: Array.isArray(client.sigcol) ? {} : client.sigcol, + eyecol: Array.isArray(client.eyecol) ? {} : client.eyecol, + facial: Array.isArray(client.facial) ? {} : client.facial, + cloth: Array.isArray(client.cloth) ? {} : client.cloth, + syancol: Array.isArray(client.syancol) ? {} : client.syancol + }; +}; + export const importInventory = (db: TInventoryDatabaseDocument, client: Partial): void => { for (const key of equipmentKeys) { if (client[key] !== undefined) { @@ -352,7 +367,7 @@ export const importInventory = (db: TInventoryDatabaseDocument, client: Partial< db.PlayerSkills = client.PlayerSkills; } if (client.LotusCustomization !== undefined) { - db.LotusCustomization = client.LotusCustomization; + db.LotusCustomization = convertItemConfig(client.LotusCustomization); } if (client.CollectibleSeries !== undefined) { db.CollectibleSeries = client.CollectibleSeries; diff --git a/src/services/inventoryService.ts b/src/services/inventoryService.ts index 90ed22f5..c3d47ec6 100644 --- a/src/services/inventoryService.ts +++ b/src/services/inventoryService.ts @@ -1847,6 +1847,25 @@ export const cleanupInventory = (inventory: TInventoryDatabaseDocument): void => logger.debug(`removing FreeFavorsEarned from LibrarySyndicate`); LibrarySyndicate.FreeFavorsEarned = undefined; } + + if (inventory.LotusCustomization) { + if ( + Array.isArray(inventory.LotusCustomization.attcol) || + Array.isArray(inventory.LotusCustomization.sigcol) || + Array.isArray(inventory.LotusCustomization.eyecol) || + Array.isArray(inventory.LotusCustomization.facial) || + Array.isArray(inventory.LotusCustomization.cloth) || + Array.isArray(inventory.LotusCustomization.syancol) + ) { + logger.debug(`fixing empty objects represented as empty arrays in LotusCustomization`); + inventory.LotusCustomization.attcol = {}; + inventory.LotusCustomization.sigcol = {}; + inventory.LotusCustomization.eyecol = {}; + inventory.LotusCustomization.facial = {}; + inventory.LotusCustomization.cloth = {}; + inventory.LotusCustomization.syancol = {}; + } + } }; export const getCalendarProgress = (inventory: TInventoryDatabaseDocument): ICalendarProgress => {