Hi, while I’m trying to send a post request to the server from Ionic 4 reactive form data, I’m getting a response with status code 200. But when I try to fetch the details from the server, all are null values. I don’t understand where I’m doing a mistake.
I’ve tried with stringifying the object before sending to the server as well. But the same issue. Please let me know where I’ve mistaken. Thank You.
Client-side code:
uploadSendingRules() {
const sendingRules = new SendingRules(this.sendingRulesForm.value.localSendBy,
this.sendingRulesForm.value.nationalSendBy,
this.sendingRulesForm.value.regionalSendBy,
this.sendingRulesForm.value.internationalSendBy);
this.saveSendingRules(sendingRules, this.authService.loggedUser.id);
}
async saveSendingRules(sendingRules: SendingRules, userId: number) {
try {
this.authService.showLoader('Updating Sending Rules...');
const url = 'https:url-to-server/save-sending-rules';
const params = {sendingRules, userId};
const response = await this.http.post(url, params, this.authService.authHeaders);
this.authService.hideLoader();
alert(response.data);
} catch (error) {
this.authService.hideLoader();
alert('error-->' + error.status);
alert(error.data);
}
}
Server side code:
router.post('/v1/save-sending-rules',function(req,res){
if(constants.DEBUG) console.log(req.body);
SendConfRules.findOne({
where : {
SRUL_VPUI_ID : req.body.userId
},
order : [['SRUL_VPUI_ID','DESC']]
}).then((confRules) => {
if(confRules){
confRules.update(dataObjects.sendingRules(req.body)).then((numRows) => {
res.json({
status : 200,
msg: "Rules updated"
});
});
}
else{
SendConfRules.create(dataObjects.sendingRules(req.body)).then(
(sendingRules) => {
res.json({
status : 200,
sendingRules : resSendingRules(confRules.dataValues)
});
}).catch((err) => {logger.error(err)});
}
}).catch((err) => {logger.error(err)});
});