feat(auth): add user and role management
This commit is contained in:
26
packages/backend/src/graphql/queries/get-users.ts
Normal file
26
packages/backend/src/graphql/queries/get-users.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import Context from '../../types/express/context';
|
||||
import paginate from '../../helpers/pagination';
|
||||
import User from '../../models/user';
|
||||
|
||||
type Params = {
|
||||
limit: number;
|
||||
offset: number;
|
||||
};
|
||||
|
||||
const getUsers = async (_parent: unknown, params: Params, context: Context) => {
|
||||
context.currentUser.can('read', 'User');
|
||||
|
||||
const usersQuery = User
|
||||
.query()
|
||||
.leftJoinRelated({
|
||||
role: true
|
||||
})
|
||||
.withGraphFetched({
|
||||
role: true
|
||||
})
|
||||
.orderBy('full_name', 'desc');
|
||||
|
||||
return paginate(usersQuery, params.limit, params.offset);
|
||||
};
|
||||
|
||||
export default getUsers;
|
Reference in New Issue
Block a user