User Management Operations
This section documents the GraphQL operations available for managing user accounts in the CRM system.
Queries​
users​
Retrieves a paginated list of users with filtering, sorting, and pagination capabilities.
Query​
query Users(
$limit: Int
$offset: Int
$order: OrderDirection
$orderBy: String
$filter: UsersFilterInput
) {
users(
limit: $limit
offset: $offset
order: $order
orderBy: $orderBy
filter: $filter
) {
data {
id
username
email
createdAt
updatedAt
avatar
phoneNumber
isEmailVerified
emailVerifiedAt
status
# Additional fields as needed
}
count
limit
offset
}
}
Arguments​
Name | Type | Description | Required | Default |
---|---|---|---|---|
limit | Int | Maximum number of items to return | No | 10 |
offset | Int | Number of items to skip | No | 0 |
order | OrderDirection | Sort order (ASC/DESC) | No | ASC |
orderBy | String | Field to sort by | No | createdAt |
filter | UsersFilterInput | Filter criteria | No | - |
UsersFilterInput​
input UsersFilterInput {
query: String
email: String
# Additional filter fields
}
Response​
Returns a UsersPaginationBoResponse
containing an array of UserBoModel
instances and pagination metadata.
user​
Retrieves detailed information about a specific user by ID.
Query​
query User($id: ID!) {
user(id: $id) {
id
username
email
createdAt
updatedAt
avatar
phoneNumber
isEmailVerified
emailVerifiedAt
status
sessions {
all {
id
sessionId
deviceName
deviceType
browser
operatingSystem
ipAddress
country
region
city
isActive
createdAt
updatedAt
lastActiveAt
}
aggregatedInfo {
totalLogins
}
first {
id
createdAt
}
last {
id
createdAt
}
}
overlapIPUsers {
id
username
email
}
# Additional fields as needed
}
}
Arguments​
Name | Type | Description | Required |
---|---|---|---|
id | ID! | ID of the user to retrieve | Yes |
Response​
Returns a UserBoModel
instance with detailed user information, including nested data like sessions and related users.
Mutations​
blockUsers​
Blocks multiple users by setting their status to BLOCKED
.
Mutation​
mutation BlockUsers($ids: [ID!]!) {
blockUsers(ids: $ids)
}
Arguments​
Name | Type | Description | Required |
---|---|---|---|
ids | [ID!]! | Array of user IDs to block | Yes |
Response​
Returns a boolean indicating whether the operation was successful.
activeUsers​
Activates multiple users by setting their status to ACTIVE
.
Mutation​
mutation ActiveUsers($ids: [ID!]!) {
activeUsers(ids: $ids)
}
Arguments​
Name | Type | Description | Required |
---|---|---|---|
ids | [ID!]! | Array of user IDs to activate | Yes |
Response​
Returns a boolean indicating whether the operation was successful.
Error Handling​
Common Errors​
Error Code | Description | Resolution |
---|---|---|
UNAUTHORIZED | User is not authorized to perform the operation | Ensure the user has the proper CRM role (BO) |
RESOURCE_NOT_FOUND | User with specified ID not found | Verify the user ID exists |
INVALID_ARGUMENTS | Invalid arguments provided | Check the provided arguments against the schema |
Example Error Response​
{
"errors": [
{
"message": "User not found",
"locations": [
{
"line": 2,
"column": 3
}
],
"path": ["user"],
"extensions": {
"code": "RESOURCE_NOT_FOUND"
}
}
],
"data": {
"user": null
}
}
Usage Examples​
Fetching Users with Pagination and Filtering​
const GET_USERS = gql`
query GetUsers($limit: Int, $offset: Int, $filter: UsersFilterInput) {
users(limit: $limit, offset: $offset, filter: $filter) {
data {
id
username
email
status
}
count
limit
offset
}
}
`;
// Example usage
const { data, loading, error } = useQuery(GET_USERS, {
variables: {
limit: 20,
offset: 0,
filter: { query: 'john' },
},
});
Blocking Users​
const BLOCK_USERS = gql`
mutation BlockUsers($ids: [ID!]!) {
blockUsers(ids: $ids)
}
`;
// Example usage
const [blockUsers] = useMutation(BLOCK_USERS);
blockUsers({ variables: { ids: ['user1', 'user2'] } });