summaryrefslogtreecommitdiff
path: root/backend/src/controllers/stopRobot.ts
blob: af9832997f82d610176987b3efbb196f8bb863a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { Request, Response } from "express";
import { setRobotIdle } from "../simulation/robotMovementSimulator.js";
import { ErrorResponse } from "../types/error";
import { SimulationResponse } from "../types/robot";

async function stopRobot(req: Request, res: Response) {
    const robotId = Number(req.params.id);

    if (!robotId || Number.isNaN(robotId)) {
        return res.status(400).json({ message: "Ungültige Roboter ID." });
    }

    try {
        const result: SimulationResponse = await setRobotIdle(robotId);
        return res.status(200).json(result);
    } catch (error) {
        console.error(`Error on trying to stop robot ID ${robotId}: `, error);

        const errorResponse: ErrorResponse = {
            message: `Internal server error on trying to stop robot ID ${robotId}.`,
            error,
        };
        return res.status(500).json(errorResponse);
    }
}

export default stopRobot;