import { PaginationRequest } from '@libs/pagination' ; import { EntityRepository , Repository } from 'typeorm' ; import { UserEntity } from './user.entity' ; @ EntityRepository ( UserEntity ) export class UsersRepository extends Repository < UserEntity > { param pagination { PaginationRequest } returns public async getUsersAndCount ( pagination ) { const { skip , limit : take , order , params : { search } , } = pagination ; const query = this . createQueryBuilder ( 'u' ) . innerJoinAndSelect ( 'u.roles' , 'r' ) . leftJoinAndSelect ( 'u.permissions' , 'p' ) . skip ( skip ) . take ( take ) . orderBy ( order ) ; if ( search ) { query . where ( `
            u.username ILIKE :search
            OR u.first_name ILIKE :search
            OR u.last_name ILIKE :search
            ` , { search : `%${ search }%` } ) ; } return query . getManyAndCount ( ) ; } param username { string } returns async findUserByUsername ( username ) { return this . createQueryBuilder ( 'u' ) . leftJoinAndSelect ( 'u.roles' , 'r' , 'r.active = true' ) . leftJoinAndSelect ( 'r.permissions' , 'rp' , 'rp.active = true' ) . leftJoinAndSelect ( 'u.permissions' , 'p' , 'p.active = true' ) . where ( 'u.username = :username' , { username } ) . getOne ( ) ; } }