Just an idea for you…regarding the fetch function on your backend…
The shown function below, gives you the following options (features)…
- It can itarate into depth of objects
- It will search for required properties (of your choice → you can define the required properties) → see code.
- It will generate a separate RESULT-OBJECT including all required properties, no matter if the PROPERTY was found or not, it will be automatically filled up if not fund (with → ‘undefined’).
So this code will generate you ALWAYS a CONSTANT → RESULT-OBJECT → NO MATTER IF GOOLE-FETCH-RESULT will have missing properties, like you mentioned.
I hope you understand what i mean. I already assumed such a behaviour of your fetched RESULTS.
Implement this code on your backend aswell → in can help you to get a more compressed and more automated code.
function fillMissingProperties(obj, requiredProperties, defaultProperties) {
let resultObj = {};
// Iterate through required properties
for (let prop of requiredProperties) {
// Check if property is missing in obj
if (!(prop in obj)) {
// Fill the missing property with default value if available
resultObj[prop] = defaultProperties[prop];
if (resultObj[prop] === undefined) {
resultObj[prop] = undefined;
}
} else {
resultObj[prop] = obj[prop];
}
}
// Recursively iterate through nested objects
for (let prop in obj) {
if (typeof obj[prop] === 'object') {
const nestedObj = fillMissingProperties(obj[prop], requiredProperties, defaultProperties);
for (let nestedProp in nestedObj) {
resultObj[nestedProp] = nestedObj[nestedProp];
}
}
}
return resultObj;
}
// Example usage:
const obj = {
person: {
name: "John",
age: 30,
address: {
city: "New York"
}
},
car: {
model: "Toyota"
}
};
const requiredProps = ['name', 'age', 'lastname']; // Define required properties
const defaultProperties = { lastname: undefined }; // Define default properties
const newObj = fillMissingProperties(obj, requiredProps, defaultProperties);
console.log(newObj);
Let’s take this example-Object…
const obj = {
person: {
name: "John",
age: 30,
address: {
city: "New York"
}
},
car: {
model: "Toyota"
}
};
Your defined required properties are…
const requiredProps = ['name', 'age', 'lastname'];
So as you can see → lastname <— is missing inside of the object.
This missing PROPERTY including → undefined ← as value → will be automatically filled up inside the NEW-GENERATED RESULT-OBJECT, which will look like…
So your result-object will be…
{
name: "John",
age: 30,
lastname: undefined,
city: "New York",
model: "Toyota"
}
The function makes sure that you always have the same structure and values inside of your object in a flattened-mode.
It will make your coding life a little bit easier 
But wait the ‘_id’ property is missing !!! —> What to do ??? 
You already have an idea?
Good luck and happy coding! Expand your horizont and overthing your code again and again, until you got a real good result.