Skip to content

Commit c4a7fbb

Browse files
committed
Update OrganizationMemberRepository.java
1 parent 24902c5 commit c4a7fbb

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

org-service/src/main/java/com/codecampus/organization/repository/OrganizationMemberRepository.java

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,40 @@
1414
@Repository
1515
public interface OrganizationMemberRepository
1616
extends JpaRepository<OrganizationMember, String> {
17+
@Query(value = """
18+
select m.*
19+
from organization_members m
20+
join organizations o on o.id = m.scope_id
21+
where m.user_id = :userId
22+
and m.scope_type = :scopeType
23+
and m.is_active = true
24+
and m.is_primary = true
25+
and m.deleted_at is null
26+
and o.deleted_at is null
27+
order by m.created_at asc
28+
limit 1
29+
""", nativeQuery = true)
1730
Optional<OrganizationMember> findFirstByUserIdAndScopeTypeAndIsActiveIsTrueAndIsPrimaryIsTrueOrderByCreatedAtAsc(
18-
String userId, ScopeType scopeType);
31+
@Param("userId") String userId,
32+
@Param("scopeType") ScopeType scopeType
33+
);
34+
1935

36+
@Query(value = """
37+
select m.*
38+
from organization_members m
39+
join organizations o on o.id = m.scope_id
40+
where m.user_id = :userId
41+
and m.scope_type = :scopeType
42+
and m.is_active = true
43+
and m.deleted_at is null
44+
and o.deleted_at is null
45+
order by m.created_at asc
46+
""", nativeQuery = true)
2047
List<OrganizationMember> findByUserIdAndScopeTypeAndIsActiveIsTrue(
21-
String userId, ScopeType scopeType);
48+
@Param("userId") String userId,
49+
@Param("scopeType") ScopeType scopeType
50+
);
2251

2352
List<OrganizationMember> findByScopeTypeAndScopeIdAndIsActiveIsTrue(
2453
ScopeType scopeType, String scopeId);

0 commit comments

Comments
 (0)