Can you provide your insight on the following:
I am receiving data from an API using this function:
getRS(
idProject: string
): Observable<ResponseModel<RSModel>> {
return this.http.get<ResponseModel<RSModel>>(
ApiUrlsConfig.getRS(
idProject
)
);
}
This is the response I receive:
{
"data": [
{
"id": "id1",
"state": 1,
"note": null
},
{
"id": "id1",
"state": 2,
"note": "Reason 1"
},
{
"id": "id2",
"state": 2,
"note": "Reason updated3",
}
],
"result": null
}
I need to apply a filter to this response in order to retrieve the latest state for each ID. For instance, I want to show state 2 for the item with ID: id1. However, I am facing difficulties while trying to use the filter function. I'm not sure why it's not working.
I attempted to implement the following code:
@Input() set jobId(jobId: string) {
this.optionsService
.getRS(
this.idProject
)
.pipe()
.subscribe((res) => {
let resId = res.filter((aaa)=>{
if(aaa.id === jobId){
res.slice(-1)[0].id
}
}
)
});
}
Unfortunately, it is not functioning as intended.
If you have any suggestions or ideas, please feel free to share them. Thank you.