import Upgrades
This commit is contained in:
		
							parent
							
								
									83015ec8f3
								
							
						
					
					
						commit
						ce2459113b
					
				@ -1,11 +1,17 @@
 | 
			
		||||
/* eslint-disable @typescript-eslint/no-unused-vars */
 | 
			
		||||
 | 
			
		||||
import { Types } from "mongoose";
 | 
			
		||||
import { IEquipmentClient, IEquipmentDatabase } from "../types/inventoryTypes/commonInventoryTypes";
 | 
			
		||||
import { IMongoDate } from "../types/commonTypes";
 | 
			
		||||
import { IInventoryClient, IWeaponSkinClient, IWeaponSkinDatabase } from "../types/inventoryTypes/inventoryTypes";
 | 
			
		||||
import {
 | 
			
		||||
    IInventoryClient,
 | 
			
		||||
    IUpgradeClient,
 | 
			
		||||
    IUpgradeDatabase,
 | 
			
		||||
    IWeaponSkinClient,
 | 
			
		||||
    IWeaponSkinDatabase
 | 
			
		||||
} from "../types/inventoryTypes/inventoryTypes";
 | 
			
		||||
import { TInventoryDatabaseDocument } from "../models/inventoryModels/inventoryModel";
 | 
			
		||||
 | 
			
		||||
/* eslint-disable @typescript-eslint/no-unused-vars */
 | 
			
		||||
 | 
			
		||||
const convertDate = (value: IMongoDate): Date => {
 | 
			
		||||
    return new Date(parseInt(value.$date.$numberLong));
 | 
			
		||||
};
 | 
			
		||||
@ -33,6 +39,14 @@ const convertWeaponSkin = (client: IWeaponSkinClient): IWeaponSkinDatabase => {
 | 
			
		||||
    };
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
const convertUpgrade = (client: IUpgradeClient): IUpgradeDatabase => {
 | 
			
		||||
    const { ItemId, ...rest } = client;
 | 
			
		||||
    return {
 | 
			
		||||
        ...rest,
 | 
			
		||||
        _id: new Types.ObjectId(client.ItemId.$oid)
 | 
			
		||||
    };
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
const replaceArray = <T>(arr: T[], replacement: T[]): void => {
 | 
			
		||||
    arr.splice(0, arr.length);
 | 
			
		||||
    replacement.forEach(x => {
 | 
			
		||||
@ -43,4 +57,5 @@ const replaceArray = <T>(arr: T[], replacement: T[]): void => {
 | 
			
		||||
export const importInventory = (db: TInventoryDatabaseDocument, client: IInventoryClient): void => {
 | 
			
		||||
    replaceArray<IEquipmentDatabase>(db.Suits, client.Suits.map(convertEquipment));
 | 
			
		||||
    replaceArray<IWeaponSkinDatabase>(db.WeaponSkins, client.WeaponSkins.map(convertWeaponSkin));
 | 
			
		||||
    replaceArray<IUpgradeDatabase>(db.Upgrades, client.Upgrades.map(convertUpgrade));
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user