@@ -9,7 +9,7 @@ import { prisma } from "@/prisma";
99import { StatusCodes } from "http-status-codes" ;
1010import { ErrorCode } from "@/lib/errorCodes" ;
1111
12- export const joinOrganization = ( orgId : number , inviteLinkId : string ) => sew ( async ( ) =>
12+ export const joinOrganization = ( orgId : number , inviteLinkId ? : string ) => sew ( async ( ) =>
1313 withAuth ( async ( userId ) => {
1414 const org = await prisma . org . findUnique ( {
1515 where : {
@@ -21,20 +21,23 @@ export const joinOrganization = (orgId: number, inviteLinkId: string) => sew(asy
2121 return orgNotFound ( ) ;
2222 }
2323
24- if ( ! org . inviteLinkEnabled ) {
25- return {
26- statusCode : StatusCodes . BAD_REQUEST ,
27- errorCode : ErrorCode . INVITE_LINK_NOT_ENABLED ,
28- message : "Invite link is not enabled." ,
29- } satisfies ServiceError ;
30- }
24+ // If member approval is required we must be using a valid invite link
25+ if ( org . memberApprovalRequired ) {
26+ if ( ! org . inviteLinkEnabled ) {
27+ return {
28+ statusCode : StatusCodes . BAD_REQUEST ,
29+ errorCode : ErrorCode . INVITE_LINK_NOT_ENABLED ,
30+ message : "Invite link is not enabled." ,
31+ } satisfies ServiceError ;
32+ }
3133
32- if ( org . inviteLinkId !== inviteLinkId ) {
33- return {
34- statusCode : StatusCodes . BAD_REQUEST ,
35- errorCode : ErrorCode . INVALID_INVITE_LINK ,
36- message : "Invalid invite link." ,
37- } satisfies ServiceError ;
34+ if ( org . inviteLinkId !== inviteLinkId ) {
35+ return {
36+ statusCode : StatusCodes . BAD_REQUEST ,
37+ errorCode : ErrorCode . INVALID_INVITE_LINK ,
38+ message : "Invalid invite link." ,
39+ } satisfies ServiceError ;
40+ }
3841 }
3942
4043 const addUserToOrgRes = await addUserToOrganization ( userId , org . id ) ;
0 commit comments