Skip to content
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
8 changes: 4 additions & 4 deletions src/latLon/controllers/latLonController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,18 @@ export class LatLonController {

public getCoordinates: GetCoordinatesHandler = async (req, res, next) => {
try {
const { lat, lon, target_grid } = req.query;
const { target_grid: targetGrid } = req.query;

let response:
| ({
[key: string]: unknown;
} & Feature)
| undefined = undefined;

if (target_grid === 'control') {
response = await this.manager.latLonToTile({ lat, lon });
if (targetGrid === 'control') {
response = await this.manager.latLonToTile({ ...req.query, targetGrid });
} else {
response = this.manager.latLonToMGRS({ lat, lon });
response = this.manager.latLonToMGRS({ ...req.query, targetGrid });
}

return res.status(httpStatus.OK).json(response);
Expand Down
18 changes: 16 additions & 2 deletions src/latLon/models/latLonManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class LatLonManager {
@inject(SERVICES.CONFIG) private readonly config: IConfig
) {}

public async latLonToTile({ lat, lon }: WGS84Coordinate): Promise<{ [key: string]: unknown } & Feature> {
public async latLonToTile({ lat, lon, targetGrid }: WGS84Coordinate & { targetGrid: string }): Promise<{ [key: string]: unknown } & Feature> {
if (!validateWGS84Coordinate({ lat, lon })) {
this.logger.warn("LatLonManager.latLonToTile: Invalid lat lon, check 'lat' and 'lon' keys exists and their values are legal");
throw new BadRequestError("Invalid lat lon, check 'lat' and 'lon' keys exists and their values are legal");
Expand Down Expand Up @@ -63,9 +63,11 @@ export class LatLonManager {
return {
type: 'Feature',
geocoding: {
version: process.env.npm_package_version,
query: {
lat,
lon,
...convertCamelToSnakeCase({ targetGrid }),
},
response: convertCamelToSnakeCase({
maxScore: 1,
Expand All @@ -90,7 +92,17 @@ export class LatLonManager {
};
}

public latLonToMGRS({ lat, lon, accuracy = 5 }: { lat: number; lon: number; accuracy?: number }): { [key: string]: unknown } & Feature {
public latLonToMGRS({
lat,
lon,
accuracy = 5,
targetGrid,
}: {
lat: number;
lon: number;
accuracy?: number;
targetGrid: string;
}): { [key: string]: unknown } & Feature {
const accuracyString: Record<number, string> = {
[0]: '100km',
[1]: '10km',
Expand All @@ -103,9 +115,11 @@ export class LatLonManager {
return {
type: 'Feature',
geocoding: {
version: process.env.npm_package_version,
query: {
lat,
lon,
...convertCamelToSnakeCase({ targetGrid }),
},
response: convertCamelToSnakeCase({
maxScore: 1,
Expand Down
4 changes: 4 additions & 0 deletions tests/integration/latLon/latLon.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@ describe('/lookup', function () {
expect(response.body).toEqual({
type: 'Feature',
geocoding: {
version: expect.any(String) as string,
query: {
lat: 52.57326537485767,
lon: 12.948781146422107,
target_grid: 'control',
},
response: {
max_score: 1,
Expand Down Expand Up @@ -90,9 +92,11 @@ describe('/lookup', function () {
expect(response.body).toEqual({
type: 'Feature',
geocoding: {
version: expect.any(String) as string,
query: {
lat: 52.57326537485767,
lon: 12.948781146422107,
target_grid: 'MGRS',
},
response: {
max_score: 1,
Expand Down