2025-03-28 03:08:22 -07:00
|
|
|
import { getJSONfromString } from "@/src/helpers/stringHelpers";
|
|
|
|
import { getInventory } from "@/src/services/inventoryService";
|
|
|
|
import { getAccountIdForRequest } from "@/src/services/loginService";
|
2025-07-04 16:49:25 -07:00
|
|
|
import { Status } from "@/src/types/equipmentTypes";
|
2025-03-28 03:08:22 -07:00
|
|
|
import { RequestHandler } from "express";
|
|
|
|
|
|
|
|
export const retrievePetFromStasisController: RequestHandler = async (req, res) => {
|
|
|
|
const accountId = await getAccountIdForRequest(req);
|
|
|
|
const inventory = await getInventory(accountId, "KubrowPets");
|
|
|
|
const data = getJSONfromString<IRetrievePetFromStasisRequest>(String(req.body));
|
|
|
|
|
|
|
|
let oldPetId: string | undefined;
|
|
|
|
for (const pet of inventory.KubrowPets) {
|
|
|
|
if (pet.Details!.Status == Status.StatusAvailable) {
|
|
|
|
pet.Details!.Status = Status.StatusStasis;
|
|
|
|
oldPetId = pet._id.toString();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inventory.KubrowPets.id(data.petId)!.Details!.Status = Status.StatusAvailable;
|
|
|
|
|
|
|
|
await inventory.save();
|
|
|
|
res.json({
|
|
|
|
petId: data.petId,
|
|
|
|
oldPetId,
|
|
|
|
status: Status.StatusAvailable
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
interface IRetrievePetFromStasisRequest {
|
|
|
|
petId: string;
|
|
|
|
}
|