Skip to content

Commit

Permalink
feat(CostSurface): Update Cost Surface PR tweaks and Develop Rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
KevSanchez committed Sep 8, 2023
1 parent 808a425 commit a9a6005
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
6 changes: 3 additions & 3 deletions api/apps/api/src/modules/cost-surface/cost-surface.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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 {}
Original file line number Diff line number Diff line change
@@ -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 {}
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Expand All @@ -51,6 +54,7 @@ export class ProjectCostSurfaceController {
@Inject(forwardRef(() => ScenariosService))
public readonly scenarioService: ScenariosService,
public readonly costSurfaceService: CostSurfaceService,
public readonly costSurfaceSeralizer: CostSurfaceSerializer,
) {}

@ImplementsAcl()
Expand Down Expand Up @@ -105,8 +109,8 @@ export class ProjectCostSurfaceController {
@Param('projectId') projectId: string,
@Param('costSurfaceId') costSurfaceId: string,
@Req() req: RequestWithAuthenticatedUser,
@Body() dto: UploadCostSurfaceShapefileDto,
): Promise<NotImplementedException> {
@Body() dto: UpdateCostSurfaceDto,
): Promise<JSONAPICostSurface> {
const result = await this.costSurfaceService.updateCostSurfaceShapefile(
req.user.id,
projectId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe('Upload Cost Surface Shapefile', () => {
});
});

describe('Upload Cost Surface Shapefile', () => {
describe('Update Cost Surface', () => {
beforeEach(async () => {
fixtures = await getProjectCostSurfaceControllerFixtures();
});
Expand All @@ -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 () => {
Expand Down

0 comments on commit a9a6005

Please sign in to comment.