I've come across several similar posts with the same title, but none of them address my specific use case.
In my situation, I have an array of items with properties that can be ('serials','macs','null'). For each type of property, a different API endpoint needs to be called. Additionally, within the 'model' property, there is an array of models that also need to be sent individually. I understand this may not be the most efficient way to handle this, but unfortunately, I inherited this messy design and am not responsible for it.
the service code :
createDevice(data: Device) {
return this.http.post('somewhere', data, {
headers: this.httpHeader,
});
}
component code:
this.sourceDataSet.forEach(item=>{
if(item.serials){
item.serials.forEach(serial=>{
//create it
})
}
else if(item.macs){
item.macs.forEach(serial=>{
//create it
})
}
else{
// create it
}
})
The issue is that other properties may be affected by these actions, which is something I want to avoid. Is there a more elegant solution for this problem?