From b2fcae611abb3028e09732143dbc42416b60b0e9 Mon Sep 17 00:00:00 2001 From: Jose Carlos Laura Ramirez Date: Sun, 1 Jun 2025 17:06:21 -0400 Subject: [PATCH 1/2] [TM-2049] add project short name column filter --- apps/entity-service/src/entities/dto/entity-query.dto.ts | 6 +++++- apps/entity-service/src/entities/dto/project.dto.ts | 3 +++ .../src/entities/processors/project.processor.ts | 6 +++++- libs/database/src/lib/entities/project.entity.ts | 4 ++++ 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/apps/entity-service/src/entities/dto/entity-query.dto.ts b/apps/entity-service/src/entities/dto/entity-query.dto.ts index a19b4b3e..97b0da9e 100644 --- a/apps/entity-service/src/entities/dto/entity-query.dto.ts +++ b/apps/entity-service/src/entities/dto/entity-query.dto.ts @@ -1,5 +1,5 @@ import { ApiProperty } from "@nestjs/swagger"; -import { IsArray, IsIn, IsInt, IsOptional, Max, Min, ValidateNested } from "class-validator"; +import { IsArray, IsIn, IsInt, IsOptional, IsString, Max, Min, ValidateNested } from "class-validator"; import { POLYGON_STATUSES_FILTERS, PolygonStatusFilter, @@ -102,6 +102,10 @@ export class EntityQueryDto extends IndexQueryDto { @TransformBooleanString({ optional: true }) nothingToReport?: boolean; + @ApiProperty({ required: false }) + @IsOptional() + shortName?: string; + // This one is internal use only, not exposed to the API surface taskId?: number; } diff --git a/apps/entity-service/src/entities/dto/project.dto.ts b/apps/entity-service/src/entities/dto/project.dto.ts index 4bcfbefd..17285595 100644 --- a/apps/entity-service/src/entities/dto/project.dto.ts +++ b/apps/entity-service/src/entities/dto/project.dto.ts @@ -54,6 +54,9 @@ export class ProjectLightDto extends EntityDto { @ApiProperty({ nullable: true, type: String }) name: string | null; + @ApiProperty({ nullable: true, type: String }) + shortName: string | null; + @ApiProperty({ nullable: true, type: Date }) plantingStartDate: Date | null; diff --git a/apps/entity-service/src/entities/processors/project.processor.ts b/apps/entity-service/src/entities/processors/project.processor.ts index 3f87c2f9..13f563ef 100644 --- a/apps/entity-service/src/entities/processors/project.processor.ts +++ b/apps/entity-service/src/entities/processors/project.processor.ts @@ -53,7 +53,7 @@ export class ProjectProcessor extends EntityProcessor< ]); if (query.sort?.field != null) { - if (["name", "plantingStartDate", "country"].includes(query.sort.field)) { + if (["name", "plantingStartDate", "country", "shortName"].includes(query.sort.field)) { builder.order([query.sort.field, query.sort.direction ?? "ASC"]); } else if (query.sort.field === "organisationName") { builder.order(["organisation", "name", query.sort.direction ?? "ASC"]); @@ -104,6 +104,10 @@ export class ProjectProcessor extends EntityProcessor< builder.where({ cohort: { [Op.in]: query.cohort } }); } + if (query.shortName != null) { + builder.where({ shortName: query.shortName }); + } + if (query.search != null || query.searchFilter != null) { builder.where({ name: { [Op.like]: `%${query.search ?? query.searchFilter}%` } }); } diff --git a/libs/database/src/lib/entities/project.entity.ts b/libs/database/src/lib/entities/project.entity.ts index b80f0581..22e96947 100644 --- a/libs/database/src/lib/entities/project.entity.ts +++ b/libs/database/src/lib/entities/project.entity.ts @@ -368,6 +368,10 @@ export class Project extends Model { @Column(INTEGER.UNSIGNED) directSeedingSurvivalRate: number | null; + @AllowNull + @Column(STRING) + shortName: string | null; + @BelongsTo(() => Organisation) organisation: Organisation | null; From 8985032221eaaaccc3655157d51edf99cb1d8830 Mon Sep 17 00:00:00 2001 From: Jose Carlos Laura Ramirez Date: Wed, 4 Jun 2025 14:35:01 -0400 Subject: [PATCH 2/2] [TM-2049] fix lint --- apps/entity-service/src/entities/dto/entity-query.dto.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/entity-service/src/entities/dto/entity-query.dto.ts b/apps/entity-service/src/entities/dto/entity-query.dto.ts index 97b0da9e..6089afeb 100644 --- a/apps/entity-service/src/entities/dto/entity-query.dto.ts +++ b/apps/entity-service/src/entities/dto/entity-query.dto.ts @@ -1,5 +1,5 @@ import { ApiProperty } from "@nestjs/swagger"; -import { IsArray, IsIn, IsInt, IsOptional, IsString, Max, Min, ValidateNested } from "class-validator"; +import { IsArray, IsIn, IsInt, IsOptional, Max, Min, ValidateNested } from "class-validator"; import { POLYGON_STATUSES_FILTERS, PolygonStatusFilter,