77 insertUserTeamsSchema ,
88 selectTeamsSchema ,
99 teamsSchema ,
10+ udpateUserTeamsSchema ,
11+ updateTeamsSchema ,
1012 UserParticipationStatusEnum ,
1113 UserTeamRoleEnum ,
1214 userTeamsSchema ,
@@ -42,7 +44,7 @@ builder.mutationField("createTeam", (t) =>
4244 } ) ,
4345 } ,
4446 authz : {
45- rules : [ "IsAuthenticated " ] ,
47+ rules : [ "IsSuperAdmin " ] ,
4648 } ,
4749 resolve : async ( root , { input } , { DB , USER } ) => {
4850 if ( ! USER ) {
@@ -130,7 +132,7 @@ builder.mutationField("addPersonToTeam", (t) =>
130132 } ) ,
131133 } ,
132134 authz : {
133- rules : [ "IsAuthenticated " ] ,
135+ rules : [ "IsSuperAdmin " ] ,
134136 } ,
135137 resolve : async ( root , { input } , { USER , DB , logger } ) => {
136138 const { teamId, userEmail } = input ;
@@ -227,7 +229,7 @@ builder.mutationField("deletePersonFomTeam", (t) =>
227229 } ) ,
228230 } ,
229231 authz : {
230- rules : [ "IsAuthenticated " ] ,
232+ rules : [ "IsSuperAdmin " ] ,
231233 } ,
232234 resolve : async ( root , { input } , { USER , DB } ) => {
233235 const { teamId, userId } = input ;
@@ -257,7 +259,7 @@ builder.mutationField("deletePersonFomTeam", (t) =>
257259 } ) ,
258260) ;
259261
260- const updateTeam = builder . inputType ( "updateTeam " , {
262+ const updateTeam = builder . inputType ( "UpdateTeamInput " , {
261263 fields : ( t ) => ( {
262264 teamId : t . string ( {
263265 required : true ,
@@ -273,7 +275,7 @@ const updateTeam = builder.inputType("updateTeam", {
273275
274276builder . mutationField ( "updateTeam" , ( t ) =>
275277 t . field ( {
276- description : "Try to add a person to a team" ,
278+ description : "Updates a team information " ,
277279 type : TeamRef ,
278280 args : {
279281 input : t . arg ( {
@@ -306,13 +308,14 @@ builder.mutationField("updateTeam", (t) =>
306308 addToObjectIfPropertyExists ( properties , "name" , name ) ;
307309 addToObjectIfPropertyExists ( properties , "description" , description ) ;
308310
309- const teamToUpdate = insertTeamsSchema . parse ( properties ) ;
311+ const teamToUpdate = updateTeamsSchema . parse ( properties ) ;
310312
311- await DB . update ( teamsSchema )
313+ const udpatedTeam = await DB . update ( teamsSchema )
312314 . set ( teamToUpdate )
313- . where ( eq ( teamsSchema . id , teamId ) ) ;
315+ . where ( eq ( teamsSchema . id , teamId ) )
316+ . returning ( ) ;
314317
315- return team ;
318+ return selectTeamsSchema . parse ( udpatedTeam [ 0 ] ) ;
316319 } ,
317320 } ) ,
318321) ;
@@ -330,7 +333,7 @@ const acceptTeamInvitationInput = builder.inputType(
330333
331334builder . mutationField ( "acceptTeamInvitation" , ( t ) =>
332335 t . field ( {
333- description : "Accept an invitation to a team" ,
336+ description : "Accept the user's invitation to a team" ,
334337 type : TeamRef ,
335338 args : {
336339 input : t . arg ( {
@@ -362,13 +365,71 @@ builder.mutationField("acceptTeamInvitation", (t) =>
362365 throw new GraphQLError ( "You do not have permission to edit this team" ) ;
363366 }
364367
365- const teamToUpdate = insertTeamsSchema . parse ( {
368+ const teamToUpdate = udpateUserTeamsSchema . parse ( {
366369 userParticipationStatus : UserParticipationStatusEnum . accepted ,
367370 } ) ;
368371
369372 await DB . update ( userTeamsSchema )
370373 . set ( teamToUpdate )
371- . where ( eq ( userTeamsSchema . teamId , teamId ) ) ;
374+ . where ( eq ( userTeamsSchema . id , teamAndUsers ?. id ) ) ;
375+
376+ return team ;
377+ } ,
378+ } ) ,
379+ ) ;
380+
381+ const rejectTeamInvitationInput = builder . inputType (
382+ "RejectTeamInvitationInput" ,
383+ {
384+ fields : ( t ) => ( {
385+ teamId : t . string ( {
386+ required : true ,
387+ } ) ,
388+ } ) ,
389+ } ,
390+ ) ;
391+
392+ builder . mutationField ( "rejectTeamInvitation" , ( t ) =>
393+ t . field ( {
394+ description : "Reject the user's invitation to a team" ,
395+ type : TeamRef ,
396+ args : {
397+ input : t . arg ( {
398+ type : rejectTeamInvitationInput ,
399+ required : true ,
400+ } ) ,
401+ } ,
402+ authz : {
403+ rules : [ "IsAuthenticated" ] ,
404+ } ,
405+ resolve : async ( root , { input } , { USER , DB } ) => {
406+ const { teamId } = input ;
407+
408+ if ( ! USER ) {
409+ throw new GraphQLError ( "User not found" ) ;
410+ }
411+
412+ const teamAndUsers = await DB . query . userTeamsSchema . findFirst ( {
413+ where : ( t , { eq, and } ) =>
414+ and ( eq ( t . teamId , teamId ) , eq ( t . userId , USER . id ) ) ,
415+ with : {
416+ team : true ,
417+ user : true ,
418+ } ,
419+ } ) ;
420+ const team = teamAndUsers ?. team ;
421+
422+ if ( ! team ) {
423+ throw new GraphQLError ( "You do not have permission to edit this team" ) ;
424+ }
425+
426+ const teamToUpdate = udpateUserTeamsSchema . parse ( {
427+ userParticipationStatus : UserParticipationStatusEnum . not_accepted ,
428+ } ) ;
429+
430+ await DB . update ( userTeamsSchema )
431+ . set ( teamToUpdate )
432+ . where ( eq ( userTeamsSchema . id , teamAndUsers ?. id ) ) ;
372433
373434 return team ;
374435 } ,
0 commit comments