import WeaponSkins
This commit is contained in:
parent
d11dfc5485
commit
79cf50b9ae
@ -1,7 +1,9 @@
|
|||||||
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
||||||
|
|
||||||
import { Types } from "mongoose";
|
import { Types } from "mongoose";
|
||||||
import { IEquipmentClient, IEquipmentDatabase } from "../types/inventoryTypes/commonInventoryTypes";
|
import { IEquipmentClient, IEquipmentDatabase } from "../types/inventoryTypes/commonInventoryTypes";
|
||||||
import { IMongoDate } from "../types/commonTypes";
|
import { IMongoDate } from "../types/commonTypes";
|
||||||
import { IInventoryResponse } from "../types/inventoryTypes/inventoryTypes";
|
import { IInventoryResponse, IWeaponSkinClient, IWeaponSkinDatabase } from "../types/inventoryTypes/inventoryTypes";
|
||||||
import { TInventoryDatabaseDocument } from "../models/inventoryModels/inventoryModel";
|
import { TInventoryDatabaseDocument } from "../models/inventoryModels/inventoryModel";
|
||||||
|
|
||||||
const convertDate = (value: IMongoDate): Date => {
|
const convertDate = (value: IMongoDate): Date => {
|
||||||
@ -13,7 +15,6 @@ const convertOptionalDate = (value: IMongoDate | undefined): Date | undefined =>
|
|||||||
};
|
};
|
||||||
|
|
||||||
const convertEquipment = (client: IEquipmentClient): IEquipmentDatabase => {
|
const convertEquipment = (client: IEquipmentClient): IEquipmentDatabase => {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
||||||
const { ItemId, ...rest } = client;
|
const { ItemId, ...rest } = client;
|
||||||
return {
|
return {
|
||||||
...rest,
|
...rest,
|
||||||
@ -24,10 +25,22 @@ const convertEquipment = (client: IEquipmentClient): IEquipmentDatabase => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export const importInventory = (db: TInventoryDatabaseDocument, client: IInventoryResponse): void => {
|
const convertWeaponSkin = (client: IWeaponSkinClient): IWeaponSkinDatabase => {
|
||||||
const clientSuitsInDbFormat = client.Suits.map(x => convertEquipment(x));
|
const { ItemId, ...rest } = client;
|
||||||
db.Suits.splice(0, db.Suits.length);
|
return {
|
||||||
clientSuitsInDbFormat.forEach(suitToImport => {
|
...rest,
|
||||||
db.Suits.push(suitToImport);
|
_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);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const importInventory = (db: TInventoryDatabaseDocument, client: IInventoryResponse): void => {
|
||||||
|
replaceArray<IEquipmentDatabase>(db.Suits, client.Suits.map(convertEquipment));
|
||||||
|
replaceArray<IWeaponSkinDatabase>(db.WeaponSkins, client.WeaponSkins.map(convertWeaponSkin));
|
||||||
|
};
|
||||||
|
@ -916,9 +916,10 @@ export interface ITaunt {
|
|||||||
|
|
||||||
export interface IWeaponSkinDatabase {
|
export interface IWeaponSkinDatabase {
|
||||||
ItemType: string;
|
ItemType: string;
|
||||||
|
_id: Types.ObjectId;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IWeaponSkinClient extends IWeaponSkinDatabase {
|
export interface IWeaponSkinClient extends Omit<IWeaponSkinDatabase, "_id"> {
|
||||||
ItemId: IOid;
|
ItemId: IOid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user