feat: format run response
This commit is contained in:
@@ -303,7 +303,7 @@ router.get("/robots/:id/runs", requireAPIKey, async (req: Request, res: Response
|
|||||||
messageCode: "success",
|
messageCode: "success",
|
||||||
runs: {
|
runs: {
|
||||||
totalCount: runs.length,
|
totalCount: runs.length,
|
||||||
items: runs,
|
items: formatRunResponse(runs),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -319,6 +319,32 @@ router.get("/robots/:id/runs", requireAPIKey, async (req: Request, res: Response
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
function formatRunResponse(run: any) {
|
||||||
|
const formattedRun = {
|
||||||
|
id: run.id,
|
||||||
|
status: run.status,
|
||||||
|
name: run.name,
|
||||||
|
robotId: run.robotMetaId, // Renaming robotMetaId to robotId
|
||||||
|
startedAt: run.startedAt,
|
||||||
|
finishedAt: run.finishedAt,
|
||||||
|
runId: run.runId,
|
||||||
|
runByUserId: run.runByUserId,
|
||||||
|
runByScheduleId: run.runByScheduleId,
|
||||||
|
runByAPI: run.runByAPI,
|
||||||
|
data: {},
|
||||||
|
screenshot: null,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (run.serializableOutput && run.serializableOutput['item-0']) {
|
||||||
|
formattedRun.data = run.serializableOutput['item-0'];
|
||||||
|
} else if (run.binaryOutput && run.binaryOutput['item-0']) {
|
||||||
|
formattedRun.screenshot = run.binaryOutput['item-0'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return formattedRun;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @swagger
|
* @swagger
|
||||||
* /api/robots/{id}/runs/{runId}:
|
* /api/robots/{id}/runs/{runId}:
|
||||||
@@ -393,7 +419,7 @@ router.get("/robots/:id/runs/:runId", requireAPIKey, async (req: Request, res: R
|
|||||||
const response = {
|
const response = {
|
||||||
statusCode: 200,
|
statusCode: 200,
|
||||||
messageCode: "success",
|
messageCode: "success",
|
||||||
run: run,
|
run: formatRunResponse(run),
|
||||||
};
|
};
|
||||||
|
|
||||||
res.status(200).json(response);
|
res.status(200).json(response);
|
||||||
@@ -754,7 +780,7 @@ router.post("/robots/:id/runs", requireAPIKey, async (req: AuthenticatedRequest,
|
|||||||
const response = {
|
const response = {
|
||||||
statusCode: 200,
|
statusCode: 200,
|
||||||
messageCode: "success",
|
messageCode: "success",
|
||||||
run: completedRun,
|
run: formatRunResponse(completedRun),
|
||||||
};
|
};
|
||||||
|
|
||||||
res.status(200).json(response);
|
res.status(200).json(response);
|
||||||
|
|||||||
Reference in New Issue
Block a user