I'm running the project Angular using Node.js server MSSQL express. Can someone please check my code what is missing or mistake in getting the data using WHERE condition. Thank you.
/// Backend server API node.js MSSQL
checkCustPhone: (phone, callback) => {
connection.query(
`select * from tbl_customers where Phone_Number='${phone}'`,
(error, result) => {
if (error) {
return callback(error);
}
return callback(null, result);
}
);
}
custData: (req, res) => {
let phone = req.phone;
checkCustPhone(req.params.phone,(error, result) => {
if (error) {
return res.send({ status: 0, data: result.recordset });
}
return res.send({ status: 1, data: result.recordset });
});
}
const express = require("express");
const router = express.Router();
const {
custData,
} = require("./Tcontroller");
router.get("/getcustomer", custData);
// Service.ts
getCustomerData(Phone_Number: any) {
return this.http.get(`${this.url}/orders/getcustomer`,Phone_Number);
}
/// Component.ts
Phone_Number = '9762985657';
ngOnInit(): void {
this.orderService.getCustomerData(this.Phone_Number).subscribe((res: any) => {
console.log(res.data); },
(error) => {
this.alertService.onError(error.message);
});
}
I'm testing in console log in my Component to check if I get data using a Phone Number from the DB but it returns nothing.
1条答案
按热度按时间am46iovg1#
From the response to your previous comment, you get a response when you run the phone number query against your backend db. Which is a great start.
Here are few errors I see on the angular side of your code.
phone
as a parameter in the request.the backend is expecting aphone
as req.params. that is in yourcheckCustPhone(....). Without passing in the
phone` as parameter through your service, your BE won't receive any phone as req.params to check your db against and return a results.Modify your service.ts to include the phone as params.
eg.