Skip to content

Implement createVolunteer function#87

Merged
LeandroHamaguchi merged 5 commits intomainfrom
backend/new-create-volunteer
Feb 5, 2026
Merged

Implement createVolunteer function#87
LeandroHamaguchi merged 5 commits intomainfrom
backend/new-create-volunteer

Conversation

@LeandroHamaguchi
Copy link
Member

This function adds a volunteer record to the database atomically by creating/updating Roles, Cohorts, VolunteerCohorts, and VolunteerRoles accordingly.

  • There are tests for this function in createVolunteer.test.ts, and I had to update the supabase:setup script to run migrations since I implemented a plpgsql script as a migration file.
  • The plpgsql migration file creates an RPC (Remote Procedure Call) function called create_volunteer_with_role_and_cohort locally for testing purposes. I also created the same function in Supabase, remotely, to work with the main project.
  • The create_volunteer_with_role_and_cohort function creates volunteer with role and cohort in a single transaction.
  • If the role (by name, type) or cohort (by year, term) does not exist, they are created.
  • The RPC function returns the new volunteer id.

This PR consists of:

  • The updated supabase:setup script
  • The migration file
  • New typing for the RPC function
  • createVolunteer.ts and createVolunteer.test.ts

@vercel
Copy link

vercel bot commented Feb 2, 2026

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

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
trcc Ignored Ignored Feb 5, 2026 6:17pm

Copy link
Contributor

@a1-su a1-su left a comment

Choose a reason for hiding this comment

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

Other than the email validation, LGTM! I might also remind the others to run supabase setup again once the PR is merged.

Comment on lines 85 to 86
(data["email"] as string).trim().length > 0 &&
!isValidEmail(data["email"] as string)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure if this is intentional, but the email validation allows empty strings as valid emails; presumably this should check for length === 0 || !isValidEmail(...)? I'm pretty sure just !isValidEmail(...) in itself would also work.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for catching that! I ended up removing that check since we don't know exactly what type of annotations TRCC uses for the email field. For example, they might use "no email" or "double check: email@email.com" or something else.

@LeandroHamaguchi LeandroHamaguchi merged commit 3cc3656 into main Feb 5, 2026
3 checks passed
@LeandroHamaguchi LeandroHamaguchi deleted the backend/new-create-volunteer branch February 5, 2026 23:04
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.

2 participants