2025-01-19 17:04:38 +01:00
|
|
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
|
|
|
2025-01-19 12:33:04 +01:00
|
|
|
import { Types } from "mongoose";
|
|
|
|
import { IEquipmentClient, IEquipmentDatabase } from "../types/inventoryTypes/commonInventoryTypes";
|
|
|
|
import { IMongoDate } from "../types/commonTypes";
|
2025-01-19 17:04:38 +01:00
|
|
|
import { IInventoryResponse, IWeaponSkinClient, IWeaponSkinDatabase } from "../types/inventoryTypes/inventoryTypes";
|
2025-01-19 12:33:04 +01:00
|
|
|
import { TInventoryDatabaseDocument } from "../models/inventoryModels/inventoryModel";
|
|
|
|
|
2025-01-19 14:53:45 +01:00
|
|
|
const convertDate = (value: IMongoDate): Date => {
|
2025-01-19 12:33:04 +01:00
|
|
|
return new Date(parseInt(value.$date.$numberLong));
|
|
|
|
};
|
|
|
|
|
2025-01-19 14:53:45 +01:00
|
|
|
const convertOptionalDate = (value: IMongoDate | undefined): Date | undefined => {
|
|
|
|
return value ? convertDate(value) : undefined;
|
2025-01-19 12:33:04 +01:00
|
|
|
};
|
|
|
|
|
2025-01-19 14:53:45 +01:00
|
|
|
const convertEquipment = (client: IEquipmentClient): IEquipmentDatabase => {
|
2025-01-19 12:33:04 +01:00
|
|
|
const { ItemId, ...rest } = client;
|
|
|
|
return {
|
|
|
|
...rest,
|
|
|
|
_id: new Types.ObjectId(client.ItemId.$oid),
|
2025-01-19 14:53:45 +01:00
|
|
|
InfestationDate: convertOptionalDate(client.InfestationDate),
|
|
|
|
Expiry: convertOptionalDate(client.Expiry),
|
|
|
|
UpgradesExpiry: convertOptionalDate(client.UpgradesExpiry)
|
2025-01-19 12:33:04 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2025-01-19 17:04:38 +01:00
|
|
|
const convertWeaponSkin = (client: IWeaponSkinClient): IWeaponSkinDatabase => {
|
|
|
|
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 => {
|
|
|
|
arr.push(x);
|
2025-01-19 12:33:04 +01:00
|
|
|
});
|
|
|
|
};
|
2025-01-19 17:04:38 +01:00
|
|
|
|
|
|
|
export const importInventory = (db: TInventoryDatabaseDocument, client: IInventoryResponse): void => {
|
|
|
|
replaceArray<IEquipmentDatabase>(db.Suits, client.Suits.map(convertEquipment));
|
|
|
|
replaceArray<IWeaponSkinDatabase>(db.WeaponSkins, client.WeaponSkins.map(convertWeaponSkin));
|
|
|
|
};
|