import { PaginationRequest } from '@libs/pagination' ; import { EntityRepository , Repository } from 'typeorm' ; import { RoleEntity } from './role.entity' ; @ EntityRepository ( RoleEntity ) export class RolesRepository extends Repository < RoleEntity > { param pagination { PaginationRequest } returns public async getRolesAndCount ( pagination ) { const { skip , limit : take , order , params : { search } , } = pagination ; const query = this . createQueryBuilder ( 'r' ) . innerJoinAndSelect ( 'r.permissions' , 'p' ) . skip ( skip ) . take ( take ) . orderBy ( order ) ; if ( search ) { query . where ( 'name ILIKE :search' , { search : `%${ search }%` } ) ; } return query . getManyAndCount ( ) ; } }