Source

frontend/src/api/routes/robots/robots.js

  1. /**
  2. * @category Frontend
  3. * @module
  4. */
  5. /**
  6. * @description Triggers parsing of the ssot to .robot file
  7. * @returns {String} .robot file code
  8. */
  9. const getParsedRobotFile = async (robotId) =>
  10. fetch(`/robots/${robotId}/robotCode`);
  11. /**
  12. * @description Fetch the ssot correlating to the specified Id
  13. * @param {String} robotId Id of the robot that will be retrieved
  14. * @returns {Object} Found ssot
  15. */
  16. const getSsot = async (robotId) => {
  17. const requestString = `/robots/${robotId}`;
  18. const response = await fetch(requestString);
  19. return response;
  20. };
  21. /**
  22. * @description Rename the robot in the ssot
  23. * @param {String} robotId RobotId of the robot that will be renamed
  24. * @param {String} newRobotName String with the new RobotName
  25. * @returns {Object} Object containing robotName and starterId
  26. */
  27. const changeSsotName = async (robotId, newRobotName) => {
  28. const payload = {
  29. newRobotName,
  30. };
  31. const requestString = `/robots/${robotId}/robotName`;
  32. const requestParams = {
  33. body: JSON.stringify(payload),
  34. method: 'PATCH',
  35. headers: {
  36. 'Content-Type': 'application/json;charset=utf-8',
  37. },
  38. };
  39. const response = await fetch(requestString, requestParams);
  40. return response;
  41. };
  42. /**
  43. * @description Delete a robot by sending a call to the backend
  44. * @param {String} robotId Id of the robot that will be deleted
  45. * @returns {Object} Mongoose query describing execution of call
  46. */
  47. const deleteRobotFromDB = async (robotId) => {
  48. const requestStringParameters = `/robots/${robotId}`;
  49. await fetch(requestStringParameters, { method: 'DELETE' }).catch((err) => {
  50. console.error(err);
  51. });
  52. };
  53. /**
  54. * @description Overwrites an existing sssot in the backend with a new one
  55. * @param {String} robotId Id of the robot that will be overwritten
  56. * @param {String} ssot New ssot that will be written to the database
  57. * @returns {Object} Updated ssot object
  58. */
  59. const updateRobot = async (robotId, ssot) => {
  60. const requestStringSsot = `/robots/${robotId}`;
  61. const response = await fetch(requestStringSsot, {
  62. body: ssot,
  63. method: 'PUT',
  64. headers: {
  65. 'Content-Type': 'application/json;charset=utf-8',
  66. },
  67. });
  68. return response;
  69. };
  70. export {
  71. getParsedRobotFile,
  72. getSsot,
  73. changeSsotName,
  74. deleteRobotFromDB,
  75. updateRobot,
  76. };