import loadout presets
This commit is contained in:
parent
9c5310e418
commit
af065c5928
@ -1,15 +1,24 @@
|
||||
import { importInventory } from "@/src/services/importService";
|
||||
import { importInventory, importLoadOutPresets } from "@/src/services/importService";
|
||||
import { getInventory } from "@/src/services/inventoryService";
|
||||
import { getLoadout } from "@/src/services/loadoutService";
|
||||
import { getAccountIdForRequest } from "@/src/services/loginService";
|
||||
import { IInventoryClient } from "@/src/types/inventoryTypes/inventoryTypes";
|
||||
import { RequestHandler } from "express";
|
||||
|
||||
export const importController: RequestHandler = async (req, res) => {
|
||||
const accountId = await getAccountIdForRequest(req);
|
||||
const inventory = await getInventory(accountId);
|
||||
const request = JSON.parse(String(req.body)) as IImportRequest;
|
||||
|
||||
const inventory = await getInventory(accountId);
|
||||
importInventory(inventory, request.inventory);
|
||||
await inventory.save();
|
||||
|
||||
if (request.inventory.LoadOutPresets) {
|
||||
const loadout = await getLoadout(accountId);
|
||||
importLoadOutPresets(loadout, request.inventory.LoadOutPresets);
|
||||
await loadout.save();
|
||||
}
|
||||
|
||||
res.end();
|
||||
};
|
||||
|
||||
|
@ -9,6 +9,8 @@ import { IMongoDate } from "../types/commonTypes";
|
||||
import {
|
||||
equipmentKeys,
|
||||
IInventoryClient,
|
||||
ILoadoutConfigClient,
|
||||
ILoadOutPresets,
|
||||
ISlots,
|
||||
IUpgradeClient,
|
||||
IUpgradeDatabase,
|
||||
@ -16,6 +18,7 @@ import {
|
||||
IWeaponSkinDatabase
|
||||
} from "../types/inventoryTypes/inventoryTypes";
|
||||
import { TInventoryDatabaseDocument } from "../models/inventoryModels/inventoryModel";
|
||||
import { ILoadoutConfigDatabase, ILoadoutDatabase } from "../types/saveLoadoutTypes";
|
||||
|
||||
/* eslint-disable @typescript-eslint/no-unused-vars */
|
||||
|
||||
@ -137,3 +140,25 @@ export const importInventory = (db: TInventoryDatabaseDocument, client: Partial<
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const convertLoadOutConfig = (client: ILoadoutConfigClient): ILoadoutConfigDatabase => {
|
||||
const { ItemId, ...rest } = client;
|
||||
return {
|
||||
...rest,
|
||||
_id: new Types.ObjectId(client.ItemId.$oid)
|
||||
};
|
||||
};
|
||||
|
||||
export const importLoadOutPresets = (db: ILoadoutDatabase, client: ILoadOutPresets): void => {
|
||||
db.NORMAL = client.NORMAL.map(convertLoadOutConfig);
|
||||
db.SENTINEL = client.SENTINEL.map(convertLoadOutConfig);
|
||||
db.ARCHWING = client.ARCHWING.map(convertLoadOutConfig);
|
||||
db.NORMAL_PVP = client.NORMAL_PVP.map(convertLoadOutConfig);
|
||||
db.LUNARO = client.LUNARO.map(convertLoadOutConfig);
|
||||
db.OPERATOR = client.OPERATOR.map(convertLoadOutConfig);
|
||||
db.KDRIVE = client.KDRIVE.map(convertLoadOutConfig);
|
||||
db.DATAKNIFE = client.DATAKNIFE.map(convertLoadOutConfig);
|
||||
db.MECH = client.MECH.map(convertLoadOutConfig);
|
||||
db.OPERATOR_ADULT = client.OPERATOR_ADULT.map(convertLoadOutConfig);
|
||||
db.DRIFTER = client.DRIFTER.map(convertLoadOutConfig);
|
||||
};
|
||||
|
@ -210,7 +210,7 @@ export interface IInventoryClient extends IDailyAffiliations {
|
||||
Scoops: IEquipmentDatabase[];
|
||||
TrainingRetriesLeft: number;
|
||||
LoadOutPresets: ILoadOutPresets;
|
||||
CurrentLoadOutIds: Array<any[] | IOid>;
|
||||
CurrentLoadOutIds: IOid[]; // we store it in the database using this representation as well :/
|
||||
Missions: IMission[];
|
||||
RandomUpgradesIdentified?: number;
|
||||
LastRegionPlayed: TSolarMapRegion;
|
||||
@ -667,7 +667,7 @@ export interface ILibraryPersonalProgress {
|
||||
Completed: boolean;
|
||||
}
|
||||
|
||||
//this needs to be checked against ILoadoutDatabase
|
||||
// keep in sync with ILoadoutDatabase
|
||||
export interface ILoadOutPresets {
|
||||
NORMAL: ILoadoutConfigClient[];
|
||||
NORMAL_PVP: ILoadoutConfigClient[];
|
||||
@ -680,6 +680,7 @@ export interface ILoadOutPresets {
|
||||
DATAKNIFE: ILoadoutConfigClient[];
|
||||
MECH: ILoadoutConfigClient[];
|
||||
OPERATOR_ADULT: ILoadoutConfigClient[];
|
||||
DRIFTER: ILoadoutConfigClient[];
|
||||
}
|
||||
|
||||
export enum FocusSchool {
|
||||
|
@ -54,18 +54,19 @@ export interface IConfigEntry {
|
||||
|
||||
export interface ILoadoutClient extends Omit<ILoadoutDatabase, "_id" | "loadoutOwnerId"> {}
|
||||
|
||||
// keep in sync with ILoadOutPresets
|
||||
export interface ILoadoutDatabase {
|
||||
NORMAL: ILoadoutEntry;
|
||||
SENTINEL: ILoadoutEntry;
|
||||
ARCHWING: ILoadoutEntry;
|
||||
NORMAL_PVP: ILoadoutEntry;
|
||||
LUNARO: ILoadoutEntry;
|
||||
OPERATOR: ILoadoutEntry;
|
||||
KDRIVE: ILoadoutEntry;
|
||||
DATAKNIFE: ILoadoutEntry;
|
||||
MECH: ILoadoutEntry;
|
||||
OPERATOR_ADULT: ILoadoutEntry;
|
||||
DRIFTER: ILoadoutEntry;
|
||||
NORMAL: ILoadoutConfigDatabase[];
|
||||
SENTINEL: ILoadoutConfigDatabase[];
|
||||
ARCHWING: ILoadoutConfigDatabase[];
|
||||
NORMAL_PVP: ILoadoutConfigDatabase[];
|
||||
LUNARO: ILoadoutConfigDatabase[];
|
||||
OPERATOR: ILoadoutConfigDatabase[];
|
||||
KDRIVE: ILoadoutConfigDatabase[];
|
||||
DATAKNIFE: ILoadoutConfigDatabase[];
|
||||
MECH: ILoadoutConfigDatabase[];
|
||||
OPERATOR_ADULT: ILoadoutConfigDatabase[];
|
||||
DRIFTER: ILoadoutConfigDatabase[];
|
||||
_id: Types.ObjectId;
|
||||
loadoutOwnerId: Types.ObjectId;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user