Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions backend/src/routes/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ router.post("/login", validateAuth, async (req: Request, res: Response) => {
);

const user = (await users[0]) as User;
// console.log(user);

if (!user) {
res.status(401).json({
Expand All @@ -79,8 +78,7 @@ router.post("/login", validateAuth, async (req: Request, res: Response) => {
});
return;
}
// console.log(user.password);
// console.log(hashedPassword);


const refreshToken = generateRefreshToken(user.id!);
const accessToken = generateAccessToken(user.id!);
Expand All @@ -92,7 +90,6 @@ router.post("/login", validateAuth, async (req: Request, res: Response) => {
httpOnly: true,
maxAge: 24 * 60 * 60 * 1000,
});
// console.log(req.cookies.jwt);
res.status(200).json({ accessToken, isAdmin: user.is_admin, id: user.id });
} catch (error) {
const errorMessage = (error as Error).message;
Expand All @@ -112,15 +109,13 @@ router.get("/refresh", async (req: Request, res: Response) => {
}

const refreshToken = cookies.jwt;
// console.log(refreshToken);

const foundUser = (
await pool.query("SELECT * FROM users WHERE refresh_token = $1", [
refreshToken,
])
).rows[0];

// console.log(foundUser);

if (!foundUser) {
res.status(403).json({
Expand All @@ -137,13 +132,11 @@ router.get("/refresh", async (req: Request, res: Response) => {
process.env.REFRESH_TOKEN_SECRET!
) as JwtPayload;

console.log(payload.userId);
const accessToken = generateAccessToken(payload.userId);
res
.status(200)
.json({ accessToken, isAdmin: foundUser.is_admin, id: foundUser.id });
} catch (error) {
console.log(error);
} catch {
res.status(403).json({
title: "No Access Rights",
message: "You do not have access to these features.",
Expand Down
18 changes: 2 additions & 16 deletions backend/src/routes/cars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ router.post("/check-license", async (req: Request, res: Response) => {
);

const driverFound = drivers[0];
console.log(drivers);

if (!driverFound) {
res.status(401).json({
Expand Down Expand Up @@ -42,14 +41,6 @@ router.post("/add", async (req: Request, res: Response) => {
license_number,
}: Cars = req.body;

console.log(
car_model,
license_plate,
license_number,
color,
driver_id,
brand
);

const { rows: drivers } = await pool.query(
`SELECT id
Expand All @@ -67,7 +58,7 @@ router.post("/add", async (req: Request, res: Response) => {
return;
}

const car = await pool.query(
await pool.query(
`INSERT INTO cars (
driver_id,
car_model,
Expand All @@ -79,7 +70,6 @@ router.post("/add", async (req: Request, res: Response) => {

[driver_id, car_model, license_plate, brand, color, license_number]
);
console.log(car.rows);
res.status(200).json({
title: "Car Added!",
message: `Car ${brand} ${car_model} ${color} with a license plate of ${license_plate} has been added!`,
Expand All @@ -94,7 +84,6 @@ router.get("/get", async (req: Request, res: Response) => {
try {
const { driverId } = req.query;

console.log("Received driverId:", driverId);

if (!driverId) {
res.status(400).json({
Expand Down Expand Up @@ -162,7 +151,6 @@ router.patch("/update", async (req: Request, res: Response) => {
}

const updateCar = result.rows[0];
console.log("Car updated successfully:", updateCar);

res.status(200).json({
title: "Car Updated!",
Expand All @@ -177,9 +165,8 @@ router.patch("/update", async (req: Request, res: Response) => {

router.delete("/delete", async (req: Request, res: Response) => {
try {
console.log("Fetching. . .");

const car = await pool.query(
await pool.query(
`DELETE FROM
cars
WHERE
Expand All @@ -189,7 +176,6 @@ router.delete("/delete", async (req: Request, res: Response) => {
);

res.status(200).json({ message: "Car Added Successfully" });
console.log("Driver deleted successfully:", car);
} catch (error) {
const errorMessage = (error as Error).message;
res.status(500).json({ title: "Unknown Error", message: errorMessage });
Expand Down
8 changes: 1 addition & 7 deletions backend/src/routes/driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ router.post("/add", validateDriver, async (req: Request, res: Response) => {
license_expiration_date,
} = req.body as Driver;

const driver = await pool.query(
await pool.query(
`INSERT INTO drivers (
email,
first_name,
Expand All @@ -44,7 +44,6 @@ router.post("/add", validateDriver, async (req: Request, res: Response) => {
]
);

console.log(driver.rows);
res.status(200).json({
title: "Driver Added!",
message: `Driver ${last_name}, ${first_name} ${middle_name} has been added`,
Expand All @@ -59,13 +58,11 @@ router.post("/add", validateDriver, async (req: Request, res: Response) => {

router.get("/get", async (req: Request, res: Response) => {
try {
console.log("Fetching drivers from the database...");

const { rows: drivers } = await pool.query(
`SELECT *
FROM drivers`
);
console.log("Drivers fetched successfully:", drivers);

// Send the drivers list as a response
res.json(drivers);
Expand Down Expand Up @@ -101,7 +98,6 @@ router.get("/get/:driverId", async (req: Request, res: Response) => {
);

const foundDriver = await drivers[0];
console.log(foundDriver);

if (!foundDriver) {
res.status(404).json({ message: "Driver not found" });
Expand Down Expand Up @@ -193,7 +189,6 @@ router.patch("/update", async (req: Request, res: Response) => {
});

router.delete("/delete", async (req: Request, res: Response) => {
console.log("Request body:", req.body); // Log the incoming request body
try {
const { id } = req.body;

Expand Down Expand Up @@ -225,7 +220,6 @@ router.delete("/delete", async (req: Request, res: Response) => {
}

const deletedDriver = resultDriver.rows[0];
console.log("Driver deleted successfully:", deletedDriver);

res.status(200).json({
title: "Driver Deleted",
Expand Down
3 changes: 1 addition & 2 deletions backend/src/routes/notification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ router.get("/get-by-user", async (req: Req, res: Response) => {
} else {
res.json(notifications);
}
} catch (err) {
console.log(err);
} catch {
res.status(500).json({
title: "Server Error",
message: "An unexpected error occurred while retrieving notifications",
Expand Down
3 changes: 1 addition & 2 deletions backend/src/routes/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ router.get("/get/:id", async (req: Request, res: Response) => {
);

res.status(200).json({ ...foundDriver, violations, cars });
} catch (error) {
console.log(error);
} catch {
res.sendStatus(500);
}
});
Expand Down
8 changes: 0 additions & 8 deletions backend/src/routes/registration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@ const fetchRegistrationByLicense = async (license_number: string) => {
// GET route to fetch all registrations
router.get("/get", async (_req: Request, res: Response) => {
try {
console.log("Fetching registration from the database...");
const { rows: registrations } = await pool.query(
"SELECT user_id, license_number, school_email, first_name, last_name, middle_name, date_of_birth, driver_type, sex FROM registrations"
);
console.log("Registrations fetched successfully:", registrations);

res.json(registrations); // Send the registration list as a response
} catch (error) {
Expand All @@ -46,7 +44,6 @@ router.post("/add", async (req: Request, res: Response) => {
driver_type,
} = req.body as Registration;

console.log(req.body);
if (
![
license_number,
Expand Down Expand Up @@ -105,11 +102,6 @@ router.delete("/delete", async (req: Request, res: Response): Promise<void> => {
try {
const { license_number } = req.body as Registration; // Extract license_number from request body

console.log(
"Attempting to delete registration with license number:",
license_number
);

// Attempt to delete the registration
await pool.query(
`DELETE FROM registrations WHERE license_number = $1 RETURNING *`,
Expand Down
6 changes: 1 addition & 5 deletions backend/src/routes/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,10 @@ router.get("/get", async (req: Request, res: Response) => {
try {
const userId = req.user;

console.log(req.user);
console.log("Fetching user from the database...");
const { rows: users } = await pool.query(
"SELECT id, first_name, last_name FROM users WHERE id = $1",
[userId]
);
console.log("User fetched successfully:", users);

const { rows: registrations } = await pool.query(
"SELECT * FROM registrations WHERE user_id = $1",
Expand Down Expand Up @@ -102,9 +99,8 @@ router.patch("/change-password", async (req: Request, res: Response) => {
title: "Password Changed",
message: "Password has been successfully changed.",
});
} catch (error) {
} catch {
res.status(500).json({ message: "An Unknown Error Occured" });
console.log(error);
}
});

Expand Down
12 changes: 3 additions & 9 deletions backend/src/routes/violation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@ router.post("/add", async (req: Request, res: Response) => {
return;
}

console.log("THIS IS THE DRIVER FROM VIOLATION");
console.log(driverFound);

const violations = await pool.query(
await pool.query(
`INSERT INTO violations (
driver_id,
violation_type,
Expand All @@ -43,7 +41,6 @@ router.post("/add", async (req: Request, res: Response) => {
[driver_id, violation_type, violation_date, description]
);

console.log(violations.rows[0]);

res.status(200).json({
title: "Violation Added!",
Expand Down Expand Up @@ -88,9 +85,6 @@ router.patch("/update", async (req: Request, res: Response) => {
return;
}

const updateViolation = result.rows[0];
console.log("Violations updated successfully:", updateViolation);

res.status(200).json({
title: "Violation Updated!",
message: `Violation has been updated successfully.`,
Expand All @@ -99,7 +93,6 @@ router.patch("/update", async (req: Request, res: Response) => {

router.delete("/delete", async (req: Request, res: Response) => {
try {
console.log("Fetching. . .");

const { violationId } = req.body;

Expand All @@ -124,7 +117,8 @@ router.delete("/delete", async (req: Request, res: Response) => {
message: "Violation Deleted Successfully.",
});
} catch (error) {
console.log(error);
const errorMessage = (error as Error).message;
res.status(500).json({ title: "Unknown Error", message: errorMessage });
}
});

Expand Down
3 changes: 1 addition & 2 deletions backend/src/routes/violators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ router.get("/get", async (_req: Request, res: Response) => {
}

res.status(200).json(violators);
} catch (error) {
console.log(error);
} catch {
res.sendStatus(500);
}
});
Expand Down
1 change: 0 additions & 1 deletion frontend/src/hooks/car-hooks/useCheckLicenseNumber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ const useCheckLicenseNumber = () => {

try {
// Make sure license_number is URL-safe
console.log(license_number);
const response = await fetchWithAuth(
navigate,
refresh,
Expand Down
2 changes: 0 additions & 2 deletions frontend/src/hooks/car-hooks/useDeleteCar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export const useDeleteCar = () => {
const deleteCar = async (carId: string) => {
setAppLoading!(true)
try {
console.log("Sending delete request for car ID:", carId); // Log driverId

const response = await fetchWithAuth(
navigate,
Expand All @@ -34,7 +33,6 @@ export const useDeleteCar = () => {
const notificationAPI = await response.json()
toast.success(notificationAPI.message)

console.log("Car deleted successfully");
return ;
} catch (err: unknown) {
console.error("Network error:", err);
Expand Down
2 changes: 0 additions & 2 deletions frontend/src/hooks/driver-hooks/useAddDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export const useAddDriver = () => {
setLoading(true);

try {
console.log(`FORM DATA: ${JSON.stringify(formData)}`);
const response = await fetchWithAuth(
navigate,
refresh,
Expand All @@ -27,7 +26,6 @@ export const useAddDriver = () => {
if (!response.ok) {
const error: BackendMessage = await response.json();
setError(error);
console.log("What are you doing?!");
}
} catch (error) {
console.error("Unexpected error:", error);
Expand Down
1 change: 0 additions & 1 deletion frontend/src/hooks/driver-hooks/useDeleteDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export const useDeleteDriver = () => {
const deleteDriver = async (driverId: string) => {
setAppLoading!(true)
try {
console.log("Sending delete request for driver ID:", driverId); // Log driverId

const response = await fetchWithAuth(
navigate,
Expand Down
3 changes: 1 addition & 2 deletions frontend/src/hooks/driver-hooks/useGetDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,14 @@

const fetchedDriver = await response.json();
setDriver(fetchedDriver);
} catch (error) {
console.log(error);
} catch {
return {};
} finally {
setLoading(false);
}
};
fetchDriver(id);
}, [auth]);

Check warning on line 47 in frontend/src/hooks/driver-hooks/useGetDriver.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

React Hook useEffect has missing dependencies: 'id', 'navigate', and 'refresh'. Either include them or remove the dependency array

Check warning on line 47 in frontend/src/hooks/driver-hooks/useGetDriver.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

React Hook useEffect has missing dependencies: 'id', 'navigate', and 'refresh'. Either include them or remove the dependency array

Check warning on line 47 in frontend/src/hooks/driver-hooks/useGetDriver.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

React Hook useEffect has missing dependencies: 'id', 'navigate', and 'refresh'. Either include them or remove the dependency array

return { driver, loading };
};
Expand Down
Loading
Loading