rename converter functions

This commit is contained in:
Sainan 2025-01-19 14:53:45 +01:00
parent b41ce3751c
commit 03716daa62

View File

@ -4,23 +4,23 @@ import { IMongoDate } from "../types/commonTypes";
import { IInventoryResponse } from "../types/inventoryTypes/inventoryTypes"; import { IInventoryResponse } from "../types/inventoryTypes/inventoryTypes";
import { TInventoryDatabaseDocument } from "../models/inventoryModels/inventoryModel"; import { TInventoryDatabaseDocument } from "../models/inventoryModels/inventoryModel";
const importDate = (value: IMongoDate): Date => { const convertDate = (value: IMongoDate): Date => {
return new Date(parseInt(value.$date.$numberLong)); return new Date(parseInt(value.$date.$numberLong));
}; };
const importOptionalDate = (value: IMongoDate | undefined): Date | undefined => { const convertOptionalDate = (value: IMongoDate | undefined): Date | undefined => {
return value ? importDate(value) : undefined; return value ? convertDate(value) : undefined;
}; };
const importEquipment = (client: IEquipmentClient): IEquipmentDatabase => { const convertEquipment = (client: IEquipmentClient): IEquipmentDatabase => {
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
const { ItemId, ...rest } = client; const { ItemId, ...rest } = client;
return { return {
...rest, ...rest,
_id: new Types.ObjectId(client.ItemId.$oid), _id: new Types.ObjectId(client.ItemId.$oid),
InfestationDate: importOptionalDate(client.InfestationDate), InfestationDate: convertOptionalDate(client.InfestationDate),
Expiry: importOptionalDate(client.Expiry), Expiry: convertOptionalDate(client.Expiry),
UpgradesExpiry: importOptionalDate(client.UpgradesExpiry) UpgradesExpiry: convertOptionalDate(client.UpgradesExpiry)
}; };
}; };
@ -30,7 +30,7 @@ export const importInventory = (
replace: boolean = false, replace: boolean = false,
update: boolean = true update: boolean = true
): void => { ): void => {
const clientSuitsInDbFormat = client.Suits.map(x => importEquipment(x)); const clientSuitsInDbFormat = client.Suits.map(x => convertEquipment(x));
if (replace) { if (replace) {
db.Suits.splice(0, db.Suits.length); db.Suits.splice(0, db.Suits.length);
} }