I need to transform a JSON response to a typescript array which has different a different schema
method to get the json response
getCalendarShipments(params?: HttpParams): Observable<Shipment[]> {
return this.http.get<Shipment[]>(this.baseUrl + 'shipments', {params});
}
Current method to map the response:
events: CalendarEvent[] = [];
this.customerService.getCalendarShipments(this.httpParams)
.pipe(map((result: Shipment[]) => result.forEach(e => {
this.events = [{
start: new Date(e.appointmentTime),
end: new Date(e.appointmentTime),
title: e.container
}, ];
}))).subscribe();
In the above code, i’m using a foreach to iterate over the array and trying to add a new object with the relevant data to the typescript array, but to no luck. I have also tried using the push
method to add the objects that way.
The events
array has a different schema than the Shipments
model