Skip to content
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

fix(api): return empty specification when not found #456

Merged
merged 1 commit into from
Aug 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Injectable } from '@nestjs/common';
import { PaginationMeta } from '@marxan-api/utils/app-base.service';
import { GeoFeatureSetService } from './geo-feature-set.service';
import { GeoFeatureSetSpecification } from './dto/geo-feature-set-specification.dto';
import { SimpleJobStatus } from '../scenarios/scenario.api.entity';

@Injectable()
export class GeoFeatureSetSerializer {
Expand All @@ -16,4 +17,11 @@ export class GeoFeatureSetSerializer {
): Promise<any> {
return this.geoFeatureSetsService.serialize(entities, paginationMeta);
}

emptySpecification() {
return this.geoFeatureSetsService.serialize({
status: SimpleJobStatus.draft,
features: [],
});
}
}
3 changes: 1 addition & 2 deletions api/apps/api/src/modules/scenarios/scenarios.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
UseInterceptors,
ValidationPipe,
InternalServerErrorException,
NotFoundException,
} from '@nestjs/common';
import { scenarioResource, ScenarioResult } from './scenario.api.entity';
import { Request, Response } from 'express';
Expand Down Expand Up @@ -261,7 +260,7 @@ export class ScenariosController {
): Promise<GeoFeatureSetResult> {
const result = await this.service.getLastUpdatedSpecification(id);
if (isLeft(result)) {
throw new NotFoundException();
return this.geoFeatureSetSerializer.emptySpecification();
}
return await this.geoFeatureSetSerializer.serialize(result.right);
}
Expand Down