IlhamTahir 1 年間 前
コミット
60df57ceb2
1 ファイル変更14 行追加0 行削除
  1. 14 0
      src/article/dto/search-category.filter.ts

+ 14 - 0
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<string, any> {
+    const conditions: Record<string, any> = {};
+    if (this.name) {
+      conditions.name = Like(`%${this.name}%`); // 假设使用模糊查询
+    }
+    return conditions;
+  }
 }