missionInventoryUpdate - private functions outside
This commit is contained in:
		
							parent
							
								
									f054db1327
								
							
						
					
					
						commit
						a1c2815728
					
				@ -5,7 +5,7 @@ import { Types } from "mongoose";
 | 
				
			|||||||
import { 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 { IWeaponResponse } from "@/src/types/inventoryTypes/weaponTypes";
 | 
					import { IWeaponResponse } from "@/src/types/inventoryTypes/weaponTypes";
 | 
				
			||||||
import { FlavourItem } from "@/src/types/inventoryTypes/inventoryTypes";
 | 
					import { FlavourItem, IInventoryDatabaseDocument } from "@/src/types/inventoryTypes/inventoryTypes";
 | 
				
			||||||
import {
 | 
					import {
 | 
				
			||||||
    MissionInventoryUpdate,
 | 
					    MissionInventoryUpdate,
 | 
				
			||||||
    MissionInventoryUpdateCard,
 | 
					    MissionInventoryUpdateCard,
 | 
				
			||||||
@ -112,16 +112,11 @@ 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: MissionInventoryUpdate, accountId: string): Promise<void> => {
 | 
					const addGearExpByCategory = (
 | 
				
			||||||
    const { RawUpgrades, MiscItems, Suits, Pistols, LongGuns, Melee, RegularCredits } = data;
 | 
					    inventory: IInventoryDatabaseDocument,
 | 
				
			||||||
    const inventory = await getInventory(accountId);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    // TODO - multipliers logic
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    const addGearExpByCategory = (
 | 
					 | 
				
			||||||
    gearArray: MissionInventoryUpdateGear[] | undefined,
 | 
					    gearArray: MissionInventoryUpdateGear[] | undefined,
 | 
				
			||||||
    categoryName: "Pistols" | "LongGuns" | "Melee" | "Suits"
 | 
					    categoryName: "Pistols" | "LongGuns" | "Melee" | "Suits"
 | 
				
			||||||
    ) => {
 | 
					) => {
 | 
				
			||||||
    const category = inventory[categoryName];
 | 
					    const category = inventory[categoryName];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    gearArray?.forEach(({ ItemId, XP }) => {
 | 
					    gearArray?.forEach(({ ItemId, XP }) => {
 | 
				
			||||||
@ -133,12 +128,13 @@ export const missionInventoryUpdate = async (data: MissionInventoryUpdate, accou
 | 
				
			|||||||
            inventory.markModified(`${categoryName}.${itemIndex}.XP`);
 | 
					            inventory.markModified(`${categoryName}.${itemIndex}.XP`);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
    };
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const addItemsByCategory = (
 | 
					const addItemsByCategory = (
 | 
				
			||||||
 | 
					    inventory: IInventoryDatabaseDocument,
 | 
				
			||||||
    itemsArray: (MissionInventoryUpdateItem | MissionInventoryUpdateCard)[] | undefined,
 | 
					    itemsArray: (MissionInventoryUpdateItem | MissionInventoryUpdateCard)[] | undefined,
 | 
				
			||||||
    categoryName: "RawUpgrades" | "MiscItems"
 | 
					    categoryName: "RawUpgrades" | "MiscItems"
 | 
				
			||||||
    ) => {
 | 
					) => {
 | 
				
			||||||
    const category = inventory[categoryName];
 | 
					    const category = inventory[categoryName];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    itemsArray?.forEach(({ ItemCount, ItemType }) => {
 | 
					    itemsArray?.forEach(({ ItemCount, ItemType }) => {
 | 
				
			||||||
@ -151,15 +147,21 @@ export const missionInventoryUpdate = async (data: MissionInventoryUpdate, accou
 | 
				
			|||||||
            category.push({ ItemCount, ItemType });
 | 
					            category.push({ ItemCount, ItemType });
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
    };
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export const missionInventoryUpdate = async (data: MissionInventoryUpdate, accountId: string): Promise<void> => {
 | 
				
			||||||
 | 
					    const { RawUpgrades, MiscItems, Suits, Pistols, LongGuns, Melee, RegularCredits } = data;
 | 
				
			||||||
 | 
					    const inventory = await getInventory(accountId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // TODO - multipliers logic
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    inventory.RegularCredits += RegularCredits || 0;
 | 
					    inventory.RegularCredits += RegularCredits || 0;
 | 
				
			||||||
    addGearExpByCategory(Pistols, "Pistols");
 | 
					    addGearExpByCategory(inventory, Pistols, "Pistols");
 | 
				
			||||||
    addGearExpByCategory(LongGuns, "LongGuns");
 | 
					    addGearExpByCategory(inventory, LongGuns, "LongGuns");
 | 
				
			||||||
    addGearExpByCategory(Melee, "Melee");
 | 
					    addGearExpByCategory(inventory, Melee, "Melee");
 | 
				
			||||||
    addGearExpByCategory(Suits, "Suits");
 | 
					    addGearExpByCategory(inventory, Suits, "Suits");
 | 
				
			||||||
    addItemsByCategory(RawUpgrades, "RawUpgrades"); // TODO - check mods fusion level
 | 
					    addItemsByCategory(inventory, RawUpgrades, "RawUpgrades"); // TODO - check mods fusion level
 | 
				
			||||||
    addItemsByCategory(MiscItems, "MiscItems");
 | 
					    addItemsByCategory(inventory, MiscItems, "MiscItems");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // TODO - save ChallengeProgress (idk where to save)
 | 
					    // TODO - save ChallengeProgress (idk where to save)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -1,8 +1,11 @@
 | 
				
			|||||||
import { Oid } from "@/src/types/commonTypes";
 | 
					import { Oid } from "@/src/types/commonTypes";
 | 
				
			||||||
import { AbilityOverride, Color, Polarity } from "@/src/types/inventoryTypes/commonInventoryTypes";
 | 
					import { AbilityOverride, Color, Polarity } from "@/src/types/inventoryTypes/commonInventoryTypes";
 | 
				
			||||||
import { Document } from "mongoose";
 | 
					import { Document, Types } from "mongoose";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export interface ISuitDocument extends ISuitResponse, Document {}
 | 
					// export interface ISuitDocument extends ISuitResponse, Document {}
 | 
				
			||||||
 | 
					export interface ISuitDocument extends Document, ISuitResponse {
 | 
				
			||||||
 | 
					    _id: Types.ObjectId;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export interface ISuitResponse extends ISuitDatabase {
 | 
					export interface ISuitResponse extends ISuitDatabase {
 | 
				
			||||||
    ItemId: Oid;
 | 
					    ItemId: Oid;
 | 
				
			||||||
@ -20,6 +23,7 @@ export interface ISuitDatabase {
 | 
				
			|||||||
    ModSlotPurchases?: number;
 | 
					    ModSlotPurchases?: number;
 | 
				
			||||||
    FocusLens?: string;
 | 
					    FocusLens?: string;
 | 
				
			||||||
    UnlockLevel?: number;
 | 
					    UnlockLevel?: number;
 | 
				
			||||||
 | 
					    _id: Types.ObjectId;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export interface SuitConfig {
 | 
					export interface SuitConfig {
 | 
				
			||||||
 | 
				
			|||||||
@ -929,7 +929,7 @@ export interface Progress {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
export interface RawUpgrade {
 | 
					export interface RawUpgrade {
 | 
				
			||||||
    ItemCount: number;
 | 
					    ItemCount: number;
 | 
				
			||||||
    LastAdded: Oid;
 | 
					    LastAdded?: Oid;
 | 
				
			||||||
    ItemType: string;
 | 
					    ItemType: string;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -1,5 +1,6 @@
 | 
				
			|||||||
import { Oid } from "@/src/types/commonTypes";
 | 
					import { Oid } from "@/src/types/commonTypes";
 | 
				
			||||||
import { Color, Polarity } from "@/src/types/inventoryTypes/commonInventoryTypes";
 | 
					import { Color, Polarity } from "@/src/types/inventoryTypes/commonInventoryTypes";
 | 
				
			||||||
 | 
					import { Types } from "mongoose";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export interface IWeaponResponse extends IWeaponDatabase {
 | 
					export interface IWeaponResponse extends IWeaponDatabase {
 | 
				
			||||||
    ItemId: Oid;
 | 
					    ItemId: Oid;
 | 
				
			||||||
@ -20,6 +21,7 @@ export interface IWeaponDatabase {
 | 
				
			|||||||
    ItemName?: string;
 | 
					    ItemName?: string;
 | 
				
			||||||
    ModularParts?: string[];
 | 
					    ModularParts?: string[];
 | 
				
			||||||
    UnlockLevel?: number;
 | 
					    UnlockLevel?: number;
 | 
				
			||||||
 | 
					    _id?: Types.ObjectId;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export interface WeaponConfig {
 | 
					export interface WeaponConfig {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user