Skip to content

Commit 810e6de

Browse files
committed
documentation updated 2
1 parent afe82bd commit 810e6de

File tree

13 files changed

+133
-3
lines changed

13 files changed

+133
-3
lines changed

controllers/booking.controller.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ const bookingService = require("../services/booking.service");
22
const slotService = require("../services/slot.service");
33
const garageService = require("../services/garage.service");
44

5+
/* ------------ Controllers ----------- */
6+
7+
//renderNewBooking... renders the new booking page
58
const renderNewBooking = async (req, res) => {
69
var slot_id = req.params.id;
710
var slot = await slotService.FindSlot(slot_id);
@@ -24,6 +27,7 @@ const renderNewBooking = async (req, res) => {
2427
}
2528
};
2629

30+
//newBooking... creates a new booking calculating the price, and redirects to the dashboard
2731
const newBooking = async (req, res) => {
2832
req.body.start_time = new Date(req.body.start_datetime).getTime() / 1000;
2933
req.body.end_time = new Date(req.body.end_datetime).getTime() / 1000;
@@ -40,6 +44,7 @@ const newBooking = async (req, res) => {
4044
}
4145
};
4246

47+
//renderBooking... renders the booking page
4348
const renderBooking = async (req, res) => {
4449
var booking_id = req.params.id;
4550
const booking = await bookingService.FindBooking(booking_id);
@@ -51,6 +56,7 @@ const renderBooking = async (req, res) => {
5156
}
5257
};
5358

