Skip to content

Dev #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
May 23, 2021
Merged
77 changes: 77 additions & 0 deletions controllers/garage.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const slotService = require("../services/slot.service");
const mbxGeocoding = require("@mapbox/mapbox-sdk/services/geocoding");
const mapBoxToken = process.env.MAPBOX_TOKEN;
const geocoder = mbxGeocoding({ accessToken: mapBoxToken });
var axios = require('axios');

const renderAddGarage = (req, res) => {
res.render("garages/newgarages", { body: req.body });
Expand Down Expand Up @@ -87,11 +88,87 @@ const deleteGarage = async (req, res) => {
res.redirect("/garage/");
}
};

const renderfindgarage=async(req,res)=>
{
res.render("garages/findgarage",{ body: req.body});
}

const rendergaragebyip=async(req,res)=>
{
if(req.ipv4!==undefined)
{
var config = {
method: 'get',
url: 'http://ip-api.com/json/'
};
axios(config)
.then(function (response) {
console.log(JSON.stringify(response.data));
})
.catch(function (error) {
console.log(error);
});
}
res.render("garages/foundgarage",{ body: req.body, by:"IP"})
}

const rendergaragebyloc=async(req,res)=>
{
try{
if(!req.body.location)
{
req.flash('err','location not given');
res.redirect('/garage/find');
}
else
{
const geoData = await geocoder
.forwardGeocode({
query: req.body.location,
limit: 1,
})
.send();
var geometry = geoData.body.features[0].geometry;
geometry.place_name=req.body.location;
var garages=await garageService.AllGarages();
var min_distance=10000000.0;
var dist={};
for (let garage of garages){
var distance=garageService.DistanceCal(geometry.coordinates[1],geometry.coordinates[0],
garage.geometry.coordinates[1],garage.geometry.coordinates[0]);
if(distance<=min_distance)
{
dist=garage;
min_distance=distance;
}
}
if(min_distance>1000.0)
{
req.flash("err","Sorry! No garages found within 1000.0 km radius.")
res.redirect("/garage/find");
}
else{
res.render("garages/foundgarage",{ body: req.body,by:"Location",geometry:geometry,maptoken: mapBoxToken,garage:dist,
min_distance:min_distance});
}
}
}
catch(err)
{
req.flash("err","Err: "+err);
res.redirect("/garage/find");
}
}

module.exports = {
renderAddGarage,
addGarage,
renderGarage,
renderAllGarages,
apiSlotInfo,
deleteGarage,
renderfindgarage,
rendergaragebyip,
rendergaragebyloc
};
17 changes: 17 additions & 0 deletions controllers/user.controller.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const userService = require("../services/user.service");
const bookingService = require("../services/booking.service");
const garageService=require("../services/garage.service");
const slotService=require("../services/slot.service");
const jwt = require("jsonwebtoken");

let options = {
Expand Down Expand Up @@ -168,6 +170,20 @@ const renderBookings = async (req, res) => {
res.render("users/bookings", { body: req.body, bookings: bookings });
};

const renderBooking=async(req,res)=>
{
var id=req.params.id;
var booking=await bookingService.FindBooking(id);
if(!booking){
req.flash("err", "No Booking Found");
res.redirect("/users/dashboard");
}
else{
var slot=await slotService.FindSlot(booking.slot_id);
var garage=await garageService.FindGarage(slot.garage_id);
res.render("users/mybooking",{ body: req.body, booking: booking ,slot:slot,garage:garage});
}
}
module.exports = {
renderLogin,
renderRegister,
Expand All @@ -185,4 +201,5 @@ module.exports = {
resendOTP,
renderTransactions,
renderBookings,
renderBooking
};
8 changes: 8 additions & 0 deletions middleware/ip.middleware.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const RequestIp = require('@supercharge/request-ip')

const getIpMiddleware = function (req, res, next) {
if(RequestIp.getClientIp(req)!=="::1")req.ipv2 = RequestIp.getClientIp(req);
next();
}

module.exports=getIpMiddleware;
2 changes: 1 addition & 1 deletion models/booking.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const bookingSchema = new Schema(
},
status: {
type: String,
enum: ["Completed", "Cancelled", "Booked"],
enum: ["Completed", "Cancelled", "Booked","CheckedIn"],
default: "Booked",
},
},
Expand Down
Loading