import { Request, Response } from "express"; import { Server } from "socket.io"; import { setRobotMoving } from "../simulation/robotMovementSimulator.js"; import { ErrorResponse } from "../types/error"; import { SimulationResponse } from "../types/robot"; async function moveRobot(req: Request, res: Response) { const io: Server = req.app.get("io"); const robotId = Number(req.params.id); if (!robotId || Number.isNaN(robotId)) { return res.status(400).json({ message: "Invalid robot ID." }); } try { const result: SimulationResponse = await setRobotMoving(io, robotId); return res.status(200).json(result); } catch (error) { console.error(`Error on trying to start robot ID ${robotId}: `, error); const errorResponse: ErrorResponse = { message: `Internal server error on trying to start robot ID ${robotId}.`, error, }; return res.status(500).json(errorResponse); } } export default moveRobot;