I’d like to return the object id created for a guest
based on my if statement below. I’m new-ish to javascript and can’t figure out how to do this from the MDN function docs so wondering if there’s a way to return a variable from the below function so it can be used in another function below
const guest = await Guest.findOne({ email: req.body.email, user: event.user._id }).populate('event');
if (!guest) { // see if guest already exists
const newGuest = new Guest(req.body); // create new guest
newGuest.user = event.user._id;
newGuest.event = event._id;
await newGuest.save(); // save new guest to guest model
event.guests.push(newGuest);
await event.save(); // save guest to event
} else {
event.guests.push(guest);
await event.save(); //
}