Skip to content

Conversation

@fredh2006
Copy link

No description provided.

@vercel
Copy link

vercel bot commented Nov 20, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
trcc Ready Ready Preview Comment Nov 20, 2025 7:32pm

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR creates a new volunteer management API that allows adding volunteers to the database via a POST endpoint. The implementation includes input validation, error handling, and type safety using TypeScript and Supabase.

Key changes:

  • New API function addVolunteer with comprehensive input validation and error handling
  • REST endpoint at /api/volunteers (POST) to expose the volunteer creation functionality
  • Type definitions for volunteer input, validation errors, and API responses

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
src/lib/api/addVolunteer.ts Core API function with validation logic, email validation, and database insertion for volunteers
src/app/api/volunteers/route.ts Next.js route handler that wraps the addVolunteer function and handles HTTP request/response
src/lib/api/index.ts Export declarations for the new addVolunteer function and its associated types

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

* @returns true if the email is valid, false otherwise
*/
function isValidEmail(email: string): boolean {
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
Copy link

Copilot AI Nov 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The email validation regex is too permissive and could allow invalid email addresses. It doesn't handle edge cases like consecutive dots, leading/trailing dots in the local or domain part, or invalid TLD formats. Consider using a more robust email validation library or a more comprehensive regex pattern that follows RFC 5322 standards more closely.

Copilot uses AI. Check for mistakes.
Comment on lines +160 to +166
if (error.code === "23505") {
// Unique constraint violation
return {
success: false,
error: "A volunteer with this information already exists",
};
}
Copy link

Copilot AI Nov 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message "A volunteer with this information already exists" is vague and doesn't inform the user which field caused the unique constraint violation. Since the database schema doesn't show explicit unique constraints on the Volunteers table besides the id, this error message could be confusing. Consider either making it more specific or removing this special case if there are no unique constraints other than the primary key.

Suggested change
if (error.code === "23505") {
// Unique constraint violation
return {
success: false,
error: "A volunteer with this information already exists",
};
}

Copilot uses AI. Check for mistakes.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to implement route.ts file.

Copy link
Member

@LeandroHamaguchi LeandroHamaguchi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please include a detailed description of the PR, with screenshots demonstrating the functionality and showing that it correctly created a volunteer in the database. You can refer to the other PRs to write a good description. Let us know if you need any help!

.single();

// Handle database errors
if (error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also return the error object from Supabase client. It should help when debugging, if needed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should rename the file and function to createVolunteer. It's just better practice to use the same naming convention for all functions.


export { getExample } from "./getExample";
export { addVolunteer } from "./addVolunteer";
export type {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should only export the addVolunteer function for now. Rename the function to createVolunteer.

* @returns A response object indicating success or failure
*/
export async function addVolunteer(
volunteerData: unknown,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add typing for the volunteerData

Copy link
Member

@LeandroHamaguchi LeandroHamaguchi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When creating a volunteer we also want to create a VolunteerRoles and a VolunteerCohorts relations with the volunteer's id and the volunteer's role/cohort. We get the volunteer's role and cohort as an user input. Make sure the role and cohort inputted exist as a row in the Roles and Cohorts tables respectively.

  • The role user input should be a tuple of name: string and type: string in ["prior", "current", "future_interest"].
  • The cohort user input should be a tuple of year: int and term: string in ["fall", "summer", "winter", "spring"].

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants