Skip to content

Commit

Permalink
feat: implement tree_name feature
Browse files Browse the repository at this point in the history
  • Loading branch information
ZavenArra committed May 19, 2021
1 parent ba0c34d commit c1b2330
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 8 deletions.
3 changes: 0 additions & 3 deletions .env

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"eslint": "eslint --report-unused-disable-directives .",
"eslint:fix": "npm run eslint -- --fix",
"test": "jest --watchAll --runInBand",
"dev": "NODE_PORT=3001 nodemon src/server.js"
"dev": "NODE_PORT=3001 NODE_ENV=dev nodemon src/server.js"
},
"dependencies": {
"@sentry/node": "^5.4.3",
Expand Down
5 changes: 5 additions & 0 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const allowCrossDomain = (req, res, next) => {
}

if(process.env.NODE_ENV == 'dev'){
console.log('disable cors');
app.use(allowCrossDomain);
}

Expand Down Expand Up @@ -61,12 +62,16 @@ app.get("/tree", async function (req, res){
const tree = new Tree();
const treeId = req.query.tree_id;
const uuid = req.query.uuid;
const treeName = req.query.tree_name;
if(treeId){
const treeDetail = await tree.getTreeById(treeId);
res.status(200).json(treeDetail);
} else if(uuid){
const treeDetail = await tree.getTreeByUUID(uuid);
res.status(200).json(treeDetail);
} else if(treeName){
const treeDetail = await tree.getTreeByName(treeName);
res.status(200).json(treeDetail);
} else {
console.warn("no tree id", treeId);
res.status(400).json({message:"no tree id"});
Expand Down
16 changes: 13 additions & 3 deletions src/cron/assign-new-trees-to-clusters.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,17 @@ const pool = new Pool({
const client = await pool.connect();

const select = {
text: `SELECT count(id)
text: `SELECT count(trees.id)
FROM trees
JOIN region
ON ST_Contains( region.geom, trees.estimated_geometric_location)
JOIN region_zoom
ON region_zoom.region_id = region.id
WHERE trees.active = true
AND trees.cluster_regions_assigned = false`
};
const rval = await client.query(select);
console.log(rval.rows[0].count)
/* if(rval.rows[0].count == 0){
console.log("no new trees");
client.release();
Expand Down Expand Up @@ -63,13 +68,18 @@ const pool = new Pool({
AND cluster_regions_assigned = false`
};
console.log(update);
await client.query(update);
const rval2 = await client.query(update);
console.log(rval2);

await client.query('COMMIT');

const select = {
text: `SELECT count(id)
text: `SELECT count(trees.id)
FROM trees
JOIN region
ON ST_Contains( region.geom, trees.estimated_geometric_location)
JOIN region_zoom
ON region_zoom.region_id = region.id
WHERE trees.active = true
AND trees.cluster_regions_assigned = false`
};
Expand Down
5 changes: 4 additions & 1 deletion src/models/Map.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class Map{
async init(settings){
console.debug("init map with settings:", settings);
this.treeid = settings.treeid;
this.tree_name = settings.tree_name;
this.zoomLevel = parseInt(settings.zoom_level);
this.userid = settings.userid;
this.clusterRadius = settings.clusterRadius;
Expand All @@ -34,7 +35,9 @@ class Map{
*/
this.sql = new SQLCase2();
this.sql.addTreeFilter(this.treeid);

}else if(this.tree_name){
this.sql = new SQLCase2();
this.sql.addTreeNameFilter(this.tree_name);
}else if(this.capture_id){
this.sql = new SQLCase2();
this.sql.addUUIDFilter(this.capture_id);
Expand Down
1 change: 1 addition & 0 deletions src/models/Tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class Tree{
}
return treeObject;
}

}


Expand Down
8 changes: 8 additions & 0 deletions src/models/sqls/SQLCase2.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ class SQLCase2{
this.treeid = treeid;
}

addTreeNameFilter(tree_name){
this.tree_name = tree_name;
}


addUUIDFilter(uuid){
this.uuid = uuid;
}
Expand Down Expand Up @@ -46,6 +51,9 @@ class SQLCase2{
if(this.treeid){
result += 'AND trees.id = ' + this.treeid + ' \n';
}
if(this.tree_name){
result += "AND trees.name = '" + this.tree_name + "' \n";
}
if(this.uuid){
result += 'AND trees.uuid = ' + this.uuid + ' \n';
}
Expand Down

0 comments on commit c1b2330

Please sign in to comment.