|
|
|
@ -11,7 +11,7 @@ import {
@@ -11,7 +11,7 @@ import {
|
|
|
|
|
USERS_REPOSITORY, |
|
|
|
|
} from '../consts' |
|
|
|
|
import { IUsersRepository } from '../interfaces' |
|
|
|
|
import _ from 'lodash' |
|
|
|
|
import * as _ from 'lodash' |
|
|
|
|
|
|
|
|
|
@Injectable() |
|
|
|
|
export class UsersListService { |
|
|
|
@ -21,9 +21,9 @@ export class UsersListService {
@@ -21,9 +21,9 @@ export class UsersListService {
|
|
|
|
|
const query = this.usersRepository |
|
|
|
|
.createQueryBuilder('it') |
|
|
|
|
.leftJoinAndSelect('it.info', 'info') |
|
|
|
|
.leftJoinAndSelect('it.factories', 'factories') |
|
|
|
|
|
|
|
|
|
this.addSearchStringToQuery(query, pagination.searchString, params.searchFields) |
|
|
|
|
console.log(query.getQueryAndParameters()) |
|
|
|
|
this.addSearchStringToQuery(query, pagination.searchString, params) |
|
|
|
|
await this.addSearchParams(query, params) |
|
|
|
|
|
|
|
|
|
const { items, count } = await paginateAndGetMany(query, pagination, 'it') |
|
|
|
@ -35,28 +35,66 @@ export class UsersListService {
@@ -35,28 +35,66 @@ export class UsersListService {
|
|
|
|
|
private addSearchStringToQuery( |
|
|
|
|
query: SelectQueryBuilder<Users.UserModel>, |
|
|
|
|
searchString: string, |
|
|
|
|
params: Users.IGetUsersListParams['searchFields'], |
|
|
|
|
params: Users.IGetUsersListParams, |
|
|
|
|
) { |
|
|
|
|
if (!searchString || _.isEmpty(params)) return null |
|
|
|
|
if (searchString) { |
|
|
|
|
const toSearch = `%${searchString}%` |
|
|
|
|
|
|
|
|
|
const toSearch = `%${!searchString ? '' : searchString}%` |
|
|
|
|
query.andWhere( |
|
|
|
|
new Brackets(subQuery => { |
|
|
|
|
subQuery.where('info.firstName ILIKE :search', { search: toSearch }) |
|
|
|
|
subQuery.orWhere('info.lastName ILIKE :search', { search: toSearch }) |
|
|
|
|
subQuery.orWhere('info.middleName ILIKE :search', { search: toSearch }) |
|
|
|
|
subQuery.orWhere('it.email ILIKE :search', { search: toSearch }) |
|
|
|
|
subQuery.orWhere('it.login ILIKE :search', { search: toSearch }) |
|
|
|
|
subQuery.orWhere('it.status ILIKE :search', { search: toSearch }) |
|
|
|
|
subQuery.orWhere('it.loginOnDesktopDate ILIKE :search', { search: toSearch }) |
|
|
|
|
subQuery.orWhere('it.loginOnMobileDate ILIKE :search', { search: toSearch }) |
|
|
|
|
subQuery.orWhere('info.position ILIKE :search', { search: toSearch }) |
|
|
|
|
subQuery.orWhere('it.phoneNumber ILIKE :search', { search: toSearch }) |
|
|
|
|
}), |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (_.isEmpty(params)) return null |
|
|
|
|
console.log('params', params) |
|
|
|
|
query.andWhere( |
|
|
|
|
new Brackets(subQuery => { |
|
|
|
|
subQuery.where( |
|
|
|
|
new Brackets(qb => { |
|
|
|
|
qb.where('info.firstName ILIKE :search', { search: toSearch }) |
|
|
|
|
if (params.firstName) |
|
|
|
|
qb.andWhere('info.firstName ILIKE :firstName', { |
|
|
|
|
firstName: params.firstName, |
|
|
|
|
}) |
|
|
|
|
}), |
|
|
|
|
) |
|
|
|
|
subQuery.orWhere('info.lastName ILIKE :search', { search: toSearch }) |
|
|
|
|
subQuery.orWhere('info.middleName ILIKE :search', { search: toSearch }) |
|
|
|
|
subQuery.orWhere('info.position ILIKE :search', { search: toSearch }) |
|
|
|
|
subQuery.orWhere('it.phoneNumber ILIKE :search', { search: toSearch }) |
|
|
|
|
subQuery.orWhere('it.email ILIKE :search', { search: toSearch }) |
|
|
|
|
if (params.firstName) { |
|
|
|
|
console.log(`%${params.firstName}%`) |
|
|
|
|
subQuery.andWhere('info.firstName ILIKE :firstName', { |
|
|
|
|
firstName: `%${params.firstName}%`, |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
if (params.lastName) { |
|
|
|
|
subQuery.andWhere('info.lastName ILIKE :lastName', { |
|
|
|
|
lastName: params.lastName, |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
if (params.middleName) { |
|
|
|
|
subQuery.andWhere('info.middleName ILIKE :middleName', { |
|
|
|
|
middleName: params.middleName, |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
if (params.email) { |
|
|
|
|
subQuery.andWhere('it.email ILIKE :email', { email: params.email }) |
|
|
|
|
} |
|
|
|
|
if (params.login) { |
|
|
|
|
subQuery.andWhere('it.login ILIKE :login', { login: params.login }) |
|
|
|
|
} |
|
|
|
|
if (params.status) { |
|
|
|
|
subQuery.andWhere('it.status ILIKE :status', { status: params.status }) |
|
|
|
|
} |
|
|
|
|
if (params.loginOnDesktopDate) { |
|
|
|
|
subQuery.andWhere('it.loginOnDesktopDate ILIKE :loginOnDesktopDate', { |
|
|
|
|
loginOnDesktopDate: params.loginOnDesktopDate, |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
if (params.loginOnMobileDate) { |
|
|
|
|
subQuery.andWhere('it.loginOnMobileDate ILIKE :loginOnMobileDate', { |
|
|
|
|
loginOnMobileDate: params.loginOnMobileDate, |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
}), |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|