I am looking to arrange the output from the flower library (/api/tasks) into a list of objects. The current response includes multiple objects, but lacks a "list wrapper", making it difficult to iterate over. API:
An example of the return is as follows:
HTTP/1.1 200 OK
Content-Length: 1109
Content-Type: application/json; charset=UTF-8
Etag: "b2478118015c8b825f7b88ce6b660e5449746c37"
Server: TornadoServer/3.1.1
{
"e42ceb2d-8730-47b5-8b4d-8e0d2a1ef7c9": {
"args": "[3, 4]",
"client": null,
...
}
}
Any suggestions on how to achieve this? I have attempted the following:
export interface Tasks {
tasks: TaskWrapper[]
}
export interface TaskWrapper {
[uuid: string]: Task
}
export interface Task {
uuid: string,
state: string,
received: string,
}
However, implementing Dragan's example leads to an issue:
loadAllTasksFromFlower(): Observable<Task[]> {
return this.http.get<Task[]>("localhost:5566/api/tasks")
.pipe(map(response => Object.entries(response)
.map(entry => ({ uuid: entry[0], state: entry[1].state, received: entry[1].received }))
}
TS2322: Type 'Observable<{ uuid: string; state: TaskState; received: any; }[]>' is not assignable to type 'Observable<Task[]>'. Type '{ uuid: string; state: TaskState; received: any; }[]' is not assignable to type 'Task[]'. Type '{ uuid: string; state: TaskState; received: any; }' is missing the following properties from type 'Task': type, source, invoke, callback, and 3 more.