-
Notifications
You must be signed in to change notification settings - Fork 0
create volunteer api #41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this 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
addVolunteerwith 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@]+$/; |
Copilot
AI
Nov 22, 2025
There was a problem hiding this comment.
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.
| if (error.code === "23505") { | ||
| // Unique constraint violation | ||
| return { | ||
| success: false, | ||
| error: "A volunteer with this information already exists", | ||
| }; | ||
| } |
Copilot
AI
Nov 22, 2025
There was a problem hiding this comment.
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.
| if (error.code === "23505") { | |
| // Unique constraint violation | |
| return { | |
| success: false, | |
| error: "A volunteer with this information already exists", | |
| }; | |
| } |
There was a problem hiding this comment.
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.
LeandroHamaguchi
left a comment
There was a problem hiding this 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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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
LeandroHamaguchi
left a comment
There was a problem hiding this 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: stringandtype: string in ["prior", "current", "future_interest"]. - The cohort user input should be a tuple of
year: intandterm: string in ["fall", "summer", "winter", "spring"].
No description provided.