Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 24 additions & 8 deletions shatter-backend/src/controllers/event_controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,18 @@ export async function joinEventAsUser(req: Request, res: Response) {
});
} catch (e: any) {
if (e.code === 11000) {
return res.status(409).json({
success: false,
msg: "This name is already taken in this event",
});
if (e.keyPattern?.name && e.keyPattern?.eventId) {
return res.status(409).json({
success: false,
msg: "This name is already taken in this event",
});
}
if (e.keyPattern?.email) {
return res.status(409).json({
success: false,
msg: "A user with this email already exists",
});
}
}
console.error("JOIN EVENT ERROR:", e);
return res.status(500).json({ success: false, msg: "Internal error" });
Expand Down Expand Up @@ -297,10 +305,18 @@ export async function joinEventAsGuest(req: Request, res: Response) {
});
} catch (e: any) {
if (e.code === 11000) {
return res.status(409).json({
success: false,
msg: "This name is already taken in this event",
});
if (e.keyPattern?.name && e.keyPattern?.eventId) {
return res.status(409).json({
success: false,
msg: "This name is already taken in this event",
});
}
if (e.keyPattern?.email) {
return res.status(409).json({
success: false,
msg: "A user with this email already exists",
});
}
}
console.error("JOIN GUEST ERROR:", e);
return res.status(500).json({ success: false, msg: "Internal error" });
Expand Down
1 change: 0 additions & 1 deletion shatter-backend/src/models/user_model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ const UserSchema = new Schema<IUser>(
lowercase: true,
unique: true,
sparse: true, // allows multiple users without email (guests)
index: true,
match: [
/^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/,
"Please provide a valid email address",
Expand Down