fix(webui): properly handle renaming of pets #2204
@ -1,6 +1,7 @@
 | 
			
		||||
import { getJSONfromString } from "@/src/helpers/stringHelpers";
 | 
			
		||||
import { getInventory, updateCurrency } from "@/src/services/inventoryService";
 | 
			
		||||
import { getAccountIdForRequest } from "@/src/services/loginService";
 | 
			
		||||
import { IInventoryChanges } from "@/src/types/purchaseTypes";
 | 
			
		||||
import { RequestHandler } from "express";
 | 
			
		||||
 | 
			
		||||
export const renamePetController: RequestHandler = async (req, res) => {
 | 
			
		||||
@ -8,12 +9,18 @@ export const renamePetController: RequestHandler = async (req, res) => {
 | 
			
		||||
    const inventory = await getInventory(accountId, "KubrowPets PremiumCredits PremiumCreditsFree");
 | 
			
		||||
    const data = getJSONfromString<IRenamePetRequest>(String(req.body));
 | 
			
		||||
    const details = inventory.KubrowPets.id(data.petId)!.Details!;
 | 
			
		||||
 | 
			
		||||
    details.Name = data.name;
 | 
			
		||||
    const currencyChanges = updateCurrency(inventory, 15, true);
 | 
			
		||||
 | 
			
		||||
    const inventoryChanges: IInventoryChanges = {};
 | 
			
		||||
    if (!("webui" in req.query)) {
 | 
			
		||||
        updateCurrency(inventory, 15, true, inventoryChanges);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    await inventory.save();
 | 
			
		||||
    res.json({
 | 
			
		||||
        ...data,
 | 
			
		||||
        inventoryChanges: currencyChanges
 | 
			
		||||
        inventoryChanges: inventoryChanges
 | 
			
		||||
    });
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -546,6 +546,9 @@ function updateInventory() {
 | 
			
		||||
                                td.textContent = item.ItemName + " (" + td.textContent + ")";
 | 
			
		||||
                            }
 | 
			
		||||
                        }
 | 
			
		||||
                        if (item.Details?.Name) {
 | 
			
		||||
                            td.textContent = item.Details.Name + " (" + td.textContent + ")";
 | 
			
		||||
                        }
 | 
			
		||||
                        if (item.ModularParts && item.ModularParts.length) {
 | 
			
		||||
                            td.textContent += " [";
 | 
			
		||||
                            item.ModularParts.forEach(part => {
 | 
			
		||||
@ -1506,15 +1509,28 @@ function sendBatchGearExp(data) {
 | 
			
		||||
 | 
			
		||||
function renameGear(category, oid, name) {
 | 
			
		||||
    revalidateAuthz(() => {
 | 
			
		||||
        $.post({
 | 
			
		||||
            url: "/api/nameWeapon.php?" + window.authz + "&Category=" + category + "&ItemId=" + oid + "&webui=1",
 | 
			
		||||
            contentType: "text/plain",
 | 
			
		||||
            data: JSON.stringify({
 | 
			
		||||
                ItemName: name
 | 
			
		||||
            })
 | 
			
		||||
        }).done(function () {
 | 
			
		||||
            updateInventory();
 | 
			
		||||
        });
 | 
			
		||||
        if (category == "KubrowPets") {
 | 
			
		||||
            $.post({
 | 
			
		||||
                url: "/api/renamePet.php?" + window.authz + "&webui=1",
 | 
			
		||||
                contentType: "text/plain",
 | 
			
		||||
                data: JSON.stringify({
 | 
			
		||||
                    petId: oid,
 | 
			
		||||
                    name: name
 | 
			
		||||
                })
 | 
			
		||||
            }).done(function () {
 | 
			
		||||
                updateInventory();
 | 
			
		||||
            });
 | 
			
		||||
        } else {
 | 
			
		||||
            $.post({
 | 
			
		||||
                url: "/api/nameWeapon.php?" + window.authz + "&Category=" + category + "&ItemId=" + oid + "&webui=1",
 | 
			
		||||
                contentType: "text/plain",
 | 
			
		||||
                data: JSON.stringify({
 | 
			
		||||
                    ItemName: name
 | 
			
		||||
                })
 | 
			
		||||
            }).done(function () {
 | 
			
		||||
                updateInventory();
 | 
			
		||||
            });
 | 
			
		||||
        }
 | 
			
		||||
    });
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user