@@ -105,13 +105,8 @@ type UserFromDB = {
105
105
role : UserRole ;
106
106
homePhoneNumber : string | null ;
107
107
workPhoneNumber : string | null ;
108
- avatarMimeType :
109
- | "image/avif"
110
- | "image/jpeg"
111
- | "image/png"
112
- | "image/webp"
113
- | null ;
114
- avatarBase64 : string | null ;
108
+ avatarMimeType : "image/avif" | "image/jpeg" | "image/png" | "image/webp" | null
109
+ avatarBase64 : string | null ;
115
110
educationGrade : string | null ;
116
111
employmentStatus : string | null ;
117
112
maritalStatus : string | null ;
@@ -177,7 +172,7 @@ const createMockContext = (overrides?: Partial<TestContext>): TestContext => ({
177
172
decorate : vi . fn ( ) ,
178
173
get : vi . fn ( ) ,
179
174
post : vi . fn ( ) ,
180
- } as unknown as FastifyInstance ,
175
+ } as Partial < Pick < FastifyInstance , 'addHook' | 'decorate' | 'get' | 'post' > > ,
181
176
reply : {
182
177
code : vi . fn ( ) ,
183
178
send : vi . fn ( ) ,
@@ -228,6 +223,11 @@ const resolveCreator = async (
228
223
} ) ;
229
224
}
230
225
226
+ // Early return if organization has no creator
227
+ if ( parent . creatorId === null ) {
228
+ return null ;
229
+ }
230
+
231
231
const currentUserOrganizationMembership =
232
232
currentUser . organizationMembershipsWhereMember [ 0 ] ;
233
233
@@ -378,6 +378,23 @@ describe("Organization Resolver - Creator Field", () => {
378
378
} ) ;
379
379
} ) ;
380
380
381
+ it ( "should throw unauthorized error if user has no organization membership" , async ( ) => {
382
+ const mockUser = createCompleteMockUser ( "regular" , [ ] ) ;
383
+ ctx . drizzleClient . query . usersTable . findFirst . mockResolvedValueOnce ( mockUser ) ;
384
+
385
+ await expect ( async ( ) => {
386
+ await resolveCreator (
387
+ mockOrganization ,
388
+ { } ,
389
+ ctx as unknown as ResolverContext ,
390
+ ) ;
391
+ } ) . rejects . toThrow (
392
+ new TalawaGraphQLError ( {
393
+ extensions : { code : "unauthorized_action" } ,
394
+ } ) ,
395
+ ) ;
396
+ } ) ;
397
+
381
398
describe ( "Error Handling" , ( ) => {
382
399
it ( "should throw unexpected error if creator user is not found" , async ( ) => {
383
400
const mockUser = createCompleteMockUser ( "administrator" ) ;
0 commit comments