MissionInventoryUpdate(not completed), Mod upgrade, Booster purchase #49
@ -2,10 +2,11 @@ import { Inventory } from "@/src/models/inventoryModel";
 | 
				
			|||||||
import new_inventory from "@/static/fixed_responses/postTutorialInventory.json";
 | 
					import new_inventory from "@/static/fixed_responses/postTutorialInventory.json";
 | 
				
			||||||
import config from "@/config.json";
 | 
					import config from "@/config.json";
 | 
				
			||||||
import { Types } from "mongoose";
 | 
					import { Types } from "mongoose";
 | 
				
			||||||
import { ISuitDatabase, ISuitResponse } from "@/src/types/inventoryTypes/SuitTypes";
 | 
					import { ISuitResponse } from "@/src/types/inventoryTypes/SuitTypes";
 | 
				
			||||||
import { SlotType } from "@/src/types/purchaseTypes";
 | 
					import { SlotType } from "@/src/types/purchaseTypes";
 | 
				
			||||||
import { IWeaponDatabase, IWeaponResponse } from "@/src/types/inventoryTypes/weaponTypes";
 | 
					import { IWeaponResponse } from "@/src/types/inventoryTypes/weaponTypes";
 | 
				
			||||||
import { FlavourItem, RawUpgrade, MiscItem } from "@/src/types/inventoryTypes/inventoryTypes";
 | 
					import { FlavourItem } from "@/src/types/inventoryTypes/inventoryTypes";
 | 
				
			||||||
 | 
					import { MissionInventoryUpdate, MissionInventoryUpdateCard, MissionInventoryUpdateGear, MissionInventoryUpdateItem } from "../types/missionInventoryUpdateType";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const createInventory = async (accountOwnerId: Types.ObjectId) => {
 | 
					const createInventory = async (accountOwnerId: Types.ObjectId) => {
 | 
				
			||||||
    try {
 | 
					    try {
 | 
				
			||||||
@ -106,30 +107,35 @@ export const addCustomization = async (customizatonName: string, accountId: stri
 | 
				
			|||||||
    return changedInventory.FlavourItems[flavourItemIndex].toJSON(); //mongoose bug forces as FlavourItem
 | 
					    return changedInventory.FlavourItems[flavourItemIndex].toJSON(); //mongoose bug forces as FlavourItem
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const missionInventoryUpdate = async (data: any, accountId: string): Promise<void> => { // TODO - add data type
 | 
					export const missionInventoryUpdate = async (data: MissionInventoryUpdate, accountId: string): Promise<void> => {
 | 
				
			||||||
    const { RawUpgrades, MiscItems, Suits, Pistols, LongGuns, Melee, RegularCredits } = data;
 | 
					    const { RawUpgrades, MiscItems, Suits, Pistols, LongGuns, Melee, RegularCredits } = data;
 | 
				
			||||||
    const inventory = await getInventory(accountId);
 | 
					    const inventory = await getInventory(accountId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const addGearExpByCategory = (gearArray: (ISuitDatabase|IWeaponDatabase)[], category: 'Pistols'|'LongGuns'|'Melee'|'Suits') => {
 | 
					    const addGearExpByCategory = (gearArray: MissionInventoryUpdateGear[] | undefined, categoryName: 'Pistols'|'LongGuns'|'Melee'|'Suits') => {
 | 
				
			||||||
        gearArray?.forEach(({ ItemId, XP }: any) => {
 | 
					        const category = inventory[categoryName];
 | 
				
			||||||
            const itemIndex = inventory[category].findIndex(i => i._id?.equals(ItemId.$oid));
 | 
					
 | 
				
			||||||
            if (itemIndex !== -1) {
 | 
					        gearArray?.forEach(({ ItemId, XP }) => {
 | 
				
			||||||
                inventory[category][itemIndex].XP += XP;
 | 
					            const itemIndex = category.findIndex(i => i._id?.equals(ItemId.$oid));
 | 
				
			||||||
                inventory.markModified(`${category}.${itemIndex}.XP`);
 | 
					            const item = category[itemIndex];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if (itemIndex !== -1 && item.XP!=undefined) {
 | 
				
			||||||
 | 
					                item.XP += XP;
 | 
				
			||||||
 | 
					                inventory.markModified(`${categoryName}.${itemIndex}.XP`);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const addItemsByCategory = (itemsArray: (RawUpgrade | MiscItem)[], category: 'RawUpgrades'|'MiscItems') => {
 | 
					    const addItemsByCategory = (itemsArray: (MissionInventoryUpdateItem | MissionInventoryUpdateCard)[] | undefined, categoryName: 'RawUpgrades'|'MiscItems') => {
 | 
				
			||||||
        itemsArray?.forEach(item => {
 | 
					        const category = inventory[categoryName];
 | 
				
			||||||
            const { ItemCount, ItemType } = item;
 | 
					 | 
				
			||||||
            const existingItemIndex = inventory[category].findIndex(i => i.ItemType === ItemType);
 | 
					 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
            if (existingItemIndex !== -1) {
 | 
					        itemsArray?.forEach(({ ItemCount, ItemType }) => {
 | 
				
			||||||
                inventory[category][existingItemIndex].ItemCount += ItemCount;
 | 
					            const itemIndex = category.findIndex(i => i.ItemType === ItemType);
 | 
				
			||||||
                inventory.markModified(category + '.' + existingItemIndex + '.ItemCount');
 | 
					
 | 
				
			||||||
 | 
					            if (itemIndex !== -1) {
 | 
				
			||||||
 | 
					                category[itemIndex].ItemCount += ItemCount;
 | 
				
			||||||
 | 
					                inventory.markModified(`${categoryName}.${itemIndex}.ItemCount`);
 | 
				
			||||||
            } else {
 | 
					            } else {
 | 
				
			||||||
                inventory[category].push({ ItemCount, ItemType });
 | 
					                category.push({ ItemCount, ItemType });
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
@ -142,6 +148,8 @@ export const missionInventoryUpdate = async (data: any, accountId: string): Prom
 | 
				
			|||||||
    addItemsByCategory(RawUpgrades, 'RawUpgrades'); // TODO - check mods fusion level
 | 
					    addItemsByCategory(RawUpgrades, 'RawUpgrades'); // TODO - check mods fusion level
 | 
				
			||||||
    addItemsByCategory(MiscItems, 'MiscItems');
 | 
					    addItemsByCategory(MiscItems, 'MiscItems');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // TODO - save ChallengeProgress (idk where to save)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    await inventory.save();
 | 
					    await inventory.save();
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										64
									
								
								src/types/missionInventoryUpdateType.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						@ -0,0 +1,64 @@
 | 
				
			|||||||
| 
						
							
	
	
	
	
	
	
	
	 | 
				|||||||
 | 
					interface MongooseId{
 | 
				
			||||||
| 
						
							
	
	
	
	
	
	
	
	 instead of this use /types/commonTypes Oid type instead of this use /types/commonTypes Oid type 
			
			
		 | 
				|||||||
 | 
					    $oid: string;
 | 
				
			||||||
| 
						
							
	
	
	
	
	
	
	
	 instead of this use /types/commonTypes Oid type instead of this use /types/commonTypes Oid type 
			
			
		 | 
				|||||||
 | 
					}
 | 
				
			||||||
| 
						
							
	
	
	
	
	
	
	
	 instead of this use /types/commonTypes Oid type instead of this use /types/commonTypes Oid type 
			
			
		 | 
				|||||||
 | 
					
 | 
				
			||||||
| 
						
							
	
	
	
	
	
	
	
	 instead of this use /types/commonTypes Oid type instead of this use /types/commonTypes Oid type 
			
			
		 | 
				|||||||
 | 
					interface ExpireDate{
 | 
				
			||||||
| 
						
							
	
	
	
	
	
	
	
	 instead of this use /types/commonTypes Oid type instead of this use /types/commonTypes Oid type 
			
			
		 | 
				|||||||
 | 
					    $date: {
 | 
				
			||||||
| 
						
							
	
	
	
	
	
	
	
	 instead of this use /types/commonTypes Oid type instead of this use /types/commonTypes Oid type 
			
			
		 | 
				|||||||
 | 
					        $numberLong: string;
 | 
				
			||||||
| 
						
							
	
	
	
	
	
	
	
	 instead of this use /types/commonTypes Oid type instead of this use /types/commonTypes Oid type 
			
			
		 | 
				|||||||
 | 
					    }
 | 
				
			||||||
| 
						
							
	
	
	
	
	
	
	
	 instead of this use /types/commonTypes Oid type instead of this use /types/commonTypes Oid type 
			
			
		 | 
				|||||||
 | 
					}
 | 
				
			||||||
| 
						
							
	
	
	
	
	
	
	
	 instead of this use /types/commonTypes Oid type instead of this use /types/commonTypes Oid type 
			
			
		 | 
				|||||||
 | 
					
 | 
				
			||||||
| 
						
							
	
	
	
	
	
	
	
	 instead of this use /types/commonTypes Oid type instead of this use /types/commonTypes Oid type 
			
			
		 | 
				|||||||
 | 
					export interface MissionInventoryUpdateGear{
 | 
				
			||||||
| 
						
							
	
	
	
	
	
	
	
	 instead of this use /types/commonTypes Oid type instead of this use /types/commonTypes Oid type 
			
			
		 | 
				|||||||
 | 
					    ItemType: string;
 | 
				
			||||||
| 
						
							
	
	
	
	
	
	
	
	 instead of this use /types/commonTypes Oid type instead of this use /types/commonTypes Oid type 
			
			
		 | 
				|||||||
 | 
					    ItemName: string;
 | 
				
			||||||
| 
						
							
	
	
	
	
	
	
	
	 instead of this use /types/commonTypes Oid type instead of this use /types/commonTypes Oid type 
			
			
		 | 
				|||||||
 | 
					    ItemId: MongooseId;
 | 
				
			||||||
| 
						
							
	
	
	
	
	
	
	
	 instead of this use /types/commonTypes Oid type instead of this use /types/commonTypes Oid type 
			
			
		 | 
				|||||||
 | 
					    XP: number;
 | 
				
			||||||
| 
						
							
	
	
	
	
	
	
	
	 instead of this use /types/commonTypes Oid type instead of this use /types/commonTypes Oid type 
			
			
		 | 
				|||||||
 | 
					    UpgradeVer: number;
 | 
				
			||||||
| 
						
							
	
	
	
	
	
	
	
	 instead of this use /types/commonTypes Oid type instead of this use /types/commonTypes Oid type 
			
			
		 | 
				|||||||
 | 
					    Features: number;
 | 
				
			||||||
| 
						
							
	
	
	
	
	
	
	
	 instead of this use /types/commonTypes Oid type instead of this use /types/commonTypes Oid type 
			
			
		 | 
				|||||||
 | 
					    Polarized: number;
 | 
				
			||||||
| 
						
							
	
	
	
	
	
	
	
	 instead of this use /types/commonTypes Oid type instead of this use /types/commonTypes Oid type 
			
			
		 | 
				|||||||
 | 
					    CustomizationSlotPurchases: number;
 | 
				
			||||||
| 
						
							
	
	
	
	
	
	
	
	 instead of this use /types/commonTypes Oid type instead of this use /types/commonTypes Oid type 
			
			
		 | 
				|||||||
 | 
					    ModSlotPurchases: number;
 | 
				
			||||||
| 
						
							
	
	
	
	
	
	
	
	 instead of this use /types/commonTypes Oid type instead of this use /types/commonTypes Oid type 
			
			
		 | 
				|||||||
 | 
					    FocusLens: string;
 | 
				
			||||||
| 
						
							
	
	
	
	
	
	
	
	 instead of this use /types/commonTypes Oid type instead of this use /types/commonTypes Oid type 
			
			
		 | 
				|||||||
 | 
					    Expiry: ExpireDate;
 | 
				
			||||||
| 
						
							
	
	
	
	
	
	
	
	 instead of this use /types/commonTypes Oid type instead of this use /types/commonTypes Oid type 
			
			
		 | 
				|||||||
 | 
					    Polarity: any[];
 | 
				
			||||||
| 
						
							
	
	
	
	
	
	
	
	 instead of this use /types/commonTypes Oid type instead of this use /types/commonTypes Oid type 
			
			
		 | 
				|||||||
 | 
					    Configs: any[];
 | 
				
			||||||
| 
						
							
	
	
	
	
	
	
	
	 instead of this use /types/commonTypes Oid type instead of this use /types/commonTypes Oid type 
			
			
		 | 
				|||||||
 | 
					    ModularParts: any[];
 | 
				
			||||||
| 
						
							
	
	
	
	
	
	
	
	 instead of this use /types/commonTypes Oid type instead of this use /types/commonTypes Oid type 
			
			
		 | 
				|||||||
 | 
					    SkillTree: string;
 | 
				
			||||||
| 
						
							
	
	
	
	
	
	
	
	 instead of this use /types/commonTypes Oid type instead of this use /types/commonTypes Oid type 
			
			
		 | 
				|||||||
 | 
					    UpgradeType: string;
 | 
				
			||||||
| 
						
							
	
	
	
	
	
	
	
	 instead of this use /types/commonTypes Oid type instead of this use /types/commonTypes Oid type 
			
			
		 | 
				|||||||
 | 
					    UpgradeFingerprint: string;
 | 
				
			||||||
| 
						
							
	
	
	
	
	
	
	
	 instead of this use /types/commonTypes Oid type instead of this use /types/commonTypes Oid type 
			
			
		 | 
				|||||||
 | 
					    OffensiveUpgrade: string;
 | 
				
			||||||
| 
						
							
	
	
	
	
	
	
	
	 instead of this use /types/commonTypes Oid type instead of this use /types/commonTypes Oid type 
			
			
		 | 
				|||||||
 | 
					    DefensiveUpgrade: string;
 | 
				
			||||||
| 
						
							
	
	
	
	
	
	
	
	 instead of this use /types/commonTypes Oid type instead of this use /types/commonTypes Oid type 
			
			
		 | 
				|||||||
 | 
					    UpgradesExpiry: ExpireDate;
 | 
				
			||||||
| 
						
							
	
	
	
	
	
	
	
	 instead of this use /types/commonTypes Oid type instead of this use /types/commonTypes Oid type 
			
			
		 | 
				|||||||
 | 
					    ArchonCrystalUpgrades: any[];
 | 
				
			||||||
| 
						
							
	
	
	
	
	
	
	
	 instead of this use /types/commonTypes Oid type instead of this use /types/commonTypes Oid type 
			
			
		 | 
				|||||||
 | 
					}
 | 
				
			||||||
| 
						
							
	
	
	
	
	
	
	
	 instead of this use /types/commonTypes Oid type instead of this use /types/commonTypes Oid type 
			
			
		 | 
				|||||||
 | 
					
 | 
				
			||||||
| 
						
							
	
	
	
	
	
	
	
	 instead of this use /types/commonTypes Oid type instead of this use /types/commonTypes Oid type 
			
			
		 | 
				|||||||
 | 
					export interface MissionInventoryUpdateItem{
 | 
				
			||||||
| 
						
							
	
	
	
	
	
	
	
	 instead of this use /types/commonTypes Oid type instead of this use /types/commonTypes Oid type 
			
			
		 | 
				|||||||
 | 
					    ItemCount: number;
 | 
				
			||||||
| 
						
							
	
	
	
	
	
	
	
	 instead of this use /types/commonTypes Oid type instead of this use /types/commonTypes Oid type 
			
			
		 | 
				|||||||
 | 
					    ItemType: string;
 | 
				
			||||||
| 
						
							
	
	
	
	
	
	
	
	 instead of this use /types/commonTypes Oid type instead of this use /types/commonTypes Oid type 
			
			
		 | 
				|||||||
 | 
					}
 | 
				
			||||||
| 
						
							
	
	
	
	
	
	
	
	 instead of this use /types/commonTypes Oid type instead of this use /types/commonTypes Oid type 
			
			
		 | 
				|||||||
 | 
					
 | 
				
			||||||
| 
						
							
	
	
	
	
	
	
	
	 instead of this use /types/commonTypes Oid type instead of this use /types/commonTypes Oid type 
			
			
		 | 
				|||||||
 | 
					export interface MissionInventoryUpdateCard extends MissionInventoryUpdateItem{
 | 
				
			||||||
| 
						
							
	
	
	
	
	
	
	
	 instead of this use /types/commonTypes Oid type instead of this use /types/commonTypes Oid type 
			
			
		 | 
				|||||||
 | 
					    ItemId: MongooseId;
 | 
				
			||||||
| 
						
							
	
	
	
	
	
	
	
	 instead of this use /types/commonTypes Oid type instead of this use /types/commonTypes Oid type 
			
			
		 | 
				|||||||
 | 
					    UpgradeFingerprint: string;
 | 
				
			||||||
| 
						
							
	
	
	
	
	
	
	
	 instead of this use /types/commonTypes Oid type instead of this use /types/commonTypes Oid type 
			
			
		 | 
				|||||||
 | 
					    PendingRerollFingerprint: string;
 | 
				
			||||||
| 
						
							
	
	
	
	
	
	
	
	 instead of this use /types/commonTypes Oid type instead of this use /types/commonTypes Oid type 
			
			
		 | 
				|||||||
 | 
					    LastAdded: MongooseId;
 | 
				
			||||||
| 
						
							
	
	
	
	
	
	
	
	 instead of this use /types/commonTypes Oid type instead of this use /types/commonTypes Oid type 
			
			
		 | 
				|||||||
 | 
					}
 | 
				
			||||||
| 
						
							
	
	
	
	
	
	
	
	 instead of this use /types/commonTypes Oid type instead of this use /types/commonTypes Oid type 
			
			
		 | 
				|||||||
 | 
					
 | 
				
			||||||
| 
						
							
	
	
	
	
	
	
	
	 instead of this use /types/commonTypes Oid type instead of this use /types/commonTypes Oid type 
			
			
		 | 
				|||||||
 | 
					interface MissionInventoryUpdateChallange{
 | 
				
			||||||
| 
						
							
	
	
	
	
	
	
	
	 instead of this use /types/commonTypes Oid type instead of this use /types/commonTypes Oid type 
			
			
		 | 
				|||||||
 | 
					    Name: string;
 | 
				
			||||||
| 
						
							
	
	
	
	
	
	
	
	 instead of this use /types/commonTypes Oid type instead of this use /types/commonTypes Oid type 
			
			
		 | 
				|||||||
 | 
					    Progress: number;
 | 
				
			||||||
| 
						
							
	
	
	
	
	
	
	
	 instead of this use /types/commonTypes Oid type instead of this use /types/commonTypes Oid type 
			
			
		 | 
				|||||||
 | 
					    Completed: any[];
 | 
				
			||||||
| 
						
							
	
	
	
	
	
	
	
	 instead of this use /types/commonTypes Oid type instead of this use /types/commonTypes Oid type 
			
			
		 | 
				|||||||
 | 
					}
 | 
				
			||||||
| 
						
							
	
	
	
	
	
	
	
	 instead of this use /types/commonTypes Oid type instead of this use /types/commonTypes Oid type 
			
			
		 | 
				|||||||
 | 
					
 | 
				
			||||||
| 
						
							
	
	
	
	
	
	
	
	 instead of this use /types/commonTypes Oid type instead of this use /types/commonTypes Oid type 
			
			
		 | 
				|||||||
 | 
					export interface MissionInventoryUpdate{
 | 
				
			||||||
| 
						
							
	
	
	
	
	
	
	
	 instead of this use /types/commonTypes Oid type instead of this use /types/commonTypes Oid type 
			
			
		 | 
				|||||||
 | 
					    rewardsMultiplier?: number;
 | 
				
			||||||
| 
						
							
	
	
	
	
	
	
	
	 instead of this use /types/commonTypes Oid type instead of this use /types/commonTypes Oid type 
			
			
		 | 
				|||||||
 | 
					    ActiveBoosters?: any[];
 | 
				
			||||||
| 
						
							
	
	
	
	
	
	
	
	 instead of this use /types/commonTypes Oid type instead of this use /types/commonTypes Oid type 
			
			
		 | 
				|||||||
 | 
					    LongGuns?: MissionInventoryUpdateGear[];
 | 
				
			||||||
| 
						
							
	
	
	
	
	
	
	
	 instead of this use /types/commonTypes Oid type instead of this use /types/commonTypes Oid type 
			
			
		 | 
				|||||||
 | 
					    Pistols?: MissionInventoryUpdateGear[];
 | 
				
			||||||
| 
						
							
	
	
	
	
	
	
	
	 instead of this use /types/commonTypes Oid type instead of this use /types/commonTypes Oid type 
			
			
		 | 
				|||||||
 | 
					    Suits?: MissionInventoryUpdateGear[];
 | 
				
			||||||
| 
						
							
	
	
	
	
	
	
	
	 instead of this use /types/commonTypes Oid type instead of this use /types/commonTypes Oid type 
			
			
		 | 
				|||||||
 | 
					    Melee?: MissionInventoryUpdateGear[];
 | 
				
			||||||
| 
						
							
	
	
	
	
	
	
	
	 instead of this use /types/commonTypes Oid type instead of this use /types/commonTypes Oid type 
			
			
		 | 
				|||||||
 | 
					    RawUpgrades?: MissionInventoryUpdateCard[];
 | 
				
			||||||
| 
						
							
	
	
	
	
	
	
	
	 instead of this use /types/commonTypes Oid type instead of this use /types/commonTypes Oid type 
			
			
		 | 
				|||||||
 | 
					    MiscItems?: MissionInventoryUpdateItem[];
 | 
				
			||||||
| 
						
							
	
	
	
	
	
	
	
	 instead of this use /types/commonTypes Oid type instead of this use /types/commonTypes Oid type 
			
			
		 | 
				|||||||
 | 
					    RegularCredits?: number;
 | 
				
			||||||
| 
						
							
	
	
	
	
	
	
	
	 instead of this use /types/commonTypes Oid type instead of this use /types/commonTypes Oid type 
			
			
		 | 
				|||||||
 | 
					    ChallengeProgress?: MissionInventoryUpdateChallange[];
 | 
				
			||||||
| 
						
							
	
	
	
	
	
	
	
	 instead of this use /types/commonTypes Oid type instead of this use /types/commonTypes Oid type 
			
			
		 | 
				|||||||
 | 
					}
 | 
				
			||||||
| 
						
							
	
	
	
	
	
	
	
	 instead of this use /types/commonTypes Oid type instead of this use /types/commonTypes Oid type 
			
			
		 | 
				|||||||
instead of this use /types/commonTypes Oid type
instead of this use /types/commonTypes Oid type