2025-08-25 13:37:14 -07:00
|
|
|
import { getJSONfromString } from "../../helpers/stringHelpers.ts";
|
|
|
|
|
import { getInventory } from "../../services/inventoryService.ts";
|
|
|
|
|
import { getAccountIdForRequest } from "../../services/loginService.ts";
|
2025-08-24 21:41:20 -07:00
|
|
|
import type { RequestHandler } from "express";
|
2025-06-07 16:45:50 -07:00
|
|
|
|
|
|
|
|
export const adoptPetController: RequestHandler = async (req, res) => {
|
|
|
|
|
const accountId = await getAccountIdForRequest(req);
|
|
|
|
|
const inventory = await getInventory(accountId, "KubrowPets");
|
|
|
|
|
const data = getJSONfromString<IAdoptPetRequest>(String(req.body));
|
|
|
|
|
const details = inventory.KubrowPets.id(data.petId)!.Details!;
|
|
|
|
|
details.Name = data.name;
|
|
|
|
|
await inventory.save();
|
|
|
|
|
res.json({
|
|
|
|
|
petId: data.petId,
|
|
|
|
|
newName: data.name
|
|
|
|
|
} satisfies IAdoptPetResponse);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
interface IAdoptPetRequest {
|
|
|
|
|
petId: string;
|
|
|
|
|
name: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface IAdoptPetResponse {
|
|
|
|
|
petId: string;
|
|
|
|
|
newName: string;
|
|
|
|
|
}
|