I am sending query parameters when doing a POST request. I have tried using req.query.mmCode it keeps returning undefined on the server side.
app.js
app.post("/api/risk/:id", (req, res) => {
// Create a new note and pass the req.body to the entry
var mmCode = req.query.mmCode;
console.log(mmCode);
service.ts
addRisk(params: HttpParams, id: string) {
console.log(params);
this.http
.post("http://localhost:3000/api/risk/" + id, { params })
.subscribe(responseData => {
console.log(responseData);
// this.vehicles.push(vehicle);
// this.vehicleUpdate.next([...this.vehicles]);
});
}
add.component.ts
onAddVehicle(form: NgForm) {
this.params = null;
if (form.invalid) {
return;
}
this.isLoading = true;
const vehicle: Vehicle = { id: null, mmCode: form.value.mmCode, vehicleType: form.value.vehicleType,
make: form.value.make, model: form.value.model, regYear: form.value.regYear};
this.http.post<{ message: string, vehicle: Vehicle }>("http://localhost:3000/api/vehicles", vehicle)
.subscribe((responseData) =>{
this.addVehicle = responseData;
this.addMMCode = this.addVehicle.vehicle.mmCode;
this.vehicleID = this.addVehicle.vehicle._id;
this.params = new HttpParams()
.set('mmCode', this.addMMCode);
console.log('CODE ' + this.addMMCode);
this.vehicleService.addRisk(this.params, this.vehicleID);
this.isLoading = false;
form.resetForm();
}