Skip to content

Commit

Permalink
feat: adds tiles endpoint and finds for BLMfinalresults
Browse files Browse the repository at this point in the history
  • Loading branch information
rubvalave committed Mar 30, 2022
1 parent 2a8a2ee commit ac7acf9
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 0 deletions.
40 changes: 40 additions & 0 deletions api/apps/api/src/modules/scenarios/scenarios.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,46 @@ export class ScenariosController {
return await this.proxyService.proxyTileRequest(req, response);
}

@BaseTilesOpenApi()
@ApiOperation({
description: 'Get tiles for a scenario blm values to generate maps.',
})
@ApiParam({
name: 'id',
description: 'scenario id',
type: String,
required: true,
example: 'e5c3b978-908c-49d3-b1e3-89727e9f999c',
})
@Get(':id/calibration/tiles/:blmValues/:z/:x/:y.mvt')
async proxyPlanningUnitsBlmValuesTiles(
@Req() req: RequestWithAuthenticatedUser,
@Res() response: Response,
@Param('id', ParseUUIDPipe) scenarioId: string,
) {
/* Due to the usage of proxyService in other modules
the ACL control for this endpoint is placed in the controller */
const scenario = await this.service.getById(scenarioId, {
authenticatedUser: req.user,
});

if (isLeft(scenario)) {
throw mapAclDomainToHttpError(scenario.left, {
userId: req.user.id,
resourceType: scenarioResource.name.plural,
});
}
if (
!(await this.scenarioAclService.canViewBlmResults(
req.user.id,
scenario.right.projectId,
))
) {
throw new ForbiddenException();
}
return await this.proxyService.proxyTileRequest(req, response);
}

@BaseTilesOpenApi()
@ApiParam({
name: 'scenarioIdA',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ export class BlmFinalResultsRepository {
return Promise.resolve(undefined);
}

async findOneByScenarioId(
scenarioId: string,
): Promise<BlmFinalResultEntity | undefined> {
const result = await this.entityManager.findOne(BlmFinalResultEntity, {
where: { scenarioId },
});
return result;
}

/**
* clear previous results, move the new ones to target
* table - everything within transaction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,33 @@ export class MarxanSandboxBlmRunnerService
);
}
this.interruptIfKilled(scenarioId);

await this.finalResultsRepository.saveFinalResults(
scenarioId,
calibrationId,
);

const createdFinalResult = await this.finalResultsRepository.findOneByScenarioId(
scenarioId,
);

const puIds = createdFinalResult?.protected_pu_ids;

//-> I need to get the tiles for the APP(FE) to generate the maps.
// Once they are ready after the ¿proxy? request to API I need to
// request the webshot service png generation with those tiles.
// const proxyCall(puids)
// this.interruptIfKilled(scenarioId);

/*
Webshot call happens here with puIds.
This will return the PNG data, that needs to be inserted in next call to update finalResults.
await this.webshot.createScreenshot(puData, scenarioId, runId);
this.interruptIfKilled(scenarioId);
*/

// When webshot call returns -> this.finalResultsRepository.updateFinalResults(scenarioId, pngData).

this.clearAbortController(scenarioId);
this.interruptIfKilled(scenarioId);
} catch (err) {
Expand Down

0 comments on commit ac7acf9

Please sign in to comment.