SpaceNinjaServer/src/controllers/api/renamePetController.ts
Sainan d78ca91d6c
All checks were successful
Build / build (push) Successful in 56s
Build Docker image / docker (push) Successful in 4m26s
fix(webui): properly handle renaming of pets (#2204)
Reviewed-on: #2204
Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com>
Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
2025-06-19 04:23:33 -07:00

31 lines
1.0 KiB
TypeScript

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) => {
const accountId = await getAccountIdForRequest(req);
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 inventoryChanges: IInventoryChanges = {};
if (!("webui" in req.query)) {
updateCurrency(inventory, 15, true, inventoryChanges);
}
await inventory.save();
res.json({
...data,
inventoryChanges: inventoryChanges
});
};
interface IRenamePetRequest {
petId: string;
name: string;
}