From eec38e1c70894ea8164008b37e81324a1d27b7a3 Mon Sep 17 00:00:00 2001 From: dan-du-car <62157949+dan-du-car@users.noreply.github.com> Date: Tue, 9 Apr 2024 12:03:38 -0400 Subject: [PATCH] Web server: Fix the issue with topic request url changed (#201) init --- .../client/src/api/user-topic-request.js | 84 ++++++++++++------- 1 file changed, 55 insertions(+), 29 deletions(-) diff --git a/telematic_system/telematic_apps/web_app/client/src/api/user-topic-request.js b/telematic_system/telematic_apps/web_app/client/src/api/user-topic-request.js index eae380b5..aabda5eb 100644 --- a/telematic_system/telematic_apps/web_app/client/src/api/user-topic-request.js +++ b/telematic_system/telematic_apps/web_app/client/src/api/user-topic-request.js @@ -7,28 +7,37 @@ import { constructError } from './api-utils'; * @Param The list of events and units combinations * @Return Response status and save a bulk of topics for each event and unit combination */ -const upsertUserTopicRequestForEventUnits = async (seletedUnitsTopics, user_id) => { - const URL = `${env.REACT_APP_WEB_SERVER_URI}/api/user-topic-request/upsert` +const upsertUserTopicRequestForEventUnits = async ( + seletedUnitsTopics, + user_id +) => { + const URL = `${env.REACT_APP_WEB_SERVER_URI}/api/user_topic_request/upsert`; let event_id = 0; let unit_identifiers = []; - seletedUnitsTopics.forEach(element => { + seletedUnitsTopics.forEach((element) => { event_id = element.event_id; unit_identifiers.push(element.unit_identifier); }); - if (unit_identifiers.length === 0 || event_id === 0 || event_id === undefined) { + if ( + unit_identifiers.length === 0 || + event_id === 0 || + event_id === undefined + ) { return { errCode: "404", errMsg: "Event id or units cannot be empty" }; } try { - const { data } = await axios.post(URL, { unitsTopics: seletedUnitsTopics, user_id: user_id }, { withCredentials: true }); + const { data } = await axios.post( + URL, + { unitsTopics: seletedUnitsTopics, user_id: user_id }, + { withCredentials: true } + ); return data; } catch (err) { - - return constructError(err) - + return constructError(err); } -} +}; /** *@brief Load or find the user topic request for the given event and list of units @@ -37,10 +46,21 @@ const upsertUserTopicRequestForEventUnits = async (seletedUnitsTopics, user_id) * @Params selectedUnitIdentifiers: A list of unit identifiers. Each unit identifier is a string and is used to uniquely identify each unit. * @Return Response status and load a bulk of topics for each event and list of units for the event */ -const findUsersTopicRequestByEventUnits = async (event_id, selectedUnitIdentifiers, exclude_user_id) => { - const URL = `${env.REACT_APP_WEB_SERVER_URI}/api/user-topic-request/all` - if (selectedUnitIdentifiers.length === 0 || event_id === 0 || event_id === undefined) { - return { errCode: CanceledError.ERR_BAD_REQUEST, errMsg: "Event id or units cannot be empty" }; +const findUsersTopicRequestByEventUnits = async ( + event_id, + selectedUnitIdentifiers, + exclude_user_id +) => { + const URL = `${env.REACT_APP_WEB_SERVER_URI}/api/user_topic_request/all`; + if ( + selectedUnitIdentifiers.length === 0 || + event_id === 0 || + event_id === undefined + ) { + return { + errCode: CanceledError.ERR_BAD_REQUEST, + errMsg: "Event id or units cannot be empty", + }; } try { @@ -51,15 +71,12 @@ const findUsersTopicRequestByEventUnits = async (event_id, selectedUnitIdentifie exclude_user_id: exclude_user_id, unit_identifiers: selectedUnitIdentifiers, }, - },); + }); return data; } catch (err) { - - return constructError(err) - + return constructError(err); } -} - +}; /** *@brief Load or find the user topic request for the given event and list of units @@ -67,10 +84,21 @@ const findUsersTopicRequestByEventUnits = async (event_id, selectedUnitIdentifie * @Params selectedUnitIdentifiers: A list of unit identifiers. Each unit identifier is a string and is used to uniquely identify each unit. * @Return Response status and load a bulk of topics for each event and list of units for the event */ - const findUserTopicRequestByUserEventUnits = async (event_id, selectedUnitIdentifiers, user_id) => { - const URL = `${env.REACT_APP_WEB_SERVER_URI}/api/user-topic-request/user/list` - if (selectedUnitIdentifiers.length === 0 || event_id === 0 || event_id === undefined) { - return { errCode: CanceledError.ERR_BAD_REQUEST, errMsg: "Event id or units cannot be empty" }; +const findUserTopicRequestByUserEventUnits = async ( + event_id, + selectedUnitIdentifiers, + user_id +) => { + const URL = `${env.REACT_APP_WEB_SERVER_URI}/api/user_topic_request/user/list`; + if ( + selectedUnitIdentifiers.length === 0 || + event_id === 0 || + event_id === undefined + ) { + return { + errCode: CanceledError.ERR_BAD_REQUEST, + errMsg: "Event id or units cannot be empty", + }; } try { @@ -79,15 +107,13 @@ const findUsersTopicRequestByEventUnits = async (event_id, selectedUnitIdentifie params: { event_id: event_id, unit_identifiers: selectedUnitIdentifiers, - user_id: user_id + user_id: user_id, }, - },); + }); return data; } catch (err) { - - return constructError(err) - + return constructError(err); } -} +}; export { upsertUserTopicRequestForEventUnits,findUserTopicRequestByUserEventUnits, findUsersTopicRequestByEventUnits, }