When the search route is placed at the top, everything works fine. However, when it is placed at the end, the route that takes ID as a parameter keeps getting called repeatedly in Node. Why does this happen and how can it be resolved?
router.get('/search', function (req, res) {
var p_Where = {};
if (req.query.IsDeleted)
p_Where.IsDeleted = req.query.IsDeleted;
if (req.query.CustomerName)
p_Where.CustomerName = { $like: '%' + req.query.CustomerName + '%' };
if (req.query.PhoneNumber)
p_Where.PhoneNumber = { $like: '%' + req.query.PhoneNumber + '%' };
if (req.query.OmitCustomerID)
p_Where.CustomerID = { $ne: req.query.OmitCustomerID };
if (req.query.CustomerID)
p_Where.CustomerID = req.query.CustomerID;
if (req.query.ShowAutoGenerated)
p_Where.IsAutoGenerated = req.query.ShowAutoGenerated;
if (req.query.DeviceNumber)
p_Where.DeviceNumber = req.query.DeviceNumber;
if (req.query.CarrierID)
p_Where.CarrierID = req.query.CarrierID;
console.log(p_Where);
models.Product.findAll ({
where : p_Where,
}).then(function (customer) {
res.json({
status : true,
message : "Products has been found",
data : customer
});
});
});
router.get ('/', function (req, res) {
models.Product.findAll ({
where: {
WholeSaleCustomerId: req.get ("wscId")
},
include: [models.ProductSpecification]
}).then (function (Product) {
if (Product.length == 0) {
res.status (404).json ({
status: false,
message: "No product has been found."
});
}else{
res.json ({
status: true,
message: "Products has been found.",
data: Product
});
}
});
});
router.get (':productId', function (req, res) {
models.Product.findOne({
where: {
WholeSaleCustomerId: req.get ("wscId"),
id: req.params.productId
},
include: [models.ProductSpecification]
}).then (function (Product) {
if (!Product) {
res.status (404).json ({
status : false,
message : "No product has been found."
});
return;
}else{
res.json ({
status : true,
message : "Product has been found.",
data : Product
});
}
});
});