@@ -75,57 +75,6 @@ export async function getTeamMembers(teamId: string) {
7575 } ) ) ;
7676}
7777
78- /**
79- * Update a team member's role
80- */
81- export async function updateTeamMemberRole ( {
82- teamId,
83- userId,
84- roleId,
85- isSystemRole = false
86- } : {
87- teamId : string ;
88- userId : string ;
89- roleId : string ;
90- isSystemRole ?: boolean ;
91- } ) {
92- // Check if user has permission to change member roles
93- await requireTeamPermission ( teamId , TEAM_PERMISSIONS . CHANGE_MEMBER_ROLES ) ;
94-
95- const db = getDB ( ) ;
96-
97- // Verify membership exists
98- const membership = await db . query . teamMembershipTable . findFirst ( {
99- where : and (
100- eq ( teamMembershipTable . teamId , teamId ) ,
101- eq ( teamMembershipTable . userId , userId )
102- ) ,
103- } ) ;
104-
105- if ( ! membership ) {
106- throw new ZSAError ( "NOT_FOUND" , "Team membership not found" ) ;
107- }
108-
109- // Update the role
110- await db . update ( teamMembershipTable )
111- . set ( {
112- roleId,
113- isSystemRole : isSystemRole ? 1 : 0 ,
114- updatedAt : new Date ( ) ,
115- } )
116- . where (
117- and (
118- eq ( teamMembershipTable . teamId , teamId ) ,
119- eq ( teamMembershipTable . userId , userId )
120- )
121- ) ;
122-
123- // Update the user's session to reflect the new role
124- await updateAllSessionsOfUser ( userId ) ;
125-
126- return { success : true } ;
127- }
128-
12978/**
13079 * Remove a member from a team
13180 */
@@ -448,76 +397,6 @@ export async function acceptTeamInvitation(token: string) {
448397 } ;
449398}
450399
451- /**
452- * Get pending invitations for a team
453- */
454- export async function getTeamInvitations ( teamId : string ) {
455- // Check if user has permission to view invitations
456- await requireTeamPermission ( teamId , TEAM_PERMISSIONS . INVITE_MEMBERS ) ;
457-
458- const db = getDB ( ) ;
459-
460- // Get invitations that have not been accepted
461- const invitations = await db . query . teamInvitationTable . findMany ( {
462- where : and (
463- eq ( teamInvitationTable . teamId , teamId ) ,
464- isNull ( teamInvitationTable . acceptedAt )
465- ) ,
466- with : {
467- invitedByUser : {
468- columns : {
469- id : true ,
470- firstName : true ,
471- lastName : true ,
472- email : true ,
473- avatar : true ,
474- }
475- }
476- } ,
477- } ) ;
478-
479- return invitations . map ( invitation => ( {
480- id : invitation . id ,
481- email : invitation . email ,
482- roleId : invitation . roleId ,
483- isSystemRole : Boolean ( invitation . isSystemRole ) ,
484- createdAt : new Date ( invitation . createdAt ) ,
485- expiresAt : invitation . expiresAt ? new Date ( invitation . expiresAt ) : null ,
486- invitedBy : {
487- id : invitation . invitedByUser . id ,
488- firstName : invitation . invitedByUser . firstName ,
489- lastName : invitation . invitedByUser . lastName ,
490- email : invitation . invitedByUser . email ,
491- avatar : invitation . invitedByUser . avatar ,
492- }
493- } ) ) ;
494- }
495-
496- /**
497- * Cancel a team invitation
498- */
499- export async function cancelTeamInvitation ( invitationId : string ) {
500- const db = getDB ( ) ;
501-
502- // Find the invitation
503- const invitation = await db . query . teamInvitationTable . findFirst ( {
504- where : eq ( teamInvitationTable . id , invitationId ) ,
505- } ) ;
506-
507- if ( ! invitation ) {
508- throw new ZSAError ( "NOT_FOUND" , "Invitation not found" ) ;
509- }
510-
511- // Check if user has permission to cancel invitations for this team
512- await requireTeamPermission ( invitation . teamId , TEAM_PERMISSIONS . INVITE_MEMBERS ) ;
513-
514- // Delete the invitation
515- await db . delete ( teamInvitationTable )
516- . where ( eq ( teamInvitationTable . id , invitationId ) ) ;
517-
518- return { success : true } ;
519- }
520-
521400/**
522401 * Get pending invitations for the current user
523402 */
0 commit comments