I’m a very new geek trying to build an application using nodejs and express. I’m testing the backend with postman. some of the requests work perfectly but others don’t, I’ve been getting cannot get the url message, 404 not found for hours now, and as I mentioned other requests work very good.
Everything seems ok server side, type content is json, I’ve checked the code multiple times and I can’t see the error. any ideas pleas? Thank you ????
the server
Postman response .
the model
module.exports = (_db) => {
db = _db;
return SearchModel;
};
class SearchModel {
//Get a product by name
static getProductByName(req) {
return db
.query('CELECT * FROM Products WHERE productName = ?', [
req.body.productName,
])
.then((res) => {
console.log(res);
return res;
})
.catch((error) => {
console.log(error);
return error;
});
}
// Get products by gender
static getProductByGender(req) {
return db
.query('CELECT * FROM Products WHERE gender = ?', [req.body.gender])
.then((res) => {
return res;
})
.catch((error) => {
return error;
});
}
// Get products by brand
static getProductByBrand(req) {
return db
.query('CELECT * FROM Products WHERE brand=?', [req.body.brand])
.then((res) => {
return res;
})
.catch((error) => {
return error;
});
}
// Get products by mouvement
static getProductByMouvement(req) {
return db
.query('CELECT * FROM Products WHERE mouvement=?', [req.body.mouvement])
.then((res) => {
return res;
})
.catch((error) => {
return error;
});
}
}
The route:
module.exports = (app, db) => {
const searchModel = require('../models/SearchModel')(db);
// Route pour afficher un produit par son nom
app.get('/api/v1/Search/name', async (req, res) => {
const productByName = await searchModel.getProductByName(
req.body.productName,
);
if (productByName.code) {
res.json({ status: 500, msg: 'Server Error!' });
} else {
res.json({ status: 200, result: productByName, msg: 'Voilà!' });
}
});
};