modif test erreur suppression VMs

This commit is contained in:
corenthin-lebreton 2025-12-02 21:30:39 +01:00
parent be23cf5891
commit c99c1809c4

View File

@ -123,14 +123,22 @@ export const destroyFormation = async (req: Request, res: Response): Promise<voi
try {
const { formationId } = req.params;
await terraformService.destroyFormation(formationId);
const formation = await prisma.terraform_formations.findUnique({
where: { formation_id: formationId }
});
res.status(204).send();
} catch (error: any) {
if (error.message === 'Formation not found') {
if (!formation) {
res.status(404).json({ message: 'Formation not found' });
return;
}
// Run in background
terraformService.destroyFormation(formationId).catch(err => {
logger.error(`Background destroy failed for ${formationId}: ${err}`);
});
res.status(202).json({ message: 'Formation destruction queued' });
} catch (error: any) {
logger.error(`Destroy formation error: ${error}`);
res.status(500).json({ message: 'Internal server error' });
}