From 2240d749a9b534c37327ac35fd8a69a95841d728 Mon Sep 17 00:00:00 2001 From: Priyatham-sai-chand Date: Wed, 24 Mar 2021 08:35:53 +0530 Subject: [PATCH] pricing update to db --- client/src/components/PricingPlan.js | 12 ++++++++---- server/routes/users.js | 14 +++++++------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/client/src/components/PricingPlan.js b/client/src/components/PricingPlan.js index 16aea0b..9b6f63f 100644 --- a/client/src/components/PricingPlan.js +++ b/client/src/components/PricingPlan.js @@ -209,11 +209,13 @@ const [ purchased, setPurchased ] = useState(false); const submit = async (props) => { props.preventDefault(); try { + const id = userData.user.id; const pricingRes = await Axios.put( "http://localhost:5000/users/update", { - userData.user.email, - pricing - } + id, + pricing + + } ); } catch (err) { @@ -315,10 +317,12 @@ const submit = async (props) => { ): ( + user name: {userData.user.username} -

Plan selected : {pricing}

+ Plan selected : {pricing} +
) } diff --git a/server/routes/users.js b/server/routes/users.js index fd98d44..13bdb51 100644 --- a/server/routes/users.js +++ b/server/routes/users.js @@ -111,22 +111,22 @@ router.get("/", auth, async (req, res) => { }); }); router.put("/update", async (req, res) => { - const { email,pricing } = req.body; - const existingUser = await User.findOne({ email: email }); + const { id,pricing } = req.body; - - if (!existingUser) { + console.log("id " + id) + if (!id) { return res.status(400).json({ Msg: "Not all fields have been entered." }); } - User.findByIdAndUpdate({ _id: existingUser._id }, { pricing: pricing }).then(() => { - User.findOne({ email: email }).then((user) => { + User.findByIdAndUpdate(id, { pricing: pricing }).then(() => { + User.findOne({ _id: id }).then((user) => { res.send(user); + console.log(user) }) }) - +