Skip to content

Commit

Permalink
Commit hightime
Browse files Browse the repository at this point in the history
This reverts commit 6763a26. (reverted from commit 71c2e2c)
  • Loading branch information
rheajain committed Dec 12, 2016
1 parent c776e19 commit 8fc8491
Show file tree
Hide file tree
Showing 16 changed files with 566 additions and 33 deletions.
43 changes: 36 additions & 7 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,51 @@ var Schema = mongoose.Schema;
var app = express();
var router = express.Router();
var login = require("./routes/login");
var mall = require("./routes/mall");
var shop = require("./routes/shop");
var product = require("./routes/product");
var Customer = require("./schemas/customer");
var search = require("./routes/search");

app.use(bodyParser.urlencoded());
app.use(bodyParser.json());

app.use('/users', login);

app.get('/', function (req, res) {
res.send('Hello World');
});
app.use('/search', search);
app.use('/product', product);
app.use('/shop', shop);

app.use('/login', login);
//app.use('/users', users);

app.post("/signUp", function(re, rea){
app.get("/signUp", function(req, res){
res.status(200).send({otp:"123"});
});

var server = app.listen(8088, function () {
app.post("/register", function (req, res) {
console.log("came here");
if( req.body.phoneNo){
var person = new Customer(req.body);
// Customer.create(person, function(err, response){
// if(err){
// console.log(err);
// res.status(400).send(err);
// } else{
// console.log(req.body);
// res.send(response);
// }
// });
console.log(person);
Customer.create(person).then(function(result){
res.send(result);
}).catch( function(e){
res.status(400).send(e);
});
} else {
res.status(400).send("Bad request");
}
});

var server = app.listen(8080,'0.0.0.0',function () {
var host = server.address().address;
var port = server.address().port;
console.log("Example app listening at http://%s:%s", host, port);
Expand Down
Binary file added images/Big-Bazaar-Store.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 29 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "smart-shop",
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/rheajain/smartShop.git"
},
"keywords": [
"shopping",
"malls",
"shops",
"market"
],
"author": "Rhea Jain",
"license": "ISC",
"bugs": {
"url": "https://github.com/rheajain/smartShop/issues"
},
"homepage": "https://github.com/rheajain/smartShop#readme",
"dependencies": {
"geo-nearby": "^2.0.1",
"mongoose-geojson-schema": "^2.1.2"
}
}
38 changes: 17 additions & 21 deletions routes/login.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,26 @@
var express = require('express');
var router = express.Router();
var app = require('../app');
var customer = require('../schemas/customer');
var Customer = require('../schemas/customer');
var mongoose = require('mongoose');

router.route('/login')
router.route('/')

// show the form (GET http://localhost:8080/login)
.get(function(req, res) {
console.log("Came to this page");
res.send('this is the login form');
})
// .get(function(req, res) {
// console.log("Came to this page");
// res.send('this is the login form');
// })

// process the form (POST http://localhost:8080/login)
.post(function(req, res) {
console.log('processing');
res.send('processing the login form!');
var person = new customer(req.body);
customer.create(req.body, function(err, r){
if(err){
console.log(err);

} else{
console.log(req.body);
console.log(r);
}
});
if(req.body){
Customer.findOne({ phoneNo : req.body.phoneNo}).exec().then(function(result){
res.send(result);
}).catch( function(e){
res.status(400).send(e);
});
} else{
res.status(404).send("No details found.");
}
});

module.exports =router;
module.exports = router;
64 changes: 64 additions & 0 deletions routes/mall.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
var express = require('express');
var router = express.Router();
var app = require('../app');
var Mall = require('../schemas/mall');

router.get("/search", function(req, res) {
console.log("Searching mall");
Mall.find({name :req.query.name}).exec().then( function(result){
if(result){
res.send(result);
} else{
res.status(404).send("Resource not found.");
}
}).catch( function(err){
res.status(400).send(err);
});
});

router.get("/:id", function(req, res) {
console.log("Getting information of mall with id- ", req.params.id);
Mall.findById(req.params.id).exec().then( function(result){
if(result){
res.send(result);
} else{
res.status(404).send("Resource not found.");
}
}).catch( function(err){
res.status(400).send(err);
});
});

router.route('/')

.get(function(req, res){
//dump all malls
Mall.find().exec().then( function(result){
if(result){
res.send(result);
} else{
res.status(404).send("Resource not found.");
}
}).catch( function(err){
res.status(400).send(err);
});
})

.post(function(req, res) {
console.log('Creating a new mall');
if(req.body){
var mall = new Mall(req.body);
Mall.create(mall).then(function(result){
res.send(result);
}).catch( function(e){
res.status(400).send(e);
});
}
})

/*.put("/:id", function(req, res){
res.send();
})*/

module.exports =router;
62 changes: 62 additions & 0 deletions routes/product.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
var express = require('express');
var router = express.Router();
var app = require('../app');
var Product = require('../schemas/product');

router.get("/search", function(req, res) {
console.log("Searching product");
Product.find({name :req.query.name}).exec().then( function(result){
if(result){
res.send(result);
} else{
res.status(404).send("Resource not found.");
}
}).catch( function(err){
res.status(400).send(err);
});
});

router.get("/:id", function(req, res) {
console.log("Getting information of product with id- ", req.params.id);
Product.findById(req.params.id).exec().then( function(result){
if(result){
res.send(result);
} else{
res.status(404).send("Resource not found.");
}
}).catch( function(err){
res.status(400).send(err);
});
});

router.route('/')



.get(function(req, res){
//dump all products
Product.find().exec().then( function(result){
if(result){
res.send(result);
} else{
res.status(404).send("Resource not found.");
}
}).catch( function(err){
res.status(400).send(err);
});
})

.post(function(req, res) {
console.log('Creating a new product');
if(req.body){
var product = new Product(req.body);
Product.create(product).then(function(result){
res.send(result);
}).catch( function(e){
res.status(400).send(e);
});
}
})


module.exports =router;
10 changes: 10 additions & 0 deletions routes/route.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
var express = require('express');
var router = express.Router();

router.get("/", function(req, res){
if(req.user.latitude && req.user.longitude){

}
});

module.exports = router;
91 changes: 91 additions & 0 deletions routes/search.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
var express = require('express');
var router = express.Router();
var mongoose = require('mongoose');
var GeoJSON = require('mongoose-geojson-schema');
var Shop = require('../schemas/shop');
var Mall = require('../schemas/mall');
var Product = require('../schemas/product');
const Geo = require('geo-nearby');

//var loc = mongoose.Schema.Types.Point;

// const data = [
// [-35.30278, 149.14167, 'Canberra'],
// [-33.86944, 151.20833, 'Sydney'],
// [-37.82056, 144.96139, 'Melbourne'],
// [-34.93333, 138.58333, 'Adelaide'],
// [-27.46778, 153.02778, 'Brisbane'],
// [-31.95306, 115.85889, 'Perth']
// ];



router.get("/nearby", function(req, res){
//if(loc){
// var dataSet = [
// { i: 'Perth', g: 3149853951719405 },
// { i: 'Adelaide', g: 3243323516150966 },
// { i: 'Melbourne', g: 3244523307653507 },
// { i: 'Canberra', g: 3251896081369449 },
// { i: 'Sydney', g: 3252342838034651 },
// { i: 'Brisbane', g: 3270013708086451 },
// { i: 'Sydney', g: 3252342838034651 }
// ];
// var geo = new Geo(dataSet);
// var a = geo.nearBy(-33.87, 151.2, 5000);
// console.log(a);

const data = [
[12.933192, 77.612205, 'Big bazaar'],
[12.933579, 77.612419, 'Shopers Stop'],
[12.934029, 77.611175, 'More supermarket'],
[12.934298, 77.610859, 'KFC'],
[12.934570, 77.611771, 'Westside'],
[12.934560, 77.611288, 'The Forum'],
[12.934445, 77.613434, 'Gramin'],
[12.935020, 77.608799, 'Punjabi by Nature'],
[12.936808, 77.610441, 'Start Bazaar'],
[12.935177, 77.613491, 'Startbucks'],
[12.933823, 77.612300, 'Bata'],
[12.934215, 77.611195, 'Puma'],
[12.935328, 77.612847, "Baby's Dayout"],
[12.934680, 77.612455, 'State Bank ATM'],
[12.934680, 77.613496, 'Citi Bank ATM'],
[12.935213, 77.614483, 'ICICI Bank'],
[12.936531, 77.616049, 'Sapna Book House'],
[12.935595, 77.614385, 'Bowling Machine and ames'],
[12.933934, 77.621245, 'Escape room'],
[12.930758, 77.622640, 'Cafe coffe Day'],
[12.937575, 77.628006, 'Oasis mall']

];
const dataSet = Geo.createCompactSet(data);
const geo = new Geo(dataSet, { sorted: true });

console.log(geo.nearBy(12.934607, 77.625298, 2000));
res.send(geo.nearBy(12.934607, 77.625298, 2000));
//}
});

router.post('/route', function(req, res){
if(req.body.list){

} else{
res.status(404).send("Wishlist not found.");
}
});

router.get('/:keyword', function(req, res){
if(req.params.keyword!==""){
var promise1 = Product.find({name: req.params.keyword}).exec();
var promise2 = Mall.find({name: req.params.keyword}).exec();
var promise3 = Shop.find({name : req.params.keyword}).exec();
Promise.all([promise1, promise2, promise3]).then( function(result){
res.send(result);
}).catch( function(err){
res.status(400).send(err);
})
}
});

module.exports = router;
Loading

0 comments on commit 8fc8491

Please sign in to comment.