From 60df57ceb28b05d42204622ae9fdefea8d44d588 Mon Sep 17 00:00:00 2001 From: IlhamTahir Date: Wed, 25 Dec 2024 10:27:14 +0800 Subject: [PATCH] fix --- src/article/dto/search-category.filter.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/article/dto/search-category.filter.ts b/src/article/dto/search-category.filter.ts index f34b9cf..e0cd53b 100644 --- a/src/article/dto/search-category.filter.ts +++ b/src/article/dto/search-category.filter.ts @@ -1,7 +1,21 @@ import { BaseFilter } from '../../core/dto/base.filter'; import { ApiProperty } from '@nestjs/swagger'; +import { IsOptional } from 'class-validator'; +import { Like } from 'typeorm'; export class SearchCategoryFilter extends BaseFilter { @ApiProperty() order = ['+order', '-createdTime']; + + @ApiProperty({ required: false, description: '分类名称检索', example: '猫' }) + @IsOptional() + name?: string; + + getConditions(): Record { + const conditions: Record = {}; + if (this.name) { + conditions.name = Like(`%${this.name}%`); // 假设使用模糊查询 + } + return conditions; + } }