SpaceNinjaServer/src/controllers/api/retrievePetFromStasisController.ts
Sainan aa7d5067bc
All checks were successful
Build / build (20) (push) Successful in 41s
Build / build (18) (push) Successful in 1m17s
Build / build (22) (push) Successful in 1m7s
Build Docker image / docker (push) Successful in 32s
feat: retrievePetFromStasis (#1354)
Closes #621

Reviewed-on: #1354
Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com>
Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
2025-03-28 03:08:22 -07:00

34 lines
1.1 KiB
TypeScript

import { getJSONfromString } from "@/src/helpers/stringHelpers";
import { getInventory } from "@/src/services/inventoryService";
import { getAccountIdForRequest } from "@/src/services/loginService";
import { Status } from "@/src/types/inventoryTypes/inventoryTypes";
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;
}