-
Notifications
You must be signed in to change notification settings - Fork 78
Description
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;
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);
});
} 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