forked from OpenWF/SpaceNinjaServer
fix(webui): properly handle renaming of pets (#2204)
Reviewed-on: OpenWF/SpaceNinjaServer#2204 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
This commit is contained in:
parent
4ca4990f89
commit
d78ca91d6c
@ -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,6 +1509,18 @@ function sendBatchGearExp(data) {
|
||||
|
||||
function renameGear(category, oid, name) {
|
||||
revalidateAuthz(() => {
|
||||
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",
|
||||
@ -1515,6 +1530,7 @@ function renameGear(category, oid, name) {
|
||||
}).done(function () {
|
||||
updateInventory();
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user