Skip to content

Commit

Permalink
Update libraries to work with latest node version
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelpucat committed Jan 13, 2022
1 parent 6f74645 commit ff2fa27
Show file tree
Hide file tree
Showing 10 changed files with 5,574 additions and 4,456 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,7 @@ typings/
.env

# next.js build output
.next
.next

# osm pbf file
osm2pgsql/map.osm.pbf
7,078 changes: 3,784 additions & 3,294 deletions pdt-marinehelper-client/package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pdt-marinehelper-client/src/app/components/Root.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from "react";
import { Header } from "./Header";
import {Scenario} from "./Scenario";
import { Scenario } from "./Scenario";
import { About } from "./About";
import { Switch, Route } from "react-router";

Expand Down
216 changes: 109 additions & 107 deletions pdt-marinehelper-server/api/controllers/covesController.js
Original file line number Diff line number Diff line change
@@ -1,170 +1,172 @@
const db = require("../../db");

exports.getAllAnchorages = (req, res, next) => {
exports.getAllAnchorages = async (req, res, next) => {
const SELECT_ANCHORAGES_QUERY =
'SELECT osm_id, "seamark:type", "seamark:name", "seamark:anchorage:category", ST_AsGeoJSON(ST_Transform(way, 4326)) AS center ' +
"FROM planet_osm_point " +
"WHERE \"seamark:type\" = 'anchorage'";
`
SELECT osm_id, "seamark:type", "seamark:name", "seamark:anchorage:category", ST_AsGeoJSON(ST_Transform(way, 4326)) AS center
FROM planet_osm_point
WHERE "seamark:type" = 'anchorage'
`;

db.query(SELECT_ANCHORAGES_QUERY, [], (err, res1) => {
if (err) {
return next(err);
}
try {
const dbOut = await db.query(SELECT_ANCHORAGES_QUERY)

const result = res1.rows.map(row => {
const result = dbOut?.rows?.map?.(row => {
const center = JSON.parse(row.center);
return { ...row, center };
});

res.status(200).json({
message: "anchorages fetched",
result: result,
error: err
result,
});
});
} catch (err) {
next(err);
}
};

exports.getNearbyAnchorages = (req, res, next) => {
exports.getNearbyAnchorages = async (req, res, next) => {
const { lat, lng, maxDistance } = req.query;
const SELECT_ANCHORAGES_QUERY =
"WITH pos AS ( "+
" SELECT ST_SetSRID(ST_MakePoint($2, $3), 4326)::geography AS pos "+
") "+
'SELECT osm_id, "seamark:type", "seamark:name", "seamark:anchorage:category", ' +
"ST_AsGeoJSON(ST_Transform(way, 4326)) AS center, " +
"ST_Distance(pos.pos, ST_Transform(way, 4326)) AS st_distance " +
"FROM planet_osm_point, pos pos " +
"WHERE \"seamark:type\" = 'anchorage' AND ST_DWithin(ST_Transform(way, 4326), pos.pos, $1::int)" +
"ORDER BY st_distance";

db.query(SELECT_ANCHORAGES_QUERY, [maxDistance, lng, lat], (err, res1) => {
if (err) {
return next(err);
}

const result = res1.rows.map(row => {
`
WITH pos AS (
SELECT ST_SetSRID(ST_MakePoint($2, $3), 4326)::geography AS pos
)
SELECT osm_id, "seamark:type", "seamark:name", "seamark:anchorage:category",
ST_AsGeoJSON(ST_Transform(way, 4326)) AS center,
ST_Distance(pos.pos, ST_Transform(way, 4326)) AS st_distance
FROM planet_osm_point, pos pos
WHERE "seamark:type" = 'anchorage' AND ST_DWithin(ST_Transform(way, 4326), pos.pos, $1::int)
ORDER BY st_distance
`;

try {
const dbOut = await db.query(SELECT_ANCHORAGES_QUERY, [maxDistance, lng, lat])

const result = dbOut?.rows?.map?.(row => {
const center = JSON.parse(row.center);
return { ...row, center };
});

res.status(200).json({
message: "anchorages fetched",
result: result,
error: err
result,
});
});
} catch (err) {
next(err);
}
};

exports.getAllMoorings = (req, res, next) => {
exports.getAllMoorings = async (req, res, next) => {
const SELECT_MOORINGS_QUERY =
'SELECT osm_id, "seamark:type", "seamark:name", ST_AsGeoJSON(ST_Transform(way, 4326)) as center ' +
"FROM planet_osm_point " +
"WHERE \"seamark:type\" = 'mooring'";
`
SELECT osm_id, "seamark:type", "seamark:name", ST_AsGeoJSON(ST_Transform(way, 4326)) as center
FROM planet_osm_point
WHERE "seamark:type" = 'mooring'
`;

db.query(SELECT_MOORINGS_QUERY, [], (err, res1) => {
if (err) {
return next(err);
}
try {
const dbOut = await db.query(SELECT_MOORINGS_QUERY)

const result = res1.rows.map(row => {
const result = dbOut?.rows?.map?.(row => {
const center = JSON.parse(row.center);
return { ...row, center };
});

res.status(200).json({
message: "moorings fetched",
result: result,
error: err
result,
});
});
} catch (err) {
next(err);
}
};

exports.getNearbyMoorings = (req, res, next) => {
exports.getNearbyMoorings = async (req, res, next) => {
const { lat, lng, maxDistance } = req.query;
const SELECT_MOORINGS_QUERY =
"WITH pos AS ( "+
" SELECT ST_SetSRID(ST_MakePoint($2, $3), 4326)::geography AS pos "+
") "+
'SELECT osm_id, "seamark:type", "seamark:name", "seamark:anchorage:category", ' +
"ST_AsGeoJSON(ST_Transform(way, 4326)) AS center, " +
"ST_Distance(pos.pos, ST_Transform(way, 4326)) as st_distance " +
"FROM planet_osm_point, pos pos " +
"WHERE \"seamark:type\" = 'mooring' AND ST_DWithin(ST_Transform(way, 4326), pos.pos, $1::int)" +
"ORDER BY st_distance";

db.query(SELECT_MOORINGS_QUERY, [maxDistance, lng, lat], (err, res1) => {
if (err) {
return next(err);
}

const result = res1.rows.map(row => {
`
WITH pos AS (
SELECT ST_SetSRID(ST_MakePoint($2, $3), 4326)::geography AS pos
)
SELECT osm_id, "seamark:type", "seamark:name", "seamark:anchorage:category",
ST_AsGeoJSON(ST_Transform(way, 4326)) AS center,
ST_Distance(pos.pos, ST_Transform(way, 4326)) as st_distance
FROM planet_osm_point, pos pos
WHERE "seamark:type" = 'mooring' AND ST_DWithin(ST_Transform(way, 4326), pos.pos, $1::int)
ORDER BY st_distance
`;

try {
const dbOut = await db.query(SELECT_MOORINGS_QUERY, [maxDistance, lng, lat])

const result = dbOut?.rows?.map?.(row => {
const center = JSON.parse(row.center);
return { ...row, center };
});

res.status(200).json({
message: "moorings fetched",
result: result,
error: err
result,
});
});
} catch (err) {
next(err);
}
};

exports.getAllUnderwaterCablesAndPipes = (req, res, next) => {
exports.getAllUnderwaterCablesAndPipes = async (req, res, next) => {
const SELECT_UNDERWATER_CABLES_AND_PIPES_QUERY =
'SELECT osm_id, "seamark:type", "seamark:name", ST_AsGeoJSON(ST_Transform(way, 4326)) as geometry ' +
"FROM planet_osm_line " +
"WHERE \"seamark:type\" = 'pipeline_submarine' OR \"seamark:type\" = 'cable_submarine'";
`
SELECT osm_id, "seamark:type", "seamark:name", ST_AsGeoJSON(ST_Transform(way, 4326)) as geometry
FROM planet_osm_line
WHERE "seamark:type" = 'pipeline_submarine' OR "seamark:type" = 'cable_submarine'
`;

db.query(SELECT_UNDERWATER_CABLES_AND_PIPES_QUERY, [], (err, res1) => {
if (err) {
return next(err);
}
try {
const dbOut = await db.query(SELECT_UNDERWATER_CABLES_AND_PIPES_QUERY)

const result = res1.rows.map(row => {
const result = dbOut?.rows?.map?.(row => {
const geometry = JSON.parse(row.geometry);
return { ...row, geometry };
});

res.status(200).json({
message: "underwater cables and pipes fetched",
result: result,
error: err
result,
});
});
} catch (err) {
next(err);
}
};

exports.getNearbyUnderwaterCablesAndPipes = (req, res, next) => {
exports.getNearbyUnderwaterCablesAndPipes = async (req, res, next) => {
const { lat, lng, maxDistance } = req.query;
const SELECT_UNDERWATER_CABLES_AND_PIPES_QUERY =
"WITH pos AS ( "+
" SELECT ST_SetSRID(ST_MakePoint($2, $3), 4326)::geography AS pos "+
") "+
'SELECT osm_id, "seamark:type", "seamark:name", ' +
"ST_AsGeoJSON(ST_Transform(way, 4326)) AS geometry, " +
"ST_Distance(pos.pos, ST_Transform(way, 4326)) as st_distance " +
"FROM planet_osm_line, pos pos " +
"WHERE (\"seamark:type\" = 'pipeline_submarine' OR \"seamark:type\" = 'cable_submarine') AND ST_DWithin(ST_Transform(way, 4326), pos.pos, $1::int)" +
"ORDER BY st_distance";

db.query(
SELECT_UNDERWATER_CABLES_AND_PIPES_QUERY,
[maxDistance, lng, lat],
(err, res1) => {
if (err) {
return next(err);
}

const result = res1.rows.map(row => {
const geometry = JSON.parse(row.geometry);
return { ...row, geometry };
});

res.status(200).json({
message: "underwater cables and pipes fetched",
result: result,
error: err
});
}
);
`
WITH pos AS (
SELECT ST_SetSRID(ST_MakePoint($2, $3), 4326)::geography AS pos
)
SELECT osm_id, "seamark:type", "seamark:name",
ST_AsGeoJSON(ST_Transform(way, 4326)) AS geometry,
ST_Distance(pos.pos, ST_Transform(way, 4326)) as st_distance
FROM planet_osm_line, pos pos
WHERE ("seamark:type" = 'pipeline_submarine' OR "seamark:type" = 'cable_submarine') AND ST_DWithin(ST_Transform(way, 4326), pos.pos, $1::int)
ORDER BY st_distance
`;

try {
const dbOut = await db.query(SELECT_UNDERWATER_CABLES_AND_PIPES_QUERY, [maxDistance, lng, lat])

const result = dbOut?.rows?.map?.(row => {
const geometry = JSON.parse(row.geometry);
return { ...row, geometry };
});

res.status(200).json({
message: "underwater cables and pipes fetched",
result,
});
} catch (err) {
next(err);
}
};
Loading

0 comments on commit ff2fa27

Please sign in to comment.