Skip to content

Commit 641b982

Browse files
Merge pull request #1 from Codehackerone/dev
Dev
2 parents 7b1c670 + 6d67ff2 commit 641b982

15 files changed

+4289
-32
lines changed

controllers/garage.controller.js

+77
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const slotService = require("../services/slot.service");
33
const mbxGeocoding = require("@mapbox/mapbox-sdk/services/geocoding");
44
const mapBoxToken = process.env.MAPBOX_TOKEN;
55
const geocoder = mbxGeocoding({ accessToken: mapBoxToken });
6+
var axios = require('axios');
67

78
const renderAddGarage = (req, res) => {
89
res.render("garages/newgarages", { body: req.body });
@@ -87,11 +88,87 @@ const deleteGarage = async (req, res) => {
8788
res.redirect("/garage/");
8889
}
8990
};
91+
92+
const renderfindgarage=async(req,res)=>
93+
{
94+
res.render("garages/findgarage",{ body: req.body});
95+
}
96+
97+
const rendergaragebyip=async(req,res)=>
98+
{
99+
if(req.ipv4!==undefined)
100+
{
101+
var config = {
102+
method: 'get',
103+
url: 'http://ip-api.com/json/'
104+
};
105+
axios(config)
106+
.then(function (response) {
107+
console.log(JSON.stringify(response.data));
108+
})
109+
.catch(function (error) {
110+
console.log(error);
111+
});
112+
}
113+
res.render("garages/foundgarage",{ body: req.body, by:"IP"})
114+
}
115+
116+
const rendergaragebyloc=async(req,res)=>
117+
{
118+
try{
119+
if(!req.body.location)
120+
{
121+
req.flash('err','location not given');
122+
res.redirect('/garage/find');
123+
}
124+
else
125+
{
126+
const geoData = await geocoder
127+
.forwardGeocode({
128+
query: req.body.location,
129+
limit: 1,
130+
})
131+
.send();
132+
var geometry = geoData.body.features[0].geometry;
133+
geometry.place_name=req.body.location;
134+
var garages=await garageService.AllGarages();
135+
var min_distance=10000000.0;
136+
var dist={};
137+
for (let garage of garages){
138+
var distance=garageService.DistanceCal(geometry.coordinates[1],geometry.coordinates[0],
139+
garage.geometry.coordinates[1],garage.geometry.coordinates[0]);
140+
if(distance<=min_distance)
141+
{
142+
dist=garage;
143+
min_distance=distance;
144+
}
145+
}
146+
if(min_distance>1000.0)
147+
{
148+
req.flash("err","Sorry! No garages found within 1000.0 km radius.")
149+
res.redirect("/garage/find");
150+
}
151+
else{
152+
res.render("garages/foundgarage",{ body: req.body,by:"Location",geometry:geometry,maptoken: mapBoxToken,garage:dist,
153+
min_distance:min_distance});
154+
}
155+
}
156+
}
157+
catch(err)
158+
{
159+
req.flash("err","Err: "+err);
160+
res.redirect("/garage/find");
161+
}
162+
}
163+
90164
module.exports = {
91165
renderAddGarage,
92166
addGarage,
93167
renderGarage,
94168
renderAllGarages,
95169
apiSlotInfo,
96170
deleteGarage,
171+
renderfindgarage,
172+
rendergaragebyip,
173+
rendergaragebyloc
97174
};

controllers/user.controller.js

+17
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
const userService = require("../services/user.service");
22
const bookingService = require("../services/booking.service");
3+
const garageService=require("../services/garage.service");
4+
const slotService=require("../services/slot.service");
35
const jwt = require("jsonwebtoken");
46

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

173+
const renderBooking=async(req,res)=>
174+
{
175+
var id=req.params.id;
176+
var booking=await bookingService.FindBooking(id);
177+
if(!booking){
178+
req.flash("err", "No Booking Found");
179+
res.redirect("/users/dashboard");
180+
}
181+
else{
182+
var slot=await slotService.FindSlot(booking.slot_id);
183+
var garage=await garageService.FindGarage(slot.garage_id);
184+
res.render("users/mybooking",{ body: req.body, booking: booking ,slot:slot,garage:garage});
185+
}
186+
}
171187
module.exports = {
172188
renderLogin,
173189
renderRegister,
@@ -185,4 +201,5 @@ module.exports = {
185201
resendOTP,
186202
renderTransactions,
187203
renderBookings,
204+
renderBooking
188205
};

middleware/ip.middleware.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const RequestIp = require('@supercharge/request-ip')
2+
3+
const getIpMiddleware = function (req, res, next) {
4+
if(RequestIp.getClientIp(req)!=="::1")req.ipv2 = RequestIp.getClientIp(req);
5+
next();
6+
}
7+
8+
module.exports=getIpMiddleware;

models/booking.model.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const bookingSchema = new Schema(
2525
},
2626
status: {
2727
type: String,
28-
enum: ["Completed", "Cancelled", "Booked"],
28+
enum: ["Completed", "Cancelled", "Booked","CheckedIn"],
2929
default: "Booked",
3030
},
3131
},

0 commit comments

Comments
 (0)