From fdc6af9e20a3c20f5859ea2ce3ab02c808ebf0ea Mon Sep 17 00:00:00 2001 From: louis <869322496@qq.com> Date: Thu, 28 Mar 2024 14:35:00 +0800 Subject: [PATCH] feat: users filter --- README.md | 2 +- src/modules/user/dto/user.dto.ts | 5 +++++ src/modules/user/user.service.ts | 13 +++++++++++-- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 04406fe..f08f061 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,7 @@ docker rmi huaxin-admin-server:stable ```bash pnpm docker:logs # or -docker compose --env-file .env --env-file .env.production logs -f +docker-compose --env-file .env --env-file .env.production logs -f ``` diff --git a/src/modules/user/dto/user.dto.ts b/src/modules/user/dto/user.dto.ts index 3b2c3c7..f7efc73 100644 --- a/src/modules/user/dto/user.dto.ts +++ b/src/modules/user/dto/user.dto.ts @@ -95,4 +95,9 @@ export class UserQueryDto extends IntersectionType(PagerDto, PartialTyp @IsInt() @IsOptional() status?: number; + + @ApiProperty({ description: '关键字' }) + @IsString() + @IsOptional() + keyword?: string; } diff --git a/src/modules/user/user.service.ts b/src/modules/user/user.service.ts index a3a2867..afb8345 100644 --- a/src/modules/user/user.service.ts +++ b/src/modules/user/user.service.ts @@ -249,7 +249,8 @@ export class UserService { nickname, deptId, email, - status + status, + keyword }: UserQueryDto): Promise> { const queryBuilder = this.userRepository .createQueryBuilder('user') @@ -264,7 +265,15 @@ export class UserService { }); if (deptId) queryBuilder.andWhere('dept.id = :deptId', { deptId }); - + if (keyword) { + //关键字模糊查询product的name,productNumber,productSpecification + queryBuilder.andWhere( + '(user.name like :keyword or dept.name like :keyword)', + { + keyword: `%${keyword}%` + } + ); + } return paginate(queryBuilder, { page, pageSize