-
Notifications
You must be signed in to change notification settings - Fork 0
[TM-2768] add site polygon bulk status update #464
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: staging
Are you sure you want to change the base?
Changes from all commits
5b5a225
5f00005
685a845
0143758
4496c0f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import { ApiProperty } from "@nestjs/swagger"; | ||
| import { Equals, IsOptional, IsString, IsUUID } from "class-validator"; | ||
| import { JsonApiBulkBodyDto } from "@terramatch-microservices/common/util/json-api-update-dto"; | ||
|
|
||
| export class SitePolygonStatusUpdate { | ||
| @Equals("sitePolygons") | ||
| @ApiProperty({ enum: ["sitePolygons"] }) | ||
| type: string; | ||
|
|
||
| @IsUUID() | ||
| @ApiProperty({ format: "uuid" }) | ||
| id: string; | ||
| } | ||
|
|
||
| export class SitePolygonStatusBulkUpdateBodyDto extends JsonApiBulkBodyDto(SitePolygonStatusUpdate, { | ||
| description: "Array of site polygons to update", | ||
| minSize: 1, | ||
| minSizeMessage: "At least one site polygon must be provided", | ||
| example: [{ id: "123e4567-e89b-12d3-a456-426614174000" }, { id: "123e4567-e89b-12d3-a456-426614174001" }] | ||
| }) { | ||
| @IsOptional() | ||
| @IsString() | ||
| @ApiProperty({ description: "Comment for the status update", required: false, type: String }) | ||
| comment: string | null = null; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -64,6 +64,7 @@ import { GeoJsonQueryDto } from "../geojson-export/dto/geojson-query.dto"; | |
| import { GeoJsonExportDto } from "../geojson-export/dto/geojson-export.dto"; | ||
| import { GeometryUploadComparisonSummaryDto } from "./dto/geometry-upload-comparison-summary.dto"; | ||
| import { GeometryUploadComparisonService } from "./geometry-upload-comparison.service"; | ||
| import { SitePolygonStatusBulkUpdateBodyDto } from "./dto/site-polygon-status-update.dto"; | ||
|
|
||
| const MAX_PAGE_SIZE = 100 as const; | ||
|
|
||
|
|
@@ -365,6 +366,34 @@ export class SitePolygonsController { | |
| return document.addIndex(indexData); | ||
| } | ||
|
|
||
| @Patch("status/:status") | ||
| @ApiOperation({ | ||
| operationId: "updateSitePolygonStatus", | ||
| summary: "Update the status of a site polygon", | ||
| description: "Update the status of a site polygon" | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These descriptions make it sound like this endpoint operates on a single polygon. |
||
| }) | ||
| @JsonApiResponse({ data: SitePolygonLightDto, hasMany: true }) | ||
| @ExceptionResponse(UnauthorizedException, { description: "Authentication failed." }) | ||
| @ExceptionResponse(BadRequestException, { description: "Invalid request data." }) | ||
| @ExceptionResponse(NotFoundException, { description: "Site polygon not found." }) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should also be something more like |
||
| async updateBulkStatus(@Param("status") status: string, @Body() request: SitePolygonStatusBulkUpdateBodyDto) { | ||
| await this.policyService.authorize("update", SitePolygon); | ||
| const userId = this.policyService.userId; | ||
| if (userId == null) { | ||
| throw new UnauthorizedException("User must be authenticated"); | ||
| } | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For a normal endpoint (one that doesn't opt out of auth), the user id is guaranteed to be non null, so instead of this check, you can do: |
||
| const user = await User.findByPk(userId, { | ||
| attributes: ["id", "firstName", "lastName", "emailAddress"] | ||
| }); | ||
| const { data, comment } = request; | ||
| const updatedUuids = await this.sitePolygonService.updateBulkStatus(status, data, comment, user); | ||
| const document = buildJsonApi(SitePolygonLightDto); | ||
| for (const sitePolygon of updatedUuids) { | ||
| document.addData(sitePolygon.uuid, await this.sitePolygonService.buildLightDto(sitePolygon, {})); | ||
| } | ||
| return document; | ||
| } | ||
|
|
||
| @Patch() | ||
| @ApiOperation({ | ||
| operationId: "bulkUpdateSitePolygons", | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For
required: false, this should becomment?: string. If you really want to explicitly acceptnull, theApiPropertyshould havenullable: true.