@idpass/data-collect-core / AssignmentService
Class: AssignmentService
Defined in: services/AssignmentService.ts:62
Service for managing user-to-area assignments and entity overrides.
Implements a hybrid assignment model:
- Area-based: users are assigned to areas, gaining access to all entities in those areas
- Per-entity overrides: specific entities can be explicitly included or excluded
Used by selective sync to determine which data a client should receive.
Constructors
Constructor
new AssignmentService(
connectionString,areaService):AssignmentService
Defined in: services/AssignmentService.ts:67
Parameters
connectionString
string
areaService
Returns
AssignmentService
Methods
initialize()
initialize():
Promise<void>
Defined in: services/AssignmentService.ts:76
Initializes the assignment tables in the database.
Returns
Promise<void>
assignUserToArea()
assignUserToArea(
userId,tenantId,areaId,role,includeDescendants?):Promise<UserAssignmentRecord>
Defined in: services/AssignmentService.ts:128
Assigns a user to an area with a specific role.
Parameters
userId
string
The user ID.
tenantId
string
The tenant ID.
areaId
string
The area ID to assign the user to.
role
string
The role to assign (from SystemRole enum).
includeDescendants?
boolean = true
Whether to include descendant areas (default true).
Returns
Promise<UserAssignmentRecord>
The created assignment record.
removeAssignment()
removeAssignment(
assignmentId):Promise<void>
Defined in: services/AssignmentService.ts:166
Removes an assignment by its ID.
Parameters
assignmentId
string
The assignment ID to remove.
Returns
Promise<void>
getUserAssignments()
getUserAssignments(
userId,tenantId):Promise<UserAssignmentRecord[]>
Defined in: services/AssignmentService.ts:179
Retrieves all assignments for a user within a tenant.
Parameters
userId
string
The user ID.
tenantId
string
The tenant ID.
Returns
Promise<UserAssignmentRecord[]>
Array of user assignment records.
getAssignedAreaIds()
getAssignedAreaIds(
userId,tenantId):Promise<string[]>
Defined in: services/AssignmentService.ts:210
Retrieves all area IDs a user has access to, including descendant areas where includeDescendants is true.
Parameters
userId
string
The user ID.
tenantId
string
The tenant ID.
Returns
Promise<string[]>
Array of area IDs the user can access.
addEntityOverride()
addEntityOverride(
entityGuid,userId,tenantId,action):Promise<EntityOverrideRecord>
Defined in: services/AssignmentService.ts:239
Adds a per-entity override (include or exclude) for a user.
Parameters
entityGuid
string
The entity GUID.
userId
string
The user ID.
tenantId
string
The tenant ID.
action
"include" or "exclude".
"include" | "exclude"
Returns
Promise<EntityOverrideRecord>
The created override record.
removeEntityOverride()
removeEntityOverride(
overrideId):Promise<void>
Defined in: services/AssignmentService.ts:272
Removes an entity override by its ID.
Parameters
overrideId
string
The override ID to remove.
Returns
Promise<void>
getEntityOverrides()
getEntityOverrides(
userId,tenantId):Promise<EntityOverrideRecord[]>
Defined in: services/AssignmentService.ts:285
Retrieves all entity overrides for a user within a tenant.
Parameters
userId
string
The user ID.
tenantId
string
The tenant ID.
Returns
Promise<EntityOverrideRecord[]>
Array of entity override records.
getAssignedEntityGuids()
getAssignedEntityGuids(
userId,tenantId):Promise<string[]>
Defined in: services/AssignmentService.ts:318
Computes the full set of entity GUIDs a user should have access to.
Logic:
- Get all area IDs the user is assigned to (including descendants).
- Query all entities whose data.area_id matches any of those area IDs.
- Apply overrides: add "include" entities, remove "exclude" entities.
Parameters
userId
string
The user ID.
tenantId
string
The tenant ID.
Returns
Promise<string[]>
Array of entity GUIDs the user should see.
clearStore()
clearStore():
Promise<void>
Defined in: services/AssignmentService.ts:357
Clears all assignment and override data.
Returns
Promise<void>
closeConnection()
closeConnection():
Promise<void>
Defined in: services/AssignmentService.ts:365
Closes the database connection pool.
Returns
Promise<void>