fix: 分页查询时查询条件的number类型空值处理
This commit is contained in:
parent
5b562e1d3b
commit
2821dc6dad
|
@ -19,7 +19,7 @@ DB_DATABASE = hxoa
|
|||
DB_USERNAME = root
|
||||
DB_PASSWORD = huaxin123
|
||||
DB_SYNCHRONIZE = true
|
||||
DB_LOGGING = ["error"]
|
||||
DB_LOGGING = "all"
|
||||
|
||||
# redis
|
||||
REDIS_PORT = 6379
|
||||
|
|
|
@ -2,7 +2,7 @@ import { InjectRedis } from '@liaoliaots/nestjs-redis'
|
|||
import { Injectable } from '@nestjs/common'
|
||||
import { InjectRepository } from '@nestjs/typeorm'
|
||||
import Redis from 'ioredis'
|
||||
import { concat, isEmpty, uniq } from 'lodash'
|
||||
import { concat, isEmpty, isNumber, uniq } from 'lodash'
|
||||
|
||||
import { In, IsNull, Like, Not, Repository } from 'typeorm'
|
||||
|
||||
|
@ -45,7 +45,7 @@ export class MenuService {
|
|||
...(path && { path: Like(`%${path}%`) }),
|
||||
...(permission && { permission: Like(`%${permission}%`) }),
|
||||
...(component && { component: Like(`%${component}%`) }),
|
||||
...(status && { status }),
|
||||
...(isNumber(status) ? { status } : null),
|
||||
},
|
||||
order: { orderNo: 'ASC' },
|
||||
})
|
||||
|
|
|
@ -19,7 +19,7 @@ import { RoleEntity } from '~/modules/system/role/role.entity'
|
|||
|
||||
import { MenuService } from '../menu/menu.service'
|
||||
|
||||
import { RoleDto, RoleUpdateDto } from './role.dto'
|
||||
import { RoleDto, RoleQueryDto, RoleUpdateDto } from './role.dto'
|
||||
import { RoleInfo } from './role.model'
|
||||
import { RoleService } from './role.service'
|
||||
|
||||
|
@ -44,7 +44,7 @@ export class RoleController {
|
|||
@ApiOperation({ summary: '获取角色列表' })
|
||||
@ApiResult({ type: [RoleEntity], isPage: true })
|
||||
@Perm(permissions.LIST)
|
||||
async list(@Query() dto: PagerDto) {
|
||||
async list(@Query() dto: RoleQueryDto) {
|
||||
return this.roleService.findAll(dto)
|
||||
}
|
||||
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
import { ApiProperty, PartialType } from '@nestjs/swagger'
|
||||
import { ApiProperty, IntersectionType, PartialType } from '@nestjs/swagger'
|
||||
import {
|
||||
IsArray,
|
||||
IsIn,
|
||||
IsInt,
|
||||
IsOptional,
|
||||
IsString,
|
||||
Matches,
|
||||
MinLength,
|
||||
} from 'class-validator'
|
||||
import { PagerDto } from '~/common/dto/pager.dto'
|
||||
|
||||
export class RoleDto {
|
||||
@ApiProperty({ description: '角色名称' })
|
||||
|
@ -36,3 +38,11 @@ export class RoleDto {
|
|||
}
|
||||
|
||||
export class RoleUpdateDto extends PartialType(RoleDto) {}
|
||||
export class RoleQueryDto extends IntersectionType(PagerDto<RoleDto>, PartialType(RoleDto)) {
|
||||
|
||||
@ApiProperty({ description: '状态', example: 0, required: false })
|
||||
@IsInt()
|
||||
@IsOptional()
|
||||
status?: number
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { Injectable } from '@nestjs/common'
|
||||
import { InjectEntityManager, InjectRepository } from '@nestjs/typeorm'
|
||||
import { isEmpty } from 'lodash'
|
||||
import { EntityManager, In, Repository } from 'typeorm'
|
||||
import { isEmpty, isNumber } from 'lodash'
|
||||
import { EntityManager, In, Like, Repository } from 'typeorm'
|
||||
|
||||
import { PagerDto } from '~/common/dto/pager.dto'
|
||||
import { ROOT_ROLE_ID } from '~/constants/system.constant'
|
||||
|
@ -11,7 +11,7 @@ import { SseService } from '~/modules/sse/sse.service'
|
|||
import { MenuEntity } from '~/modules/system/menu/menu.entity'
|
||||
import { RoleEntity } from '~/modules/system/role/role.entity'
|
||||
|
||||
import { RoleDto, RoleUpdateDto } from './role.dto'
|
||||
import { RoleDto, RoleQueryDto, RoleUpdateDto } from './role.dto'
|
||||
|
||||
@Injectable()
|
||||
export class RoleService {
|
||||
|
@ -31,8 +31,22 @@ export class RoleService {
|
|||
async findAll({
|
||||
page,
|
||||
pageSize,
|
||||
}: PagerDto): Promise<Pagination<RoleEntity>> {
|
||||
return paginate(this.roleRepository, { page, pageSize })
|
||||
name,
|
||||
value,
|
||||
status,
|
||||
}: RoleQueryDto): Promise<Pagination<RoleEntity>> {
|
||||
const queryBuilder = this.roleRepository
|
||||
.createQueryBuilder('role')
|
||||
.where({
|
||||
...(name ? { name: Like(`%${name}%`) } : null),
|
||||
...(value ? { value: Like(`%${value}%`) } : null),
|
||||
...(isNumber(status) ? { status } : null),
|
||||
})
|
||||
|
||||
return paginate<RoleEntity>(queryBuilder, {
|
||||
page,
|
||||
pageSize,
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -12,7 +12,7 @@ import { UnknownElementException } from '@nestjs/core/errors/exceptions/unknown-
|
|||
import { InjectRepository } from '@nestjs/typeorm'
|
||||
import { Queue } from 'bull'
|
||||
import Redis from 'ioredis'
|
||||
import { isEmpty } from 'lodash'
|
||||
import { isEmpty, isNumber } from 'lodash'
|
||||
import { Like, Repository } from 'typeorm'
|
||||
|
||||
import { BusinessException } from '~/common/exceptions/biz.exception'
|
||||
|
@ -103,7 +103,7 @@ export class TaskService implements OnModuleInit {
|
|||
...(name ? { name: Like(`%${name}%`) } : null),
|
||||
...(service ? { service: Like(`%${service}%`) } : null),
|
||||
...(type ? { type } : null),
|
||||
...(status ? { status } : null),
|
||||
...(isNumber(status) ? { status } : null),
|
||||
})
|
||||
.orderBy('task.id', 'ASC')
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ export class UserDto {
|
|||
@ApiProperty({ description: '登录账号', example: 'admin' })
|
||||
@IsString()
|
||||
@Matches(/^[a-z0-9A-Z\W_]+$/)
|
||||
@MinLength(4)
|
||||
@MinLength(1)
|
||||
@MaxLength(20)
|
||||
username: string
|
||||
|
||||
|
@ -95,4 +95,5 @@ export class UserQueryDto extends IntersectionType(PagerDto<UserDto>, PartialTyp
|
|||
@IsInt()
|
||||
@IsOptional()
|
||||
status?: number
|
||||
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ import { InjectRedis } from '@liaoliaots/nestjs-redis'
|
|||
import { BadRequestException, Injectable } from '@nestjs/common'
|
||||
import { InjectEntityManager, InjectRepository } from '@nestjs/typeorm'
|
||||
import Redis from 'ioredis'
|
||||
import { isEmpty, isNil } from 'lodash'
|
||||
import { isEmpty, isNil, isNumber } from 'lodash'
|
||||
|
||||
import { EntityManager, In, Like, Repository } from 'typeorm'
|
||||
|
||||
|
@ -281,7 +281,7 @@ export class UserService {
|
|||
...(username ? { username: Like(`%${username}%`) } : null),
|
||||
...(nickname ? { nickname: Like(`%${nickname}%`) } : null),
|
||||
...(email ? { email: Like(`%${email}%`) } : null),
|
||||
...(status ? { status } : null),
|
||||
...(isNumber(status) ? { status } : null),
|
||||
})
|
||||
|
||||
if (deptId)
|
||||
|
|
Loading…
Reference in New Issue