@directus/api
Version:
Directus is a real-time API and App dashboard for managing SQL database content
18 lines (17 loc) • 799 B
JavaScript
export function getUserCountQuery(knex, options) {
// Safety check for an empty list of includeRoles, which would otherwise return all users
if (options.includeRoles && options.includeRoles.length === 0) {
return Promise.resolve({ count: 0 });
}
let query = knex('directus_users').count({ count: '*' }).as('count').where('status', '=', 'active');
if (options.excludeIds && options.excludeIds.length > 0) {
query = query.whereNotIn('id', options.excludeIds);
}
if (options.excludeRoles && options.excludeRoles.length > 0) {
query = query.whereNotIn('role', options.excludeRoles);
}
if (options.includeRoles && options.includeRoles.length > 0) {
query = query.whereIn('role', options.includeRoles);
}
return query.first();
}