Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Web server: Fix the issue with topic request url changed #201

Merged
merged 1 commit into from
Apr 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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, }
Loading