chore(webui): use gildWeaponController
also use `TEquipmentKey` instead `WeaponTypeInternal | "Hoverboards"` Closes #1517
This commit is contained in:
		
							parent
							
								
									327b834b07
								
							
						
					
					
						commit
						631dc0a677
					
				@ -2,36 +2,25 @@ import { RequestHandler } from "express";
 | 
				
			|||||||
import { getAccountIdForRequest } from "@/src/services/loginService";
 | 
					import { getAccountIdForRequest } from "@/src/services/loginService";
 | 
				
			||||||
import { getJSONfromString } from "@/src/helpers/stringHelpers";
 | 
					import { getJSONfromString } from "@/src/helpers/stringHelpers";
 | 
				
			||||||
import { addMiscItems, getInventory } from "@/src/services/inventoryService";
 | 
					import { addMiscItems, getInventory } from "@/src/services/inventoryService";
 | 
				
			||||||
import { WeaponTypeInternal } from "@/src/services/itemDataService";
 | 
					import { TEquipmentKey } from "@/src/types/inventoryTypes/inventoryTypes";
 | 
				
			||||||
import { ArtifactPolarity, EquipmentFeatures, IEquipmentClient } from "@/src/types/inventoryTypes/commonInventoryTypes";
 | 
					import { ArtifactPolarity, EquipmentFeatures, IEquipmentClient } from "@/src/types/inventoryTypes/commonInventoryTypes";
 | 
				
			||||||
import { ExportRecipes } from "warframe-public-export-plus";
 | 
					import { ExportRecipes } from "warframe-public-export-plus";
 | 
				
			||||||
import { IInventoryChanges } from "@/src/types/purchaseTypes";
 | 
					import { IInventoryChanges } from "@/src/types/purchaseTypes";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const modularWeaponCategory: (WeaponTypeInternal | "Hoverboards")[] = [
 | 
					 | 
				
			||||||
    "LongGuns",
 | 
					 | 
				
			||||||
    "Pistols",
 | 
					 | 
				
			||||||
    "Melee",
 | 
					 | 
				
			||||||
    "OperatorAmps",
 | 
					 | 
				
			||||||
    "Hoverboards"
 | 
					 | 
				
			||||||
];
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
interface IGildWeaponRequest {
 | 
					interface IGildWeaponRequest {
 | 
				
			||||||
    ItemName: string;
 | 
					    ItemName: string;
 | 
				
			||||||
    Recipe: string; // e.g. /Lotus/Weapons/SolarisUnited/LotusGildKitgunBlueprint
 | 
					    Recipe: string; // e.g. /Lotus/Weapons/SolarisUnited/LotusGildKitgunBlueprint
 | 
				
			||||||
    PolarizeSlot?: number;
 | 
					    PolarizeSlot?: number;
 | 
				
			||||||
    PolarizeValue?: ArtifactPolarity;
 | 
					    PolarizeValue?: ArtifactPolarity;
 | 
				
			||||||
    ItemId: string;
 | 
					    ItemId: string;
 | 
				
