-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from wri/feat/TM-1453-bulk-update-indicators
[TM-1453] Bulk update indicators
- Loading branch information
Showing
8 changed files
with
468 additions
and
193 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 33 additions & 26 deletions
59
apps/research-service/src/site-polygons/dto/site-polygon-update.dto.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,55 @@ | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
import { | ||
IndicatorFieldMonitoringDto, | ||
IndicatorHectaresDto, IndicatorMsuCarbonDto, | ||
IndicatorTreeCountDto, IndicatorTreeCoverDto, | ||
IndicatorTreeCoverLossDto | ||
} from './indicators.dto'; | ||
import { ApiProperty } from "@nestjs/swagger"; | ||
import { IndicatorDto } from "./site-polygon.dto"; | ||
import { Equals, IsArray, IsUUID, ValidateNested } from "class-validator"; | ||
import { Type } from "class-transformer"; | ||
import { INDICATOR_DTOS } from "./indicators.dto"; | ||
|
||
class SitePolygonUpdateAttributes { | ||
@IsArray() | ||
@ValidateNested() | ||
@Type(() => Object, { | ||
keepDiscriminatorProperty: true, | ||
discriminator: { | ||
property: "indicatorSlug", | ||
subTypes: Object.entries(INDICATOR_DTOS).map(([name, value]) => ({ name, value })) | ||
} | ||
}) | ||
@ApiProperty({ | ||
type: 'array', | ||
type: "array", | ||
items: { | ||
oneOf: [ | ||
{ $ref: '#/components/schemas/IndicatorTreeCoverLossDto' }, | ||
{ $ref: '#/components/schemas/IndicatorHectaresDto' }, | ||
{ $ref: '#/components/schemas/IndicatorTreeCountDto' }, | ||
{ $ref: '#/components/schemas/IndicatorTreeCoverDto' }, | ||
{ $ref: '#/components/schemas/IndicatorFieldMonitoringDto' }, | ||
{ $ref: '#/components/schemas/IndicatorMsuCarbonDto' }, | ||
{ $ref: "#/components/schemas/IndicatorTreeCoverLossDto" }, | ||
{ $ref: "#/components/schemas/IndicatorHectaresDto" }, | ||
{ $ref: "#/components/schemas/IndicatorTreeCountDto" }, | ||
{ $ref: "#/components/schemas/IndicatorTreeCoverDto" }, | ||
{ $ref: "#/components/schemas/IndicatorFieldMonitoringDto" }, | ||
{ $ref: "#/components/schemas/IndicatorMsuCarbonDto" } | ||
] | ||
}, | ||
description: 'All indicators to update for this polygon' | ||
description: "All indicators to update for this polygon" | ||
}) | ||
indicators: ( | ||
IndicatorTreeCoverLossDto | | ||
IndicatorHectaresDto | | ||
IndicatorTreeCountDto | | ||
IndicatorTreeCoverDto | | ||
IndicatorFieldMonitoringDto | | ||
IndicatorMsuCarbonDto | ||
)[]; | ||
indicators: IndicatorDto[]; | ||
} | ||
|
||
class SitePolygonUpdate { | ||
@ApiProperty({ enum: ['sitePolygons'] }) | ||
type: 'sitePolygons'; | ||
@Equals("sitePolygons") | ||
@ApiProperty({ enum: ["sitePolygons"] }) | ||
type: string; | ||
|
||
@ApiProperty({ format: 'uuid' }) | ||
@IsUUID() | ||
@ApiProperty({ format: "uuid" }) | ||
id: string; | ||
|
||
@ValidateNested() | ||
@Type(() => SitePolygonUpdateAttributes) | ||
@ApiProperty({ type: () => SitePolygonUpdateAttributes }) | ||
attributes: SitePolygonUpdateAttributes; | ||
} | ||
|
||
export class SitePolygonBulkUpdateBodyDto { | ||
@IsArray() | ||
@ValidateNested() | ||
@Type(() => SitePolygonUpdate) | ||
@ApiProperty({ isArray: true, type: () => SitePolygonUpdate }) | ||
data: SitePolygonUpdate[]; | ||
} |
Oops, something went wrong.