59+
//deleteBooking... deletes a booking and redirects to the dashboard
5460
const deleteBooking = async (req, res) => {
5561
var booking_id = req.params.id;
5662
try {
@@ -63,6 +69,7 @@ const deleteBooking = async (req, res) => {
6369
}
6470
};
6571

72+
//cancelBooking... cancels a booking and redirects to the dashboard
6673
const cancelBooking = async (req, res) => {
6774
var id = req.params.id;
6875
try {

controllers/garage.controller.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,36 @@
11
const garageService = require("../services/garage.service");
22
const slotService = require("../services/slot.service");
3-
const mbxGeocoding = require("@mapbox/mapbox-sdk/services/geocoding");
3+
const mbxGeocoding = require("@mapbox/mapbox-sdk/services/geocoding"); // mapbox geocoding api
44
const mapBoxToken = process.env.MAPBOX_TOKEN;
55
const geocoder = mbxGeocoding({ accessToken: mapBoxToken });
66
var axios = require('axios');
77

8+
/* ------------ Controllers ----------- */
9+
10+
//renderAddGarage... renders the add garage page
811
const renderAddGarage = (req, res) => {
912
res.render("garages/newgarages", { body: req.body });
1013
};
1114

15+
//addGarage... adds a new garage to the database
1216
const addGarage = async (req, res) => {
1317
try {
18+
// checking if request body has an image
1419
if (req.file) {
1520
var path = req.file.path;
1621
req.body.picture_url = path;
1722
}
23+
// geocding the location
1824
const geoData = await geocoder
1925
.forwardGeocode({
2026
query: req.body.location,
2127
limit: 1,
2228
})
2329
.send();
30+
// getting the coordinates
2431
req.body.geometry = geoData.body.features[0].geometry;
32+
33+
// adding the garage
2534
const result = await garageService.AddGarage(req.body);
2635
req.flash("success", "Garage Added Successfully");
2736
res.redirect("/garage/");
@@ -46,6 +55,7 @@ const renderGarage = async (req, res) => {
4655
}
4756
};
4857

58+
//renderAllGarages... renders all the garages in the database
4959
const renderAllGarages = async (req, res) => {
5060
var garages = await garageService.AllGarages();
5161
res.render("garages/allgarages", {
@@ -55,6 +65,7 @@ const renderAllGarages = async (req, res) => {
5565
});
5666
};
5767

68+
//apiSlotInfo... returns the slots info of a garage
5869
const apiSlotInfo = async (req, res) => {
5970
var garage_id = req.params.id;
6071
var garage = await garageService.FindGarage(garage_id);
@@ -77,6 +88,7 @@ const apiSlotInfo = async (req, res) => {
7788
res.send(str);
7889
};
7990

91+
//renderEditGarage... renders the edit garage page
8092
const deleteGarage = async (req, res) => {
8193
try {
8294
var id = req.params.id;
@@ -89,11 +101,14 @@ const deleteGarage = async (req, res) => {
89101
}
90102
};
91103

104+
//renderFindGarage... renders the find garage page
92105
const renderfindgarage=async(req,res)=>
93106
{
94107
res.render("garages/findgarage",{ body: req.body});
95108
}
96109

110+
//TODO: IN PROGRESS
111+
//rendergaragebyIp... renders the garages in progress
97112
const rendergaragebyip=async(req,res)=>
98113
{
99114
if(req.ipv4!==undefined)
@@ -113,6 +128,7 @@ const rendergaragebyip=async(req,res)=>
113128
res.render("garages/foundgarage",{ body: req.body, by:"IP"})
114129
}
115130

131+
//rendergaragebyloc... renders the garages in progress
116132
const rendergaragebyloc=async(req,res)=>
117133
{
118134
try{
@@ -123,6 +139,7 @@ const rendergaragebyloc=async(req,res)=>
123139
}
124140
else
125141
{
142+
// geocding the location taken from user
126143
const geoData = await geocoder
127144
.forwardGeocode({
128145
query: req.body.location,
@@ -135,6 +152,7 @@ const rendergaragebyloc=async(req,res)=>
135152
var min_distance=10000000.0;
136153
var dist={};
137154
for (let garage of garages){
155+
// getting the distance between the garage and the user
138156
var distance=garageService.DistanceCal(geometry.coordinates[1],geometry.coordinates[0],
139157
garage.geometry.coordinates[1],garage.geometry.coordinates[0]);
140158
if(distance<=min_distance)

controllers/slot.controller.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@ const slotService = require("../services/slot.service");
22
const garageService = require("../services/garage.service");
33
const bookingService = require("../services/booking.service");
44

5+
/* ------------ Controllers ----------- */
6+
7+
//renderAddSlot... renders add slot page
58
const renderAddSlot = (req, res) => {
69
var garage_id = req.params.id;
710
res.render("slots/addslot", { garage_id: garage_id, body: req.body });
811
};
912

13+
14+
//addSlot... adds a new slot to the garage
1015
const addSlot = async (req, res) => {
1116
try {
1217
const result = await slotService.AddSlot(req.body);
@@ -18,6 +23,7 @@ const addSlot = async (req, res) => {
1823
}
1924
};
2025

26+
//renderSlot... renders the slot page
2127
const renderSlot = async (req, res) => {
2228
var slot_id = req.params.id;
2329
const slot = await slotService.FindSlot(slot_id);
@@ -41,6 +47,7 @@ const renderSlot = async (req, res) => {
4147
}
4248
};
4349

50+
//deleteSlot... deletes a slot from the garage
4451
const deleteSlot = async (req, res) => {
4552
var slot_id = req.params.id;
4653
try {
@@ -52,6 +59,7 @@ const deleteSlot = async (req, res) => {
5259
}
5360
};
5461

62+
//renderSlot... renders the slot page
5563
const renderSlots = async (req, res) => {
5664
var garage_id = req.params.id;
5765
var garage = await garageService.FindGarage(garage_id);
@@ -73,6 +81,7 @@ const renderSlots = async (req, res) => {
7381
}
7482
};
7583

84+
//findBookings... returns all bookings for a slot
7685
const findBookings = async (id) => {
7786
var slot = await slotService.FindSlot(id);
7887
if (!slot) return "Slot Not Found";
@@ -85,6 +94,7 @@ const findBookings = async (id) => {
8594
return arr_booking;
8695
};
8796

97+
//apiBooking... returns all booking details for a slot
8898
const apiBooking = async (req, res) => {
8999
var slot_id = req.params.id;
90100
var arr_booking = await findBookings(slot_id);

controllers/user.controller.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ const garageService=require("../services/garage.service");
44
const slotService=require("../services/slot.service");
55
const jwt = require("jsonwebtoken");
66

7+
/* ------------ Configs ----------- */
8+
9+
// cookie options
710
let options = {
811
path: "/",
912
sameSite: true,
@@ -17,12 +20,21 @@ let options_otp = {
1720
maxAge: 1000 * 60 * 5,
1821
httpOnly: true,
1922
};
23+
24+
/* ------------ Controllers ----------- */
25+
26+
27+
//renderRegister... renders the register page
2028
const renderRegister = (req, res) => {
2129
res.render("users/register");
2230
};
31+
32+
//renderLogin... renders the login page
2333
const renderLogin = (req, res) => {
2434
res.render("users/login");
2535
};
36+
37+
//renderDashboard... renders the dashboard page
2638
const renderDashboard = async (req, res) => {
2739
var bookings = await bookingService.FindByUser(req.body.user_id);
2840
for (let booking of bookings) {
@@ -35,9 +47,13 @@ const renderDashboard = async (req, res) => {
3547
}
3648
res.render("users/dashboard", { body: req.body, bookings: bookings });
3749
};
50+
51+
//renderAddMoney... renders the add money page
3852
const renderAddMoney = (req, res) => {
3953
res.render("users/addmoney", { money: req.body.money, body: req.body });
4054
};
55+
56+
//renderVerify... renders the otp verify page
4157
const renderVerify = async (req, res) => {
4258
if (req.body.verified === true) {
4359
res.send("Already Verified");
@@ -47,6 +63,8 @@ const renderVerify = async (req, res) => {
4763
res.render("users/verify", { email: req.body.email });
4864
}
4965
};
66+
67+
//renderRegister... renders the register page
5068
const register = async (req, res) => {
5169
try {
5270
const result = await userService.Register(req.body);
@@ -59,6 +77,7 @@ const register = async (req, res) => {
5977
}
6078
};
6179

80+
//sendOtp... sends otp to the user
6281
const sendOtp = async (username) => {
6382
try {
6483
var gen_otp = await userService.generateOtp(username);
@@ -68,6 +87,7 @@ const sendOtp = async (username) => {
6887
}
6988
};
7089

90+
// login... logs in the user
7191
const login = async (req, res) => {
7292
try {
7393
const result = await userService.Login(
@@ -83,12 +103,14 @@ const login = async (req, res) => {
83103
}
84104
};
85105

106+
// logout... logs out the user
86107
const logout = (req, res) => {
87108
res.clearCookie("isloggedin");
88109
req.flash("success", "Logged out Successfully.");
89110
res.redirect("/");
90111
};
91112

113+
//verify.. verifies the otp and logs in the user
92114
const verify = async (req, res) => {
93115
var otp = req.body.otp;
94116
let token = req.cookies["otp"];
@@ -106,10 +128,12 @@ const verify = async (req, res) => {
106128
}
107129
};
108130

131+
//renderImageChange... renders the upload image page
109132
const renderImage = (req, res) => {
110133
res.render("users/uploadimage", { body: req.body });
111134
};
112135

136+
//upload Image... uploads the image
113137
const uploadImage = async (req, res) => {
114138
var path = req.file["path"];
115139
var userid = req.body.user_id;
@@ -124,6 +148,7 @@ const uploadImage = async (req, res) => {
124148
}
125149
};
126150

151+
//addMoney... adds money to the user
127152
const addMoney = async (req, res) => {
128153
var add_money = req.body.added_money;
129154
try {
@@ -136,6 +161,7 @@ const addMoney = async (req, res) => {
136161
}
137162
};
138163

164+
//apiOtp... compares the given otp with the otp stored in cookie
139165
const apiOtp = (req, res) => {
140166
var str = req.params.value;
141167
let token = req.cookies["otp"];
@@ -144,11 +170,13 @@ const apiOtp = (req, res) => {
144170
else res.send("0");
145171
};
146172

173+
//resendOtp... resends the otp to the user
147174
const resendOTP = (req, res) => {
148175
req.flash("alert", "Your OTP has been resent successfully to your email.");
149176
res.redirect("/users/verify");
150177
};
151178

179+
//renderTransactions... renders the transactions page
152180
const renderTransactions = async (req, res) => {
153181
var transactions = await userService.getTransactions(req.body.user_id);
154182
res.render("users/transactions", {
@@ -157,6 +185,7 @@ const renderTransactions = async (req, res) => {
157185
});
158186
};
159187

188+
//renderBookings... renders the booking page
160189
const renderBookings = async (req, res) => {
161190
var bookings = await bookingService.FindByUser(req.body.user_id);
162191
for (let booking of bookings) {
@@ -170,6 +199,7 @@ const renderBookings = async (req, res) => {
170199
res.render("users/bookings", { body: req.body, bookings: bookings });
171200
};
172201

202+
//renderBooking... renders the booking details page
173203
const renderBooking=async(req,res)=>
174204
{
175205
var id=req.params.id;

models/user.model.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ const userSchema = new Schema(
4848
}
4949
);
5050

51-
userSchema.pre("save", async function (next) {
51+
// hashes the password before saving using bcrypt
52+
userSchema.pre("save", async function (next) {
5253
if (!this.isModified || !this.isNew) {
5354
next();
5455
} else this.isModified("password");

routes/booking.route.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1+
/* ------------ Imports ----------- */
2+
13
const express = require("express");
24
const Router = express.Router();
35
const bookingController = require("../controllers/booking.controller");
46
const IsLoggedInMiddleware = require("../middleware/login.middleware");
57
const sanitizerMiddleware = require("../middleware/sanitizer.middleware");
68

9+
/* ------------ Endpoint Definitions ----------- */
10+
711
Router.route("/new/:id")
812
.get(IsLoggedInMiddleware(), bookingController.renderNewBooking)
913
.post(IsLoggedInMiddleware(), bookingController.newBooking);

routes/garage.route.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* ------------ Imports ----------- */
2+
13
const express = require("express");
24
const Router = express.Router();
35
const multer = require("multer");
@@ -9,6 +11,8 @@ const sanitizerMiddleware = require("../middleware/sanitizer.middleware");
911
const IsAdminMiddleware = require("../middleware/isadmin.middleware");
1012
const getIpMiddleware=require("../middleware/ip.middleware");
1113

14+
/* ------------ Endpoint Definitions ----------- */
15+
1216
Router.route("/").get(
1317
IsLoggedInMiddleware(),
1418
garageController.renderAllGarages

0 commit comments

Comments
 (0)