Skip to content

Commit

Permalink
updated to env auth, using client.query method for existing pg code, …
Browse files Browse the repository at this point in the history
…fixed elevation and intervals
  • Loading branch information
amyfromandi committed Sep 10, 2024
1 parent aea3843 commit 16385dd
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 23 deletions.
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ DOCKER_TAG = latest

run:
docker build -t macrostrat-api .
docker run --rm -it -p 5550:5550 macrostrat-api
docker run --env-file .env --rm -it -p 5550:5550 macrostrat-api


#add env command to docker run
11 changes: 8 additions & 3 deletions v2/credentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@ exports.pg = {
};




exports.postgresDatabases = {
burwell: "macrostrat",
geomacro: "geomacro",
elevation: "elevation"
elevation: "elevation",
};

// This is the default Redis port
Expand All @@ -25,3 +23,10 @@ exports.redis = {
// Generate a hash by running: node -e "console.log(require('uuid/v4')())"
// NOTE: this is outdated and may not be used
exports.cacheRefreshKey = "put-hash-here";


/*
exports.macrostratDatabaseUrl = process.env.MACROSTRAT_DATABASE_URL;
exports.elevationDatabaseUrl = process.env.ELEVATION_DATABASE_URL;
exports.cacheRefreshKey = process.env.CACHE_REFRESH_KEY;
*/
5 changes: 1 addition & 4 deletions v2/definitions/intervals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,7 @@ module.exports = function (req, res, next, cb) {
age_bottom AS b_age,
interval_type AS int_type,
${color},
json_agg(json_build_object(
'timescale_id', timescales.id,
'name', timescales.timescale
)) AS timescales
json_agg(json_build_object('timescale_id', timescales.id, 'name', timescales.timescale)) AS timescales
FROM macrostrat.intervals
LEFT JOIN macrostrat.timescales_intervals ON intervals.id = macrostrat.timescales_intervals.interval_id
LEFT JOIN macrostrat.timescales ON macrostrat.timescales.id = macrostrat.timescales_intervals.timescale_id
Expand Down
4 changes: 1 addition & 3 deletions v2/elevation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ module.exports = (req, res, next, cb) => {
if (Object.keys(req.query).length < 1) {
return larkin.info(req, res, next);
}
console.log(req.query)
let param = {}
let param = {}

if ((req.query.lat && req.query.lng) || "sample" in req.query) {
let lat = req.query.lat || 43.07;
Expand All @@ -33,7 +32,6 @@ module.exports = (req, res, next, cb) => {
sql,
param,
(error, result) => {
console.log(result)
if (error) {
if (cb) return cb(error);
return larkin.error(req, res, next, "Error fetching elevation data");
Expand Down
17 changes: 14 additions & 3 deletions v2/larkin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,20 +87,31 @@ const { Client, Pool } = require("pg");
/* Special case for elevation database (temporary) */
connectionDetails.database = 'elevation'
}
console.log(connectionDetails)

const pool = new Pool(connectionDetails);

pool.connect(function (err, client, done) {
if (err) {
larkin.log("error", "error connecting - " + err);
callback(err);
} else {
} else if (typeof(params) === 'object') {
//named uses yesql to modify the params dict and sql named parameters into an array before querying PG.
//client.query can only accept numerical indices in sql syntax and an array for parameter values.
const preparedQuery = named(sql)(params);
console.log("Prepared Query Text:", preparedQuery.text);
console.log("Prepared Query Values:", preparedQuery.values);
var query = client.query(preparedQuery.text, preparedQuery.values, function (err, result) {
client.query(preparedQuery.text, preparedQuery.values, function (err, result) {
done();
if (err) {
larkin.log("error", err);
callback(err);
} else {
callback(null, result);
}
});
}
else if (params.isArray) {
client.query(sql, params, function (err, result) {
done();
if (err) {
larkin.log("error", err);
Expand Down
10 changes: 2 additions & 8 deletions v2/mobile/map_query_v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,28 +333,22 @@ module.exports = (req, res, next) => {
req.query.lng = larkin.normalizeLng(req.query.lng);
req.query.z = parseInt(req.query.z || 0);


req.query.lng = stringify(req.query.lng);
req.query.lat = stringify(req.query.lat);
req.query.z = stringify(req.query.z);
console.log(params)

async.parallel(
{
elevation: (cb) => {
require("../elevation")(req, null, null, (error, data) => {
console.log(req)
console.log(data)

if (data && data.length) {
console.log(data)
console.log(data.length)
cb(null, data[0].elevation);
} else {
console.log("cb is null")
cb(null, null);
}
});
console.log('ELEVATION IS COMPLETE')

},

lines: (cb) => {
Expand Down

0 comments on commit 16385dd

Please sign in to comment.