From c95dcccb0ecc8bf1494cd1b5c31538b11ee27a63 Mon Sep 17 00:00:00 2001 From: Pierre REPETTO-ANDIPATIN Date: Mon, 7 Nov 2016 11:34:05 +0100 Subject: [PATCH 01/16] Create README.md --- README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..ff8e02b --- /dev/null +++ b/README.md @@ -0,0 +1,14 @@ +Locations +========= + +Location generator in node + +Author +------ + +Pierre Repetto-Andipatin + +License +------- + +MIT From b0606cabb7efcd09a24ee3bb64f4501ead3eecf6 Mon Sep 17 00:00:00 2001 From: Pierre REPETTO-ANDIPATIN Date: Mon, 9 Jan 2017 17:05:30 +0100 Subject: [PATCH 02/16] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index ff8e02b..31dcad7 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,7 @@ Location generator in node Author ------ +Kasun Samarasinghe Pierre Repetto-Andipatin License From f98d82932779a38b81291794763bd30769dfe886 Mon Sep 17 00:00:00 2001 From: Pierre REPETTO-ANDIPATIN Date: Mon, 9 Jan 2017 17:05:40 +0100 Subject: [PATCH 03/16] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 31dcad7..c531d2c 100644 --- a/README.md +++ b/README.md @@ -6,8 +6,8 @@ Location generator in node Author ------ -Kasun Samarasinghe -Pierre Repetto-Andipatin +* Kasun Samarasinghe +* Pierre Repetto-Andipatin License ------- From 9817fe55063326636942aafdf9dac38ea07b67be Mon Sep 17 00:00:00 2001 From: Pierre REPETTO-ANDIPATIN Date: Mon, 9 Jan 2017 17:05:54 +0100 Subject: [PATCH 04/16] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c531d2c..7754aad 100644 --- a/README.md +++ b/README.md @@ -6,8 +6,8 @@ Location generator in node Author ------ -* Kasun Samarasinghe -* Pierre Repetto-Andipatin +* Kasun Samarasinghe - +* Pierre Repetto-Andipatin - License ------- From 2bf470080399ce3d532b346e810f5ca48e7a1a88 Mon Sep 17 00:00:00 2001 From: Pierre Repetto-Andipatin Date: Mon, 9 Jan 2017 17:07:08 +0100 Subject: [PATCH 05/16] chore: update dependencies --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e783cde..4941880 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "license": "MIT", "dependencies": { "bluebird": "^3.4.6", - "dotenv": "^2.0.0", + "dotenv": "^4444.0.0", "mongoose": "^4.6.6" } } From 5682ad5650f7d79e4b3f77aa3e1f07622fe7f18e Mon Sep 17 00:00:00 2001 From: Pierre Repetto-Andipatin Date: Mon, 9 Jan 2017 17:08:10 +0100 Subject: [PATCH 06/16] fix: change dotenv dependency --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4941880..fe45900 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "license": "MIT", "dependencies": { "bluebird": "^3.4.6", - "dotenv": "^4444.0.0", + "dotenv": "^4.0.0", "mongoose": "^4.6.6" } } From b52c31a3c68194d3dcd71ab9d02476ee2a903cbc Mon Sep 17 00:00:00 2001 From: Pierre Repetto-Andipatin Date: Wed, 11 Jan 2017 17:37:56 +0100 Subject: [PATCH 07/16] feat: add flush action --- .gitignore | 1 + .jscsrc | 8 +++++++ index.js | 59 +++++++++++++++++++++++++++++++++++----------- models/Location.js | 4 ++-- package.json | 2 +- 5 files changed, 57 insertions(+), 17 deletions(-) create mode 100644 .jscsrc diff --git a/.gitignore b/.gitignore index 37d7e73..a9d3ef2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ node_modules .env +.dotenv diff --git a/.jscsrc b/.jscsrc new file mode 100644 index 0000000..034c8a7 --- /dev/null +++ b/.jscsrc @@ -0,0 +1,8 @@ +{ + "preset": "node-style-guide", + "requireTrailingComma": { + "ignoreSingleValue": true, + "ignoreSingleLine": true + }, + "excludeFiles": ["node_modules/**"] +} diff --git a/index.js b/index.js index c020d6f..8e0c3b1 100644 --- a/index.js +++ b/index.js @@ -6,20 +6,51 @@ mongoose.Promise = require('bluebird'); var Location = require('./models/Location.js'); mongoose.connect(process.env.MONGODB_URI); -mongoose.connection.on('error', function () { - console.log( - 'MongoDB Connection Error. Please make sure that MongoDB is running.' - ); - process.exit(1); -}); -var location = new Location({ - timestamp: new Date().getTime(), - latitude: '12.12', - longitude: '5.14', -}); +var db = mongoose.connection; +db.on('error', console.error.bind(console, + 'MongoDB Connection Error. ' + + 'Please make sure that MongoDB is running.\n')); + +db.once('open', () => { + console.log('Connection opened.'); -location.save(function (err, location) { - console.log(location); - process.exit(0); + switch (process.env.ACTION) { + case 'flush': { + flush(); + break; + } + default: { + saveSimple(); + } + } }); + +function flush() { + Location.remove({}).exec() + .then(() => { + console.log('Database has been flushed.'); + process.exit(0); + }) + .catch(err => { + console.error(err); + process.exit(1); + }); +} + +function saveSimple() { + var location = new Location({ + timestamp: new Date().getTime(), + latitude: '12.12', + longitude: '5.14', + }); + location.save() + .then(location => { + console.log(location); + process.exit(0); + }) + .catch(err => { + console.error(err); + process.exit(1); + }); +} diff --git a/models/Location.js b/models/Location.js index 92eff03..57c61f7 100644 --- a/models/Location.js +++ b/models/Location.js @@ -9,6 +9,6 @@ var locationsSchema = new mongoose.Schema({ longitude: String, }); -var Stocks = mongoose.model('Stocks', locationsSchema); +var Locations = mongoose.model('Locations', locationsSchema); -module.exports = Stocks; +module.exports = Locations; diff --git a/package.json b/package.json index fe45900..3dcd82e 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,6 @@ "dependencies": { "bluebird": "^3.4.6", "dotenv": "^4.0.0", - "mongoose": "^4.6.6" + "mongoose": "^4.7.6" } } From bd0a008782b9869b3e154c03e40b437c4d05acb6 Mon Sep 17 00:00:00 2001 From: Pierre Repetto-Andipatin Date: Wed, 11 Jan 2017 17:45:49 +0100 Subject: [PATCH 08/16] chore: bump 0.0.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3dcd82e..e7f410b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "locations", - "version": "0.0.1", + "version": "0.0.2", "description": "", "main": "index.js", "scripts": { From dcabf9dc91991a52325d80b30f79cab6ca9ebac9 Mon Sep 17 00:00:00 2001 From: Akila Nonis Date: Mon, 13 Feb 2017 16:19:48 +0530 Subject: [PATCH 09/16] Enhancement 01 - Show current version --- index.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/index.js b/index.js index 8e0c3b1..2b79e71 100644 --- a/index.js +++ b/index.js @@ -5,6 +5,9 @@ var mongoose = require('mongoose'); mongoose.Promise = require('bluebird'); var Location = require('./models/Location.js'); +var package_version = require('./package.json'); +console.log("version: "+package_version.version); + mongoose.connect(process.env.MONGODB_URI); var db = mongoose.connection; From d2d966a47314a54392662ca60784ec8c2c95f6be Mon Sep 17 00:00:00 2001 From: Pierre Repetto-Andipatin Date: Wed, 15 Feb 2017 08:54:55 +0100 Subject: [PATCH 10/16] fix: lint the code --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 2b79e71..083d02b 100644 --- a/index.js +++ b/index.js @@ -5,8 +5,8 @@ var mongoose = require('mongoose'); mongoose.Promise = require('bluebird'); var Location = require('./models/Location.js'); -var package_version = require('./package.json'); -console.log("version: "+package_version.version); +var packageVersion = require('./package.json'); +console.log('version: ' + packageVersion.version); mongoose.connect(process.env.MONGODB_URI); From d61761a3107c5c7bef66f52551f1f818dceb0ec9 Mon Sep 17 00:00:00 2001 From: Akila Nonis Date: Thu, 16 Feb 2017 23:55:15 +0530 Subject: [PATCH 11/16] Enhancement 02 - Save random locations --- index.js | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 083d02b..fcae361 100644 --- a/index.js +++ b/index.js @@ -24,7 +24,7 @@ db.once('open', () => { break; } default: { - saveSimple(); + saveLocation(); } } }); @@ -41,6 +41,14 @@ function flush() { }); } +function saveLocation(){ + if(process.env.BULK_SAVE > 0){ + saveMultiple(process.env.BULK_SAVE); + }else{ + saveSimple(); + }; +} + function saveSimple() { var location = new Location({ timestamp: new Date().getTime(), @@ -57,3 +65,30 @@ function saveSimple() { process.exit(1); }); } + +function saveMultiple(count){ + + var locations = []; + + // Creating locations with random coordinates and adding them to an array + for(var i=0; i { + console.log(locations); + process.exit(0); + }) + .catch(err => { + console.error(err); + process.exit(1); + });; +} + From 2555367fb22f279815c407c57aac0e3ea43c146a Mon Sep 17 00:00:00 2001 From: Pierre Repetto-Andipatin Date: Fri, 17 Feb 2017 12:56:34 +0100 Subject: [PATCH 12/16] fix: lint and newer bulk save function --- index.js | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/index.js b/index.js index fcae361..4c7f9d6 100644 --- a/index.js +++ b/index.js @@ -41,12 +41,12 @@ function flush() { }); } -function saveLocation(){ - if(process.env.BULK_SAVE > 0){ - saveMultiple(process.env.BULK_SAVE); - }else{ - saveSimple(); - }; +function saveLocation() { + if (process.env.BULK_SAVE > 0) { + saveMultiple(process.env.BULK_SAVE); + } else { + saveSimple(); + } } function saveSimple() { @@ -66,22 +66,22 @@ function saveSimple() { }); } -function saveMultiple(count){ +function saveMultiple(count) { var locations = []; - - // Creating locations with random coordinates and adding them to an array - for(var i=0; i { console.log(locations); process.exit(0); @@ -89,6 +89,5 @@ function saveMultiple(count){ .catch(err => { console.error(err); process.exit(1); - });; + }); } - From 2b374466c1095b3056ef9db86c8413efd5497e5c Mon Sep 17 00:00:00 2001 From: Akila Nonis Date: Wed, 22 Feb 2017 23:27:58 +0530 Subject: [PATCH 13/16] Enhancement 03 - Find locations --- index.js | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/index.js b/index.js index 4c7f9d6..5e9cb07 100644 --- a/index.js +++ b/index.js @@ -23,6 +23,10 @@ db.once('open', () => { flush(); break; } + case 'find': { + findLocation(); + break; + } default: { saveLocation(); } @@ -91,3 +95,65 @@ function saveMultiple(count) { process.exit(1); }); } + +function findLocation() { + + var latitudeRange, longitudeRange, timestampRange; + + var query = Location.find({}); + + // Latitude Range + if(process.env.LATITUDE_RANGE){ + latitudeRange = process.env.LATITUDE_RANGE.split('-'); + if(latitudeRange.length == 1){ + query.where('latitude').equals(latitudeRange[0]); + }else{ + if(latitudeRange[0]){ + query.where('latitude').gte(latitudeRange[0]); + } + if(latitudeRange[1]){ + query.where('latitude').lte(latitudeRange[1]); + } + } + } + + // Longitude Range + if(process.env.LONGITUDE_RANGE){ + longitudeRange = process.env.LONGITUDE_RANGE.split('-'); + if(longitudeRange.length == 1){ + query.where('longitude').equals(longitudeRange[0]); + }else{ + if(longitudeRange[0]){ + query.where('longitude').gte(longitudeRange[0]); + } + if(longitudeRange[1]){ + query.where('longitude').lte(longitudeRange[1]); + } + } + } + + // Timestamp range + if(process.env.TIMESTAMP_RANGE){ + timestampRange = process.env.TIMESTAMP_RANGE.split('-'); + if(timestampRange.length == 1){ + query.where('timestamp').equals(timestampRange[0]); + }else{ + if(timestampRange[0]){ + query.where('timestamp').gte(timestampRange[0]); + } + if(timestampRange[1]){ + query.where('timestamp').lte(timestampRange[1]); + } + } + } + + query.then(locations => { + console.log(locations); + console.log('Results :' + locations.length); + process.exit(0); + }) + .catch(err => { + console.error(err); + process.exit(1); + }); +} From 326aa15bb5bb62be6fdc79fd5270b23c631e8539 Mon Sep 17 00:00:00 2001 From: Pierre Repetto-Andipatin Date: Thu, 23 Feb 2017 15:34:44 +0100 Subject: [PATCH 14/16] Update README.md --- README.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/README.md b/README.md index 7754aad..b0fc325 100644 --- a/README.md +++ b/README.md @@ -3,9 +3,29 @@ Locations Location generator in node +Usage +----- + +ACTION=find LATITUDE_RANGE=- LONGITUDE_RANGE=- TIMESTAMP_RANGE=- npm start + +Example: +``` +$ ACTION=find LATITUDE_RANGE=20-30 npm start +``` + +If it is needed to search for the exact value rather than a range just specify only the value in front of the relevant tag. + +ACTION=find LATITUDE_RANGE= LONGITUDE_RANGE= TIMESTAMP_RANGE= npm start + +Example: +``` +ACTION=find LONGITUDE_RANGE=75 npm start +``` + Author ------ +* Akila Nonis - * Kasun Samarasinghe - * Pierre Repetto-Andipatin - From 4e516848fdb0ea634fe2a3a6ea8e739a350a6a9e Mon Sep 17 00:00:00 2001 From: isharau Date: Wed, 22 Mar 2017 01:59:43 +0530 Subject: [PATCH 15/16] initial_commit --- index.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/index.js b/index.js index 5e9cb07..d6c106c 100644 --- a/index.js +++ b/index.js @@ -27,6 +27,11 @@ db.once('open', () => { findLocation(); break; } + case 'delete': { + findLocation(); + flush(); + break; + } default: { saveLocation(); } From e1185a0ee22965f8358075a92419bcce0c322690 Mon Sep 17 00:00:00 2001 From: isharau Date: Sun, 26 Mar 2017 16:24:19 +0530 Subject: [PATCH 16/16] delete option fixed and getAll method added for testability --- index.js | 61 +++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 45 insertions(+), 16 deletions(-) diff --git a/index.js b/index.js index d6c106c..155adaf 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,7 @@ 'use strict'; +var async = require('async'); + require('dotenv').config({ silent: true }); var mongoose = require('mongoose'); mongoose.Promise = require('bluebird'); @@ -23,13 +25,13 @@ db.once('open', () => { flush(); break; } - case 'find': { - findLocation(); + case 'find': + case 'delete': { + findOrDeleteLocation(); break; } - case 'delete': { - findLocation(); - flush(); + case 'getAll': { + getAllLocations(); break; } default: { @@ -38,6 +40,20 @@ db.once('open', () => { } }); +function getAllLocations() { + console.log("all the data "); + Location.find(function(err, searchedLocations) { + if (err) { + console.log(err); + throw err; + } + console.log(searchedLocations); + console.log('total content count : ' +searchedLocations.length); + process.exit(0); +}); + + +} function flush() { Location.remove({}).exec() .then(() => { @@ -101,7 +117,7 @@ function saveMultiple(count) { }); } -function findLocation() { +function findOrDeleteLocation() { var latitudeRange, longitudeRange, timestampRange; @@ -151,14 +167,27 @@ function findLocation() { } } } - - query.then(locations => { - console.log(locations); - console.log('Results :' + locations.length); - process.exit(0); - }) - .catch(err => { - console.error(err); - process.exit(1); - }); + //after setting the find query in above, execute to get the findings or delete + if (process.env.ACTION == 'delete') { + query.remove({}).exec(function(err) { + console.log('deleted the found'); + process.exit(0); + }).catch(err => { + + console.error(err + 'the errror'); + process.exit(1); + }); + } + else { + console.log('in querying '); + query.exec(function(err, foundLocations) { + console.log(foundLocations); + console.log('Results :' + foundLocations.length); + process.exit(0); + }) + .catch(err => { + console.error(err); + process.exit(1); + }); + } }