summaryrefslogtreecommitdiff
path: root/backend/src/controllers/createRobot.ts
diff options
context:
space:
mode:
Diffstat (limited to 'backend/src/controllers/createRobot.ts')
-rw-r--r--backend/src/controllers/createRobot.ts18
1 files changed, 12 insertions, 6 deletions
diff --git a/backend/src/controllers/createRobot.ts b/backend/src/controllers/createRobot.ts
index fa483af..dbc1959 100644
--- a/backend/src/controllers/createRobot.ts
+++ b/backend/src/controllers/createRobot.ts
@@ -1,14 +1,16 @@
import { Request, Response } from "express";
import { QueryResult } from "pg";
+import { Server } from "socket.io";
import db from "../database/postgres.js";
import redisClient from "../database/redis.js";
+import { ErrorResponse } from "../types/error.js";
import { CreateRequest } from "../types/request.js";
-import { Robot } from "../types/robot.js";
+import { CreateRobotResponse, Robot } from "../types/robot.js";
const ROBOTS_CACHE_KEY = "allMyRobots";
async function createRobot(req: Request, res: Response) {
- const io = req.app.get("io");
+ const io: Server = req.app.get("io");
const { name } = req.body as CreateRequest;
@@ -44,16 +46,20 @@ async function createRobot(req: Request, res: Response) {
io.emit("robots_update", allRobots);
console.log("WebSocket update with newly created robot.");
- return res.status(201).json({
+ const createRobotResponse: CreateRobotResponse = {
message: "Robot successfully created.",
robot: newRobot,
- });
+ };
+
+ return res.status(201).json(createRobotResponse);
} catch (error) {
console.error("Error creating the robot: ", error);
- return res.status(500).json({
+
+ const errorResponse: ErrorResponse = {
message: "Internal server error during robot creation.",
error,
- });
+ };
+ return res.status(500).json(errorResponse);
}
}