Skip to content

HMTV2-9: Invite members to team#10

Open
YahyaAsmara wants to merge 1 commit intomainfrom
HMTV2-9-invite-members-to-team
Open

HMTV2-9: Invite members to team#10
YahyaAsmara wants to merge 1 commit intomainfrom
HMTV2-9-invite-members-to-team

Conversation

@YahyaAsmara
Copy link

@YahyaAsmara YahyaAsmara commented Mar 3, 2026

Implements team member invitation system for HMTV2-9.

Features:

  • join mutation -> users join a team using a 4-char team code
  • invite mutation -> team owners invite users by email (7-day expiry)
  • acceptInvite mutation -> invited users accept pending invitations
  • leave mutation -> users leave; empty teams auto-delete
  • One-team-per-user constraint enforced across all join/invite endpoints
  • Includes HMTV2-8 changes: teamCode field, MEMBER_ROLES constant, transaction safety

Files changed: teams.ts, auth-schema.ts, types.ts

@YahyaAsmara
Copy link
Author

btw some of the changes are from HMTV2-8 as it is not closed yet and since i built off this branch.

return team;
}),

join: protectedProcedure
Copy link
Author

Choose a reason for hiding this comment

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

NEW (HMTV2-9): join mutation. Users join existing team via 4-char team code. Validates one-team-per-user constraint

.toUpperCase()
})
)
.mutation(async ({ ctx, input }) => {
Copy link
Author

Choose a reason for hiding this comment

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

validates user not already on team, finds team by code, adds as MEMBER

return team;
}),

invite: protectedProcedure
Copy link
Author

Choose a reason for hiding this comment

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

NEW (HMTV2-9): invite mutation. Team owners send email invitations with 7-day expiry. Checks: user is owner, invited email exists/not on team, no duplicate pending invite

email: z.string().email("Invalid email address")
})
)
.mutation(async ({ ctx, input }) => {
Copy link
Author

Choose a reason for hiding this comment

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

validates ownership, creates invitation record with expiry

return newInvitation;
}),

acceptInvite: protectedProcedure
Copy link
Author

Choose a reason for hiding this comment

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

NEW (HMTV2-9): acceptInvite mutation. Invited users accept pending invitations. Validates: email matches current user, invitation not expired, not already on team. Transactional: adds member + marks invitation as accepted.

invitationId: z.string()
})
)
.mutation(async ({ ctx, input }) => {
Copy link
Author

Choose a reason for hiding this comment

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

validates invitation ownership & expiry, adds member, updates invitation

return { success: true };
}),

leave: protectedProcedure.mutation(async ({ ctx }) => {
Copy link
Author

Choose a reason for hiding this comment

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

NEW (HMTV2-9 or HMTV2-10): leave mutation. Users leave team; auto-deletes empty teams + their pending invitations. It removes member, cleans up team if no members remain. Had this code before last week's meeting so I just kept it here. Will probably continue this portion for HMTV2-10. Or just use this PR to complete HMTV2-10-leave-team.

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.

1 participant