From fb070065dbaafe73608fcbb7cd8be5cb7df8955f Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Thu, 10 Oct 2024 05:47:42 +0530 Subject: [PATCH 01/12] feat: get all robots /api/robots --- server/src/api/record.ts | 8 ++++---- server/src/api/run.ts | 4 ---- 2 files changed, 4 insertions(+), 8 deletions(-) delete mode 100644 server/src/api/run.ts diff --git a/server/src/api/record.ts b/server/src/api/record.ts index b892d3c6..f06ae52f 100644 --- a/server/src/api/record.ts +++ b/server/src/api/record.ts @@ -1,6 +1,7 @@ import { readFile, readFiles } from "../workflow-management/storage"; import { Router, Request, Response } from 'express'; import { requireAPIKey } from "../middlewares/api"; +import Robot from "../models/Robot"; const router = Router(); const formatRecording = (recordingData: any) => { @@ -29,11 +30,10 @@ const formatRecording = (recordingData: any) => { router.get("/robots", requireAPIKey, async (req: Request, res: Response) => { try { - const fileContents = await readFiles('./../storage/recordings/'); + const recordings = await Robot.findAll(); - const formattedRecordings = fileContents.map((fileContent: string) => { - const recordingData = JSON.parse(fileContent); - return formatRecording(recordingData); + const formattedRecordings = recordings.map((recording: any) => { + return formatRecording(recording); }); const response = { diff --git a/server/src/api/run.ts b/server/src/api/run.ts deleted file mode 100644 index ea419e49..00000000 --- a/server/src/api/run.ts +++ /dev/null @@ -1,4 +0,0 @@ -import { readFile, readFiles } from "../workflow-management/storage"; -import { Router, Request, Response } from 'express'; -import { requireAPIKey } from "../middlewares/api"; -const router = Router(); \ No newline at end of file From 974c6971bfb6a8d8dacc12ed4bd0ea7292899cd4 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Thu, 10 Oct 2024 05:57:49 +0530 Subject: [PATCH 02/12] fix: map over robots --- server/src/api/record.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/server/src/api/record.ts b/server/src/api/record.ts index f06ae52f..a69b1de3 100644 --- a/server/src/api/record.ts +++ b/server/src/api/record.ts @@ -30,11 +30,8 @@ const formatRecording = (recordingData: any) => { router.get("/robots", requireAPIKey, async (req: Request, res: Response) => { try { - const recordings = await Robot.findAll(); - - const formattedRecordings = recordings.map((recording: any) => { - return formatRecording(recording); - }); + const robots = await Robot.findAll(); + const formattedRecordings = robots.map(formatRecording); const response = { statusCode: 200, From ef4146358a01b2c0101ef47feb96bf2a597ea278 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Thu, 10 Oct 2024 06:03:44 +0530 Subject: [PATCH 03/12] feat: set raw to true --- server/src/api/record.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/api/record.ts b/server/src/api/record.ts index a69b1de3..11a10dc0 100644 --- a/server/src/api/record.ts +++ b/server/src/api/record.ts @@ -30,7 +30,7 @@ const formatRecording = (recordingData: any) => { router.get("/robots", requireAPIKey, async (req: Request, res: Response) => { try { - const robots = await Robot.findAll(); + const robots = await Robot.findAll({ raw: true}); const formattedRecordings = robots.map(formatRecording); const response = { From 0c3480324409bcf03fe2bb2b95950b49ee171a2f Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Thu, 10 Oct 2024 06:03:56 +0530 Subject: [PATCH 04/12] chore: lint --- server/src/api/record.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/api/record.ts b/server/src/api/record.ts index 11a10dc0..321e2275 100644 --- a/server/src/api/record.ts +++ b/server/src/api/record.ts @@ -30,7 +30,7 @@ const formatRecording = (recordingData: any) => { router.get("/robots", requireAPIKey, async (req: Request, res: Response) => { try { - const robots = await Robot.findAll({ raw: true}); + const robots = await Robot.findAll({ raw: true }); const formattedRecordings = robots.map(formatRecording); const response = { From d5629703174a1f70b5ec64a8eaf26143f0ab108c Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Thu, 10 Oct 2024 06:08:11 +0530 Subject: [PATCH 05/12] feat: get robot by id /api/robots/id --- server/src/api/record.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/server/src/api/record.ts b/server/src/api/record.ts index 321e2275..fc7c0706 100644 --- a/server/src/api/record.ts +++ b/server/src/api/record.ts @@ -77,12 +77,16 @@ const formatRecordingById = (recordingData: any) => { }; }; -router.get("/robots/:fileName", requireAPIKey, async (req: Request, res: Response) => { +router.get("/robots/:id", requireAPIKey, async (req: Request, res: Response) => { try { - const fileContent = await readFile(`./../storage/recordings/${req.params.fileName}.waw.json`); + const robot = await Robot.findOne({ + where: { + 'recording_meta.id': req.params.id + }, + raw: true + }); - const recordingData = JSON.parse(fileContent); - const formattedRecording = formatRecordingById(recordingData); + const formattedRecording = formatRecordingById(robot); const response = { statusCode: 200, From 4d7aee267ab267a2393290714794d6dd9cc149eb Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Thu, 10 Oct 2024 06:08:26 +0530 Subject: [PATCH 06/12] chore: lint --- server/src/api/record.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/src/api/record.ts b/server/src/api/record.ts index fc7c0706..34dff609 100644 --- a/server/src/api/record.ts +++ b/server/src/api/record.ts @@ -81,10 +81,10 @@ router.get("/robots/:id", requireAPIKey, async (req: Request, res: Response) => try { const robot = await Robot.findOne({ where: { - 'recording_meta.id': req.params.id + 'recording_meta.id': req.params.id }, raw: true - }); + }); const formattedRecording = formatRecordingById(robot); From b712cda36ef7f4b9a06085550aeeb8b88a62417e Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Thu, 10 Oct 2024 06:13:17 +0530 Subject: [PATCH 07/12] feat: get all runs by a robot /api/robots/robotId/runs --- server/src/api/record.ts | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/server/src/api/record.ts b/server/src/api/record.ts index 34dff609..4200d3e6 100644 --- a/server/src/api/record.ts +++ b/server/src/api/record.ts @@ -2,6 +2,7 @@ import { readFile, readFiles } from "../workflow-management/storage"; import { Router, Request, Response } from 'express'; import { requireAPIKey } from "../middlewares/api"; import Robot from "../models/Robot"; +import Run from "../models/Run"; const router = Router(); const formatRecording = (recordingData: any) => { @@ -105,4 +106,34 @@ router.get("/robots/:id", requireAPIKey, async (req: Request, res: Response) => } }); +router.get("/robots/:id/runs", requireAPIKey, async (req: Request, res: Response) => { + try { + const runs = await Run.findAll({ + where: { + robotId: req.params.id + }, + raw: true + }); + + const response = { + statusCode: 200, + messageCode: "success", + runs: { + totalCount: runs.length, + items: runs, + }, + }; + + res.status(200).json(response); + } catch (error) { + console.error("Error fetching runs:", error); + res.status(500).json({ + statusCode: 500, + messageCode: "error", + message: "Failed to retrieve runs", + }); + } +} +); + export default router; \ No newline at end of file From 1adb06cacb82a5b0eb9b5ca234cf8b523734db03 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Thu, 10 Oct 2024 06:15:07 +0530 Subject: [PATCH 08/12] feat: get a run /api/robots/robotId/runs/runId --- server/src/api/record.ts | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/server/src/api/record.ts b/server/src/api/record.ts index 4200d3e6..2805b3ec 100644 --- a/server/src/api/record.ts +++ b/server/src/api/record.ts @@ -136,4 +136,30 @@ router.get("/robots/:id/runs", requireAPIKey, async (req: Request, res: Response } ); +router.get("/robots/:id/runs/:runId", requireAPIKey, async (req: Request, res: Response) => { + try { + const run = await Run.findOne({ + where: { + runId: req.params.runId + }, + raw: true + }); + + const response = { + statusCode: 200, + messageCode: "success", + run: run, + }; + + res.status(200).json(response); + } catch (error) { + console.error("Error fetching run:", error); + res.status(404).json({ + statusCode: 404, + messageCode: "not_found", + message: `Run with id "${req.params.runId}" not found.`, + }); + } +}); + export default router; \ No newline at end of file From 2b6954bd5f876dc22a6db078d5a65dff3d84fcf6 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Thu, 10 Oct 2024 06:18:42 +0530 Subject: [PATCH 09/12] fix: use robotMetaId --- server/src/api/record.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/api/record.ts b/server/src/api/record.ts index 2805b3ec..22f2a8cc 100644 --- a/server/src/api/record.ts +++ b/server/src/api/record.ts @@ -110,7 +110,7 @@ router.get("/robots/:id/runs", requireAPIKey, async (req: Request, res: Response try { const runs = await Run.findAll({ where: { - robotId: req.params.id + robotMetaId: req.params.id }, raw: true }); From b6d44250c477e3b91251e25d131386e6f4406b0c Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Thu, 10 Oct 2024 06:22:53 +0530 Subject: [PATCH 10/12] feat: check robotMetaId --- server/src/api/record.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/server/src/api/record.ts b/server/src/api/record.ts index 22f2a8cc..0d3e0b68 100644 --- a/server/src/api/record.ts +++ b/server/src/api/record.ts @@ -140,7 +140,8 @@ router.get("/robots/:id/runs/:runId", requireAPIKey, async (req: Request, res: R try { const run = await Run.findOne({ where: { - runId: req.params.runId + runId: req.params.runId, + robotMetaId: req.params.id, }, raw: true }); From dbe51bde07bf668ca2b3fe6490a70e60c1933143 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Thu, 10 Oct 2024 06:24:04 +0530 Subject: [PATCH 11/12] feat: detailed error message --- server/src/api/record.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/src/api/record.ts b/server/src/api/record.ts index 0d3e0b68..dc00781c 100644 --- a/server/src/api/record.ts +++ b/server/src/api/record.ts @@ -145,7 +145,7 @@ router.get("/robots/:id/runs/:runId", requireAPIKey, async (req: Request, res: R }, raw: true }); - + const response = { statusCode: 200, messageCode: "success", @@ -158,7 +158,7 @@ router.get("/robots/:id/runs/:runId", requireAPIKey, async (req: Request, res: R res.status(404).json({ statusCode: 404, messageCode: "not_found", - message: `Run with id "${req.params.runId}" not found.`, + message: `Run with id "${req.params.runId}" for robot with id "${req.params.id}" not found.`, }); } }); From e8747f2074e5c5d60956474ee6e39e03d1fc5a4c Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Thu, 10 Oct 2024 06:26:34 +0530 Subject: [PATCH 12/12] chore: todo --- server/src/api/record.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/server/src/api/record.ts b/server/src/api/record.ts index dc00781c..bd5e2f74 100644 --- a/server/src/api/record.ts +++ b/server/src/api/record.ts @@ -106,6 +106,7 @@ router.get("/robots/:id", requireAPIKey, async (req: Request, res: Response) => } }); +// TODO: Format runs to send more data formatted router.get("/robots/:id/runs", requireAPIKey, async (req: Request, res: Response) => { try { const runs = await Run.findAll({