I have objects converted from JSON responses returned based on some conditions. The nodes of these 2 response objects would be same. but data would be different.How can I refactor and destructure below objects based on conditions?
if (searchType === "user") {
const { user_search, details, education, work } = result?.data;
search_data = user_search.results || [];
total = user_search.total || 0;
personalData = {
details,
education,
work,
};
}
if (searchType === "admin") {
const { admin_search, details, education, work } = result?.data;
search_data = admin_search.results || [];
total = admin_search.total || 0;
personalData = {
details,
education,
work,
};
}
const { user_search, admin_search, details, education, work } = result?.data;
const result = user_search || admin_search || [];
search_data = result.results;
total = result.total || 0;
personalData = {
details,
education,
work,
};