You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Add Store
const addStore = (req, res) => {
try {
console.log(req.body); // Log the request body
const { userId, name, category, address, city } = req.body;
const newStore = new Store({
userID: userId, // Assuming the property name is userId in the request body
name,
category,
address,
city
});
newStore.save()
.then((result) => {
res.status(200).send(result);
})
.catch((err) => {
console.error("Error saving store:", err); // Log the error
res.status(400).send(err);
});
const Store = require("../models/store");
// Add Store
const addStore = (req, res) => {
try {
console.log(req.body); // Log the request body
const { userId, name, category, address, city } = req.body;
} catch (err) {
console.error("Error adding store:", err); // Log the error
res.status(500).send(err);
}
};
// Get All Stores
const getAllStores = async (req, res) => {
try {
const { userID } = req.query;
console.log("UserID:", userID); // Log the userID
const findAllStores = await Store.find({ "userID": userID }).sort({ _id: -1 });
res.json(findAllStores);
} catch (err) {
console.error("Error fetching stores:", err); // Log the error
res.status(500).send(err);
}
};
module.exports = { addStore, getAllStores };
here on the console its showing UserID undefined
Data also not getting added to mongodb
The text was updated successfully, but these errors were encountered: