Service Inquiry
public submitBooking(createBooking: CreateBooking) {
const body = this.constructRequestBody(createBooking);
return this.httpClient.post(this.baseUrl + 'Save', body )
.subscribe();
}
private constructRequestBody(createBooking: CreateBooking): any {
const body = {
'Booking': {
'Header': this.prepareHeaderInfo(createBooking),
'Items': [this.generateBookingItems(createBooking)],
},
'TestOnly': !environment.production,
};
this.Logger.log(body);
return body;
}
private generateBookingItems(createBooking: CreateBooking): any {
const bookingItem = {
'CountryOfOrigin': createBooking.booking.countryoforigin,
'VehicleValue': createBooking.booking.valueofvechicle,
'SerialNumber': createBooking.booking.bookingNumber,
'Description': createBooking.booking.description,
'Mobility': createBooking.booking.mobility,
'Currency': createBooking.booking.currency,
'Weight': createBooking.booking.weight,
'Year': createBooking.booking.year,
'Cbm': createBooking.booking.cbm,
//Encountering issue with the SubUnits array.
'SubUnits':[
createBooking.booking.relatedVehicles.forEach(element => {
const units = {
'RelationType': element.relation,
'Weight': element.weight,
'Year': element.year,
};
})],
};
return bookingItem;
The
SubUnits
array is always empty in the request sent to WEB API. How can I iterate through the array and create objects for the request body.
Note: The structure of my angular model differs from the objects expected by the WEB-API.
I attempted using JSON.Stringify(unitsArray)
without success for SubUnits
const unitsArray = [];
createBooking.booking.relatedVehicles.forEach(element => {
const units = {
'RelationType': element.relation,
'SerialNumber': element.chassisno,
'Weight': element.weight,
'Year': element.year,
};
unitsArray.push(units);
});
SubUnits : JSON.stringify(unitsArray); // This approach also did not resolve the issue with the API.
Version Info: Angular 5 Typescript 2.4.2