From a9a6005b0f87425696eec84ad653b69c23a2f6a2 Mon Sep 17 00:00:00 2001 From: Kevin Date: Fri, 8 Sep 2023 17:39:41 +0200 Subject: [PATCH] feat(CostSurface): Update Cost Surface PR tweaks and Develop Rebase --- .../api/src/modules/cost-surface/cost-surface.service.ts | 6 +++--- .../modules/cost-surface/dto/update-cost-surface.dto.ts | 3 +-- .../dto/upload-cost-surface-shapefile.dto.ts | 4 ++-- .../modules/projects/project-cost-surface.controller.ts | 8 ++++++-- .../project/project-cost-surface.controller.e2e-spec.ts | 9 +++------ 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/api/apps/api/src/modules/cost-surface/cost-surface.service.ts b/api/apps/api/src/modules/cost-surface/cost-surface.service.ts index d3543eded8..0b9ea8cf60 100644 --- a/api/apps/api/src/modules/cost-surface/cost-surface.service.ts +++ b/api/apps/api/src/modules/cost-surface/cost-surface.service.ts @@ -87,10 +87,10 @@ export class CostSurfaceService { return left(projectNotEditable); } - const nameCount = await this.costSurfaceRepository.count({ - where: { name: dto.name }, + const sameNameCostSurface = await this.costSurfaceRepository.count({ + where: { projectId, name: dto.name }, }); - if (nameCount > 0) { + if (sameNameCostSurface) { return left(costSurfaceNameAlreadyExistsForProject); } diff --git a/api/apps/api/src/modules/cost-surface/dto/update-cost-surface.dto.ts b/api/apps/api/src/modules/cost-surface/dto/update-cost-surface.dto.ts index bd07a0a505..4a45e9355f 100644 --- a/api/apps/api/src/modules/cost-surface/dto/update-cost-surface.dto.ts +++ b/api/apps/api/src/modules/cost-surface/dto/update-cost-surface.dto.ts @@ -1,4 +1,3 @@ -import { PartialType } from '@nestjs/swagger'; import { CreateCostSurfaceDto } from '@marxan-api/modules/cost-surface/dto/create-cost-surface.dto'; -export class UpdateCostSurfaceDto extends PartialType(CreateCostSurfaceDto) {} +export class UpdateCostSurfaceDto extends CreateCostSurfaceDto {} diff --git a/api/apps/api/src/modules/cost-surface/dto/upload-cost-surface-shapefile.dto.ts b/api/apps/api/src/modules/cost-surface/dto/upload-cost-surface-shapefile.dto.ts index 4a5c6758b9..77500a8396 100644 --- a/api/apps/api/src/modules/cost-surface/dto/upload-cost-surface-shapefile.dto.ts +++ b/api/apps/api/src/modules/cost-surface/dto/upload-cost-surface-shapefile.dto.ts @@ -1,3 +1,3 @@ -import { UpdateCostSurfaceDto } from '@marxan-api/modules/cost-surface/dto/update-cost-surface.dto'; +import { CreateCostSurfaceDto } from '@marxan-api/modules/cost-surface/dto/create-cost-surface.dto'; -export class UploadCostSurfaceShapefileDto extends UpdateCostSurfaceDto {} +export class UploadCostSurfaceShapefileDto extends CreateCostSurfaceDto {} diff --git a/api/apps/api/src/modules/projects/project-cost-surface.controller.ts b/api/apps/api/src/modules/projects/project-cost-surface.controller.ts index 5f1b6cc069..e2ccbd24c4 100644 --- a/api/apps/api/src/modules/projects/project-cost-surface.controller.ts +++ b/api/apps/api/src/modules/projects/project-cost-surface.controller.ts @@ -43,6 +43,9 @@ import { JsonApiAsyncJobMeta, } from '@marxan-api/dto/async-job.dto'; import { ensureShapefileHasRequiredFiles } from '@marxan-api/utils/file-uploads.utils'; +import { UpdateCostSurfaceDto } from '@marxan-api/modules/cost-surface/dto/update-cost-surface.dto'; +import { CostSurfaceSerializer } from '@marxan-api/modules/cost-surface/dto/cost-surface.serializer'; +import { JSONAPICostSurface } from '@marxan-api/modules/cost-surface/cost-surface.api.entity'; @ApiTags(projectResource.className) @Controller(`${apiGlobalPrefixes.v1}/projects`) @@ -51,6 +54,7 @@ export class ProjectCostSurfaceController { @Inject(forwardRef(() => ScenariosService)) public readonly scenarioService: ScenariosService, public readonly costSurfaceService: CostSurfaceService, + public readonly costSurfaceSeralizer: CostSurfaceSerializer, ) {} @ImplementsAcl() @@ -105,8 +109,8 @@ export class ProjectCostSurfaceController { @Param('projectId') projectId: string, @Param('costSurfaceId') costSurfaceId: string, @Req() req: RequestWithAuthenticatedUser, - @Body() dto: UploadCostSurfaceShapefileDto, - ): Promise { + @Body() dto: UpdateCostSurfaceDto, + ): Promise { const result = await this.costSurfaceService.updateCostSurfaceShapefile( req.user.id, projectId, diff --git a/api/apps/api/test/project/project-cost-surface.controller.e2e-spec.ts b/api/apps/api/test/project/project-cost-surface.controller.e2e-spec.ts index 9600dc1e48..7d6a275da3 100644 --- a/api/apps/api/test/project/project-cost-surface.controller.e2e-spec.ts +++ b/api/apps/api/test/project/project-cost-surface.controller.e2e-spec.ts @@ -43,7 +43,7 @@ describe('Upload Cost Surface Shapefile', () => { }); }); -describe('Upload Cost Surface Shapefile', () => { +describe('Update Cost Surface', () => { beforeEach(async () => { fixtures = await getProjectCostSurfaceControllerFixtures(); }); @@ -58,17 +58,14 @@ describe('Upload Cost Surface Shapefile', () => { const costSurfaceName = 'someNewName'; // ACT - const response = await fixtures.WhenUpdatingCostSurfaceForProject( + await fixtures.WhenUpdatingCostSurfaceForProject( projectId, costSurface.id, costSurfaceName, ); // ASSERT - await fixtures.ThenCostSurfaceAPIEntityWasProperlySaved( - response, - costSurfaceName, - ); + await fixtures.ThenCostSurfaceAPIEntityWasProperlySaved(costSurfaceName); }); it(`should return error when the cost surface could not be found`, async () => {