Service Layer medium complexity backend
2
Dependencies
1
Dependents
4
Entities
0
Integrations

Description

Backend service managing CRUD operations for user-organization memberships stored in user_organization_roles. Handles assignment, transfer, and removal of users from organizational hierarchy nodes, enforces multi-membership rules (up to 5 simultaneous memberships per NHF requirements), emits audit log events on every membership change, and validates that bulk reassignment preserves data scoping integrity.

Feature: Member Associations

member-association-service

Sources & reasoning

The implementation notes explicitly describe this service: user_organization_roles with composite key, user-centric and org-centric queries, bulk reassignment for restructuring, audit log emission on changes, and implicit deactivation when removed from all nodes. This is the core business logic component mandated by the blueprint.

No source references — this artifact was included based on reasoning alone (see above).

Responsibilities

  • Create and remove membership records in user_organization_roles with composite key (user_id, organization_id, role)
  • Enforce per-user membership cap and validate that the target organization node exists in the hierarchy
  • Perform bulk reassignment of multiple users to a new hierarchy node in a single transaction
  • Emit structured audit log events on every membership change (assign, transfer, remove)
  • Deactivate platform access implicitly when a user is removed from all organization nodes

Interfaces

assignMembership(userId: string, organizationId: string, role: string): Promise<MembershipRecord>
removeMembership(userId: string, organizationId: string): Promise<void>
transferMembership(userId: string, fromOrgId: string, toOrgId: string): Promise<MembershipRecord>
bulkReassign(userIds: string[], targetOrgId: string): Promise<BulkReassignResult>
getUserMemberships(userId: string): Promise<MembershipRecord[]>
getOrgMembers(organizationId: string): Promise<MembershipRecord[]>
deactivateIfNoMemberships(userId: string): Promise<void>

Relationships

Dependencies (2)

Components this component depends on

Dependents (1)

Components that depend on this component