forked from OpenWF/SpaceNinjaServer
		
	and some initial refactoring to avoid it where possible Reviewed-on: OpenWF/SpaceNinjaServer#2407 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
		
			
				
	
	
		
			34 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			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/equipmentTypes";
 | 
						|
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;
 | 
						|
}
 |