Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manage store api not working #2

Open
kartikgx13 opened this issue Apr 28, 2024 · 1 comment
Open

Manage store api not working #2

kartikgx13 opened this issue Apr 28, 2024 · 1 comment

Comments

@kartikgx13
Copy link

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

@ParagVarshney
Copy link

how to correct manage store api

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants