pricing update to db
This commit is contained in:
parent
63585484f7
commit
2240d749a9
|
@ -209,10 +209,12 @@ const [ purchased, setPurchased ] = useState(false);
|
||||||
const submit = async (props) => {
|
const submit = async (props) => {
|
||||||
props.preventDefault();
|
props.preventDefault();
|
||||||
try {
|
try {
|
||||||
|
const id = userData.user.id;
|
||||||
const pricingRes = await Axios.put(
|
const pricingRes = await Axios.put(
|
||||||
"http://localhost:5000/users/update", {
|
"http://localhost:5000/users/update", {
|
||||||
userData.user.email,
|
id,
|
||||||
pricing
|
pricing
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
);
|
);
|
||||||
|
@ -315,10 +317,12 @@ const submit = async (props) => {
|
||||||
</React.Fragment>
|
</React.Fragment>
|
||||||
): (
|
): (
|
||||||
<React.Fragment>
|
<React.Fragment>
|
||||||
|
<PricingPlanContainer styles = "{'flex-direction':'column'}">
|
||||||
<Heading>user name: {userData.user.username}</Heading>
|
<Heading>user name: {userData.user.username}</Heading>
|
||||||
<h1>Plan selected : {pricing}</h1>
|
<Heading>Plan selected : {pricing}</Heading>
|
||||||
|
|
||||||
<Button onClick={submit}>Confirm and Pay</Button>
|
<Button onClick={submit}>Confirm and Pay</Button>
|
||||||
|
</PricingPlanContainer>
|
||||||
</React.Fragment>
|
</React.Fragment>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -111,18 +111,18 @@ router.get("/", auth, async (req, res) => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
router.put("/update", async (req, res) => {
|
router.put("/update", async (req, res) => {
|
||||||
const { email,pricing } = req.body;
|
const { id,pricing } = req.body;
|
||||||
const existingUser = await User.findOne({ email: email });
|
|
||||||
|
|
||||||
|
console.log("id " + id)
|
||||||
if (!existingUser) {
|
if (!id) {
|
||||||
return res.status(400).json({ Msg: "Not all fields have been entered." });
|
return res.status(400).json({ Msg: "Not all fields have been entered." });
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
User.findByIdAndUpdate({ _id: existingUser._id }, { pricing: pricing }).then(() => {
|
User.findByIdAndUpdate(id, { pricing: pricing }).then(() => {
|
||||||
User.findOne({ email: email }).then((user) => {
|
User.findOne({ _id: id }).then((user) => {
|
||||||
res.send(user);
|
res.send(user);
|
||||||
|
console.log(user)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue