Skip to content

Commit

Permalink
Web server: Fix the issue with topic request url changed (#201)
Browse files Browse the repository at this point in the history
init
  • Loading branch information
dan-du-car authored Apr 9, 2024
1 parent f341dfb commit eec38e1
Showing 1 changed file with 55 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -51,26 +71,34 @@ 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
* @Params event id used to uniquely identifer each event
* @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 {
Expand All @@ -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, }

0 comments on commit eec38e1

Please sign in to comment.