Skip to content

Commit

Permalink
Add waitlist to user model, create update endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
yash22arora committed May 18, 2024
1 parent e032d98 commit 65faca7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions server/api/models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const userScheme = mongoose.Schema({
firebaseUID: { type: String, required: true, unique: true },
email: { type: String, required: false },
stripeCustomerId: { type: String, required: false },
onWaitlist: { type: Boolean, required: true, default: false },
});

const User = mongoose.model("User", userScheme);
Expand Down
27 changes: 27 additions & 0 deletions server/api/routes/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ router.post("/login", async (req, res, next) => {
phoneNumber: phoneNumber,
firebaseUID: firebaseUID,
email: result.email,
onWaitlist: result.onWaitlist,
},
});
} else {
Expand Down Expand Up @@ -65,6 +66,8 @@ router.post("/login", async (req, res, next) => {
token: token,
phoneNumber: phoneNumber,
firebaseUID: firebaseUID,
email: result.email,
onWaitlist: result.onWaitlist,
},
});
})
Expand Down Expand Up @@ -119,6 +122,30 @@ router.patch("/update", checkAuth, async (req, res, next) => {
});
});

router.post("/waitlist", checkAuth, async (req, res, next) => {
const userID = req.userData.userID;
const onWaitlist = req.body.onWaitlist;

const doc = await User.findOneAndUpdate(
{ _id: userID },
{ onWaitlist: onWaitlist },
{ new: true }
)
.then((result) => {
res.status(200).json({
message: "User updated",
data: result,
});
})
.catch((err) => {
console.log(err);
res.status(500).json({
message: "Internal Server Error",
error: err,
});
});
});

router.post("/verify", checkAuth, (req, res, next) => {
res.status(200).json({
message: "User verified",
Expand Down

0 comments on commit 65faca7

Please sign in to comment.