			||||||
    Category: WeaponTypeInternal | "Hoverboards";
 | 
					    Category: TEquipmentKey;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const gildWeaponController: RequestHandler = async (req, res) => {
 | 
					export const gildWeaponController: RequestHandler = async (req, res) => {
 | 
				
			||||||
    const accountId = await getAccountIdForRequest(req);
 | 
					    const accountId = await getAccountIdForRequest(req);
 | 
				
			||||||
    const data = getJSONfromString<IGildWeaponRequest>(String(req.body));
 | 
					    const data = getJSONfromString<IGildWeaponRequest>(String(req.body));
 | 
				
			||||||
    data.ItemId = String(req.query.ItemId);
 | 
					    data.ItemId = String(req.query.ItemId);
 | 
				
			||||||
    if (!modularWeaponCategory.includes(req.query.Category as WeaponTypeInternal | "Hoverboards")) {
 | 
					    data.Category = req.query.Category as TEquipmentKey;
 | 
				
			||||||
        throw new Error(`Unknown modular weapon Category: ${String(req.query.Category)}`);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    data.Category = req.query.Category as WeaponTypeInternal | "Hoverboards";
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const inventory = await getInventory(accountId);
 | 
					    const inventory = await getInventory(accountId);
 | 
				
			||||||
    const weaponIndex = inventory[data.Category].findIndex(x => String(x._id) === data.ItemId);
 | 
					    const weaponIndex = inventory[data.Category].findIndex(x => String(x._id) === data.ItemId);
 | 
				
			||||||
@ -42,8 +31,10 @@ export const gildWeaponController: RequestHandler = async (req, res) => {
 | 
				
			|||||||
    const weapon = inventory[data.Category][weaponIndex];
 | 
					    const weapon = inventory[data.Category][weaponIndex];
 | 
				
			||||||
    weapon.Features ??= 0;
 | 
					    weapon.Features ??= 0;
 | 
				
			||||||
    weapon.Features |= EquipmentFeatures.GILDED;
 | 
					    weapon.Features |= EquipmentFeatures.GILDED;
 | 
				
			||||||
 | 
					    if (data.Recipe != "webui") {
 | 
				
			||||||
        weapon.ItemName = data.ItemName;
 | 
					        weapon.ItemName = data.ItemName;
 | 
				
			||||||
        weapon.XP = 0;
 | 
					        weapon.XP = 0;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    if (data.Category != "OperatorAmps" && data.PolarizeSlot && data.PolarizeValue) {
 | 
					    if (data.Category != "OperatorAmps" && data.PolarizeSlot && data.PolarizeValue) {
 | 
				
			||||||
        weapon.Polarity = [
 | 
					        weapon.Polarity = [
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
@ -56,6 +47,9 @@ export const gildWeaponController: RequestHandler = async (req, res) => {
 | 
				
			|||||||
    const inventoryChanges: IInventoryChanges = {};
 | 
					    const inventoryChanges: IInventoryChanges = {};
 | 
				
			||||||
    inventoryChanges[data.Category] = [weapon.toJSON<IEquipmentClient>()];
 | 
					    inventoryChanges[data.Category] = [weapon.toJSON<IEquipmentClient>()];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    const affiliationMods = [];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (data.Recipe != "webui") {
 | 
				
			||||||
        const recipe = ExportRecipes[data.Recipe];
 | 
					        const recipe = ExportRecipes[data.Recipe];
 | 
				
			||||||
        inventoryChanges.MiscItems = recipe.secretIngredients!.map(ingredient => ({
 | 
					        inventoryChanges.MiscItems = recipe.secretIngredients!.map(ingredient => ({
 | 
				
			||||||
            ItemType: ingredient.ItemType,
 | 
					            ItemType: ingredient.ItemType,
 | 
				
			||||||
@ -63,7 +57,6 @@ export const gildWeaponController: RequestHandler = async (req, res) => {
 | 
				
			|||||||
        }));
 | 
					        }));
 | 
				
			||||||
        addMiscItems(inventory, inventoryChanges.MiscItems);
 | 
					        addMiscItems(inventory, inventoryChanges.MiscItems);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const affiliationMods = [];
 | 
					 | 
				
			||||||
        if (recipe.syndicateStandingChange) {
 | 
					        if (recipe.syndicateStandingChange) {
 | 
				
			||||||
            const affiliation = inventory.Affiliations.find(x => x.Tag == recipe.syndicateStandingChange!.tag)!;
 | 
					            const affiliation = inventory.Affiliations.find(x => x.Tag == recipe.syndicateStandingChange!.tag)!;
 | 
				
			||||||
            affiliation.Standing += recipe.syndicateStandingChange.value;
 | 
					            affiliation.Standing += recipe.syndicateStandingChange.value;
 | 
				
			||||||
@ -72,6 +65,7 @@ export const gildWeaponController: RequestHandler = async (req, res) => {
 | 
				
			|||||||
                Standing: recipe.syndicateStandingChange.value
 | 
					                Standing: recipe.syndicateStandingChange.value
 | 
				
			||||||
            });
 | 
					            });
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    await inventory.save();
 | 
					    await inventory.save();
 | 
				
			||||||
    res.json({
 | 
					    res.json({
 | 
				
			||||||
 | 
				
			|||||||
@ -1,23 +0,0 @@
 | 
				
			|||||||
import { getInventory } from "@/src/services/inventoryService";
 | 
					 | 
				
			||||||
import { getAccountIdForRequest } from "@/src/services/loginService";
 | 
					 | 
				
			||||||
import { EquipmentFeatures } from "@/src/types/inventoryTypes/commonInventoryTypes";
 | 
					 | 
				
			||||||
import { TEquipmentKey } from "@/src/types/inventoryTypes/inventoryTypes";
 | 
					 | 
				
			||||||
import { RequestHandler } from "express";
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
export const gildEquipmentController: RequestHandler = async (req, res) => {
 | 
					 | 
				
			||||||
    const accountId = await getAccountIdForRequest(req);
 | 
					 | 
				
			||||||
    const request = req.body as IGildEquipmentRequest;
 | 
					 | 
				
			||||||
    const inventory = await getInventory(accountId, request.Category);
 | 
					 | 
				
			||||||
    const weapon = inventory[request.Category].id(request.ItemId);
 | 
					 | 
				
			||||||
    if (weapon) {
 | 
					 | 
				
			||||||
        weapon.Features ??= 0;
 | 
					 | 
				
			||||||
        weapon.Features |= EquipmentFeatures.GILDED;
 | 
					 | 
				
			||||||
        await inventory.save();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    res.end();
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type IGildEquipmentRequest = {
 | 
					 | 
				
			||||||
    ItemId: string;
 | 
					 | 
				
			||||||
    Category: TEquipmentKey;
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
@ -17,7 +17,6 @@ import { addCurrencyController } from "@/src/controllers/custom/addCurrencyContr
 | 
				
			|||||||
import { addItemsController } from "@/src/controllers/custom/addItemsController";
 | 
					import { addItemsController } from "@/src/controllers/custom/addItemsController";
 | 
				
			||||||
import { addModularEquipmentController } from "@/src/controllers/custom/addModularEquipmentController";
 | 
					import { addModularEquipmentController } from "@/src/controllers/custom/addModularEquipmentController";
 | 
				
			||||||
import { addXpController } from "@/src/controllers/custom/addXpController";
 | 
					import { addXpController } from "@/src/controllers/custom/addXpController";
 | 
				
			||||||
import { gildEquipmentController } from "@/src/controllers/custom/gildEquipmentController";
 | 
					 | 
				
			||||||
import { importController } from "@/src/controllers/custom/importController";
 | 
					import { importController } from "@/src/controllers/custom/importController";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import { getConfigDataController } from "@/src/controllers/custom/getConfigDataController";
 | 
					import { getConfigDataController } from "@/src/controllers/custom/getConfigDataController";
 | 
				
			||||||
@ -43,7 +42,6 @@ customRouter.post("/addCurrency", addCurrencyController);
 | 
				
			|||||||
customRouter.post("/addItems", addItemsController);
 | 
					customRouter.post("/addItems", addItemsController);
 | 
				
			||||||
customRouter.post("/addModularEquipment", addModularEquipmentController);
 | 
					customRouter.post("/addModularEquipment", addModularEquipmentController);
 | 
				
			||||||
customRouter.post("/addXp", addXpController);
 | 
					customRouter.post("/addXp", addXpController);
 | 
				
			||||||
customRouter.post("/gildEquipment", gildEquipmentController);
 | 
					 | 
				
			||||||
customRouter.post("/import", importController);
 | 
					customRouter.post("/import", importController);
 | 
				
			||||||
customRouter.post("/manageQuests", manageQuestsController);
 | 
					customRouter.post("/manageQuests", manageQuestsController);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -1127,11 +1127,10 @@ function disposeOfItems(category, type, count) {
 | 
				
			|||||||
function gildEquipment(category, oid) {
 | 
					function gildEquipment(category, oid) {
 | 
				
			||||||
    revalidateAuthz(() => {
 | 
					    revalidateAuthz(() => {
 | 
				
			||||||
        $.post({
 | 
					        $.post({
 | 
				
			||||||
            url: "/custom/gildEquipment?" + window.authz,
 | 
					            url: "/api/gildWeapon.php?" + window.authz + "&ItemId=" + oid + "&Category=" + category,
 | 
				
			||||||
            contentType: "application/json",
 | 
					            contentType: "application/octet-stream",
 | 
				
			||||||
            data: JSON.stringify({
 | 
					            data: JSON.stringify({
 | 
				
			||||||
                ItemId: oid,
 | 
					                Recipe: "webui"
 | 
				
			||||||
                Category: category
 | 
					 | 
				
			||||||
            })
 | 
					            })
 | 
				
			||||||
        }).done(function () {
 | 
					        }).done(function () {
 | 
				
			||||||
            updateInventory();
 | 
					            updateInventory();
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user