@@ -9,118 +9,120 @@ const mutationUpdateActionItemCategoryArgumentsSchema = z.object({
9
9
input : z . object ( {
10
10
categoryId : z . string ( ) . uuid ( ) , // The ID of the category to update
11
11
name : z . string ( ) . optional ( ) , // New name
12
- isDisabled : z . boolean ( ) . optional ( ) , // Enable/disable
12
+ isDisabled : z . boolean ( ) . optional ( ) ,
13
13
} ) ,
14
14
} ) ;
15
15
16
- export const updateActionItemCategory = builder . mutationField ( "updateActionItemCategory" , ( t ) =>
17
- t . field ( {
18
- type : ActionItemCategory ,
19
- args : {
20
- input : t . arg ( {
21
- required : true ,
22
- type : builder . inputType ( "UpdateActionItemCategoryInput" , {
23
- fields : ( t ) => ( {
24
- categoryId : t . field ( { type : "ID" , required : true } ) ,
25
- name : t . field ( { type : "String" } ) ,
26
- isDisabled : t . field ( { type : "Boolean" } ) ,
16
+ export const updateActionItemCategory = builder . mutationField (
17
+ "updateActionItemCategory" ,
18
+ ( t ) =>
19
+ t . field ( {
20
+ type : ActionItemCategory ,
21
+ args : {
22
+ input : t . arg ( {
23
+ required : true ,
24
+ type : builder . inputType ( "UpdateActionItemCategoryInput" , {
25
+ fields : ( t ) => ( {
26
+ categoryId : t . field ( { type : "ID" , required : true } ) ,
27
+ name : t . field ( { type : "String" } ) ,
28
+ isDisabled : t . field ( { type : "Boolean" } ) ,
29
+ } ) ,
27
30
} ) ,
28
31
} ) ,
29
- } ) ,
30
- } ,
31
- description : "Mutation field to update an existing Action Item Category." ,
32
- resolve : async ( _parent , args , ctx ) => {
33
- // 1. Check user authentication
34
- if ( ! ctx . currentClient . isAuthenticated ) {
35
- throw new TalawaGraphQLError ( {
36
- extensions : { code : "unauthenticated" } ,
37
- } ) ;
38
- }
32
+ } ,
33
+ description : "Mutation field to update an existing Action Item Category." ,
34
+ resolve : async ( _parent , args , ctx ) => {
35
+ // 1. Check user authentication
36
+ if ( ! ctx . currentClient . isAuthenticated ) {
37
+ throw new TalawaGraphQLError ( {
38
+ extensions : { code : "unauthenticated" } ,
39
+ } ) ;
40
+ }
39
41
40
- // 2. Validate input
41
- const parsedArgs =
42
- mutationUpdateActionItemCategoryArgumentsSchema . parse ( args ) ;
43
- const { categoryId, name, isDisabled } = parsedArgs . input ;
44
- const currentUserId = ctx . currentClient . user . id ;
42
+ // 2. Validate input
43
+ const parsedArgs =
44
+ mutationUpdateActionItemCategoryArgumentsSchema . parse ( args ) ;
45
+ const { categoryId, name, isDisabled } = parsedArgs . input ;
46
+ const currentUserId = ctx . currentClient . user . id ;
45
47
46
- // 3. Find the existing category
47
- const existingCategory =
48
- await ctx . drizzleClient . query . actionCategoriesTable . findFirst ( {
49
- columns : {
50
- id : true ,
51
- organizationId : true ,
52
- } ,
53
- where : ( fields , operators ) => operators . eq ( fields . id , categoryId ) ,
54
- } ) ;
48
+ // 3. Find the existing category
49
+ const existingCategory =
50
+ await ctx . drizzleClient . query . actionCategoriesTable . findFirst ( {
51
+ columns : {
52
+ id : true ,
53
+ organizationId : true ,
54
+ } ,
55
+ where : ( fields , operators ) => operators . eq ( fields . id , categoryId ) ,
56
+ } ) ;
55
57
56
- if ( ! existingCategory ) {
57
- throw new TalawaGraphQLError ( {
58
- extensions : {
59
- code : "arguments_associated_resources_not_found" ,
60
- issues : [ { argumentPath : [ "input" , "categoryId" ] } ] ,
61
- } ,
62
- } ) ;
63
- }
58
+ if ( ! existingCategory ) {
59
+ throw new TalawaGraphQLError ( {
60
+ extensions : {
61
+ code : "arguments_associated_resources_not_found" ,
62
+ issues : [ { argumentPath : [ "input" , "categoryId" ] } ] ,
63
+ } ,
64
+ } ) ;
65
+ }
64
66
65
- // 4. Check if the user is an admin in that category's organization
66
- const userMembership =
67
- await ctx . drizzleClient . query . organizationMembershipsTable . findFirst ( {
68
- columns : { role : true } ,
69
- where : ( fields , operators ) =>
70
- sql `${ operators . eq ( fields . memberId , currentUserId ) }
67
+ // 4. Check if the user is an admin in that category's organization
68
+ const userMembership =
69
+ await ctx . drizzleClient . query . organizationMembershipsTable . findFirst ( {
70
+ columns : { role : true } ,
71
+ where : ( fields , operators ) =>
72
+ sql `${ operators . eq ( fields . memberId , currentUserId ) }
71
73
AND ${ operators . eq ( fields . organizationId , existingCategory . organizationId ) } ` ,
72
- } ) ;
74
+ } ) ;
73
75
74
- if ( ! userMembership || userMembership . role !== "administrator" ) {
75
- throw new TalawaGraphQLError ( {
76
- extensions : {
77
- code : "forbidden_action_on_arguments_associated_resources" ,
78
- issues : [
79
- {
80
- argumentPath : [ "input" , "categoryId" ] ,
81
- message : "Only administrators can update this category." ,
82
- } ,
83
- ] ,
84
- } ,
85
- } ) ;
86
- }
76
+ if ( ! userMembership || userMembership . role !== "administrator" ) {
77
+ throw new TalawaGraphQLError ( {
78
+ extensions : {
79
+ code : "forbidden_action_on_arguments_associated_resources" ,
80
+ issues : [
81
+ {
82
+ argumentPath : [ "input" , "categoryId" ] ,
83
+ message : "Only administrators can update this category." ,
84
+ } ,
85
+ ] ,
86
+ } ,
87
+ } ) ;
88
+ }
87
89
88
- // Build update fields
89
- const updates : Record < string , unknown > = { } ;
90
- let hasUpdates = false ;
90
+ // Build update fields
91
+ const updates : Record < string , unknown > = { } ;
92
+ let hasUpdates = false ;
91
93
92
- if ( typeof name === "string" ) {
93
- updates . name = name ;
94
- hasUpdates = true ;
95
- }
94
+ if ( typeof name === "string" ) {
95
+ updates . name = name ;
96
+ hasUpdates = true ;
97
+ }
96
98
97
- if ( typeof isDisabled === "boolean" ) {
98
- updates . isDisabled = isDisabled ;
99
- hasUpdates = true ;
100
- }
99
+ if ( typeof isDisabled === "boolean" ) {
100
+ updates . isDisabled = isDisabled ;
101
+ hasUpdates = true ;
102
+ }
101
103
102
- // Only update if there's any field to update.
103
- if ( hasUpdates ) {
104
- updates . updatedAt = new Date ( ) ;
105
- // Proceed with the update operation
106
- } else {
107
- // Optionally log or handle no-op scenario: nothing to update
108
- }
104
+ // Only update if there's any field to update.
105
+ if ( hasUpdates ) {
106
+ updates . updatedAt = new Date ( ) ;
107
+ // Proceed with the update operation
108
+ } else {
109
+ // Optionally log or handle no-op scenario: nothing to update
110
+ }
109
111
110
- const [ updatedCategory ] = await ctx . drizzleClient
111
- . update ( actionCategoriesTable )
112
- . set ( updates )
113
- . where ( eq ( actionCategoriesTable . id , categoryId ) )
114
- . returning ( ) ;
112
+ const [ updatedCategory ] = await ctx . drizzleClient
113
+ . update ( actionCategoriesTable )
114
+ . set ( updates )
115
+ . where ( eq ( actionCategoriesTable . id , categoryId ) )
116
+ . returning ( ) ;
115
117
116
- if ( ! updatedCategory ) {
117
- ctx . log . error (
118
- "Postgres update operation unexpectedly returned an empty array." ,
119
- ) ;
120
- throw new TalawaGraphQLError ( { extensions : { code : "unexpected" } } ) ;
121
- }
118
+ if ( ! updatedCategory ) {
119
+ ctx . log . error (
120
+ "Postgres update operation unexpectedly returned an empty array." ,
121
+ ) ;
122
+ throw new TalawaGraphQLError ( { extensions : { code : "unexpected" } } ) ;
123
+ }
122
124
123
- return updatedCategory ;
124
- } ,
125
- } ) ,
125
+ return updatedCategory ;
126
+ } ,
127
+ } ) ,
126
128
) ;
0 commit comments