Skip to content

Commit

Permalink
fix(EventsManager): error when registering for others
Browse files Browse the repository at this point in the history
* fix(EventsManager): duplicate registration error

* fix(EventsManager): improve duplicate registration check logic
  • Loading branch information
jakeaturner committed Oct 18, 2023
1 parent 52b0591 commit b9039fc
Showing 1 changed file with 7 additions and 16 deletions.
23 changes: 7 additions & 16 deletions server/api/orgevents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,6 @@ async function submitRegistration(
} = req.body;
let stripeKey: string | null = null;
let shouldSendConfirmation = true;
let foundUser: UserInterface | undefined | null = undefined;

if (type === "self" && !userID) {
return conductor400Err(res);
Expand All @@ -405,14 +404,6 @@ async function submitRegistration(
return conductor400Err(res);
}

if (userID) {
foundUser = await User.findOne({
uuid: userID,
})
.lean()
.orFail({ name: "Not Found", message: "User not found." });
}

// This should always be found because even registering for self will have registeredBy populated
const foundRegisteredBy = await User.findOne({
uuid: registeredBy,
Expand Down Expand Up @@ -447,8 +438,8 @@ async function submitRegistration(
if (type === "self") {
const matchObj = {
$or: [
{ eventID: req.params.eventID, user: foundUser?._id },
{ eventID: req.params.eventID, email: foundUser?.email },
{ eventID: req.params.eventID, user: foundRegisteredBy._id },
{ eventID: req.params.eventID, email: foundRegisteredBy.email },
],
};
const foundExisting = await OrgEventParticipant.findOne(matchObj);
Expand Down Expand Up @@ -498,7 +489,7 @@ async function submitRegistration(
const CREATED_REG_ID = uuidv4();
const participant = new OrgEventParticipant({
regID: CREATED_REG_ID,
user: !!foundUser?._id ? foundUser._id : undefined,
user: type === "self" ? foundRegisteredBy._id : undefined,
orgID,
eventID: req.params.eventID,
paymentStatus: shouldCollectPayment ? "unpaid" : "na",
Expand Down Expand Up @@ -568,7 +559,7 @@ async function submitRegistration(
orgID,
eventID: req.params.eventID ?? "unknown",
regID: CREATED_REG_ID,
userUUID: foundUser?.uuid ?? "unknown",
userUUID: foundRegisteredBy.uuid ?? "unknown",
firstName: firstName ?? "unknown",
lastName: lastName ?? "unknown",
email: email ?? "unknown",
Expand All @@ -595,7 +586,7 @@ async function submitRegistration(
if (shouldSendConfirmation) {
const emailAddresses = [];
emailAddresses.push(foundRegisteredBy.email);
if (!foundUser && email) {
if (!foundRegisteredBy && email) {
emailAddresses.push(email);
}

Expand All @@ -622,8 +613,8 @@ async function submitRegistration(
.sendOrgEventRegistrationConfirmation(
emailAddresses,
orgEvent,
foundUser && foundUser.firstName
? foundUser.firstName
foundRegisteredBy && foundRegisteredBy.firstName
? foundRegisteredBy.firstName
: firstName
? firstName
: "Unknown",
Expand Down

0 comments on commit b9039fc

Please sign in to comment.