diff --git a/.prettierrc b/.prettierrc index e69de29b..3f269835 100644 --- a/.prettierrc +++ b/.prettierrc @@ -0,0 +1,6 @@ +{ + "semi": true, + "singleQuote": false, + "trailingComma": "all", + "printWidth": 80 +} \ No newline at end of file diff --git a/backend/src/__tests__/cars.test.ts b/backend/src/__tests__/cars.test.ts index 1553f8dd..7ed6ba35 100644 --- a/backend/src/__tests__/cars.test.ts +++ b/backend/src/__tests__/cars.test.ts @@ -22,9 +22,7 @@ describe("Cars API", () => { describe("POST /check-license", () => { it("should return 401 if license number is not found", async () => { - ( - pool.query as Mock - ).mockResolvedValue({ + (pool.query as Mock).mockResolvedValue({ rows: [], }); @@ -39,14 +37,12 @@ describe("Cars API", () => { }); expect(pool.query).toHaveBeenCalledWith( "SELECT id FROM drivers WHERE license_number = $1", - ["12345678"] + ["12345678"], ); }); it("should return 200 if license number is found", async () => { - ( - pool.query as Mock - ).mockResolvedValue({ + (pool.query as Mock).mockResolvedValue({ rows: [{ id: 1 }], }); @@ -61,9 +57,7 @@ describe("Cars API", () => { describe("POST /add", () => { it("should return 404 if driver is not found", async () => { - ( - pool.query as Mock - ).mockResolvedValueOnce({ rows: [] }); + (pool.query as Mock).mockResolvedValueOnce({ rows: [] }); const response = await request(app).post("/add").send({ car_model: "Tesla", @@ -82,9 +76,7 @@ describe("Cars API", () => { }); it("should add a car and return 200", async () => { - ( - pool.query as Mock - ) + (pool.query as Mock) .mockResolvedValueOnce({ rows: [{ id: 1 }] }) // Mock driver query .mockResolvedValueOnce({ rows: [{ id: 1 }] }); // Mock car insert @@ -115,9 +107,7 @@ describe("Cars API", () => { }); it("should return 404 if no cars are found", async () => { - ( - pool.query as Mock - ).mockResolvedValue({ rows: [] }); + (pool.query as Mock).mockResolvedValue({ rows: [] }); const response = await request(app).get("/get?driverId=1"); @@ -129,9 +119,7 @@ describe("Cars API", () => { }); it("should return cars for a valid driverId", async () => { - ( - pool.query as Mock - ).mockResolvedValue({ + (pool.query as Mock).mockResolvedValue({ rows: [ { car_model: "Tesla", @@ -172,9 +160,7 @@ describe("Cars API", () => { }); it("should update a car and return 200", async () => { - ( - pool.query as Mock - ).mockResolvedValue({ + (pool.query as Mock).mockResolvedValue({ rowCount: 1, rows: [{ id: 1, car_model: "Tesla", license_plate: "ABC123" }], }); @@ -195,9 +181,7 @@ describe("Cars API", () => { describe("DELETE /delete", () => { it("should delete a car and return 200", async () => { - ( - pool.query as Mock - ).mockResolvedValue({ + (pool.query as Mock).mockResolvedValue({ rowCount: 1, }); diff --git a/backend/src/__tests__/driver.test.ts b/backend/src/__tests__/driver.test.ts index f054e8b5..c64b51d5 100644 --- a/backend/src/__tests__/driver.test.ts +++ b/backend/src/__tests__/driver.test.ts @@ -139,7 +139,7 @@ describe("Drivers API", () => { expect(response.status).toBe(200); expect(response.body.message).toBe( - "Successfully updated Driver: John Doe." + "Successfully updated Driver: John Doe.", ); }); diff --git a/backend/src/__tests__/profile.test.ts b/backend/src/__tests__/profile.test.ts index 4dd438d8..cd67b801 100644 --- a/backend/src/__tests__/profile.test.ts +++ b/backend/src/__tests__/profile.test.ts @@ -69,11 +69,9 @@ describe("GET /profile/get/:id", () => { expect(response.body.violations.length).toBe(2); expect(response.body.cars.length).toBe(2); expect(response.body.violations[0].description).toBe( - mockViolations[0].description - ); - expect(response.body.cars[0].car_model).toBe( - mockCars[0].car_model + mockViolations[0].description, ); + expect(response.body.cars[0].car_model).toBe(mockCars[0].car_model); }); it("should return 404 if driver is not found", async () => { diff --git a/backend/src/__tests__/registration.test.ts b/backend/src/__tests__/registration.test.ts index cb88266b..64f08093 100644 --- a/backend/src/__tests__/registration.test.ts +++ b/backend/src/__tests__/registration.test.ts @@ -50,15 +50,15 @@ describe("Registration API", () => { describe("GET /get", () => { it("should fetch all registrations successfully", async () => { const mockRegistrations: Registration[] = [ - { - user_id: 1, - license_number: "123", - school_email: "test@example.com" + { + user_id: 1, + license_number: "123", + school_email: "test@example.com", }, - { - user_id: 2, - license_number: "456", - school_email: "test2@example.com" + { + user_id: 2, + license_number: "456", + school_email: "test2@example.com", }, ]; @@ -71,7 +71,7 @@ describe("Registration API", () => { expect(response.body).toEqual(mockRegistrations); expect(pool.query).toHaveBeenCalledOnce(); expect(pool.query).toHaveBeenCalledWith( - `SELECT user_id, license_number, school_email, first_name, last_name, middle_name, date_of_birth, driver_type, sex FROM registrations` + `SELECT user_id, license_number, school_email, first_name, last_name, middle_name, date_of_birth, driver_type, sex FROM registrations`, ); }); @@ -133,8 +133,15 @@ describe("Registration API", () => { expect(pool.query).toHaveBeenCalledWith( expect.stringContaining("INSERT INTO registrations"), expect.arrayContaining([ - "12345678", "test@example.com", "John", "Doe", "A", "1990-01-01", "Student", "M", - ]) + "12345678", + "test@example.com", + "John", + "Doe", + "A", + "1990-01-01", + "Student", + "M", + ]), ); }); @@ -177,9 +184,11 @@ describe("Registration API", () => { it("should return 404 if registration not found", async () => { const license_number = "12345678"; - (pool.query as Mock).mockResolvedValueOnce({ rows: [] }); // No matching registration + (pool.query as Mock).mockResolvedValueOnce({ rows: [] }); // No matching registration - const response = await request(app).post("/approve").send({ license_number }); + const response = await request(app) + .post("/approve") + .send({ license_number }); expect(response.status).toBe(404); expect(response.body).toEqual({ @@ -190,17 +199,20 @@ describe("Registration API", () => { it("should approve the registration and update driver details", async () => { const license_number = "12345678"; - const mockRegistration: Registration = { school_email: "test@example.com", user_id: 1 }; + const mockRegistration: Registration = { + school_email: "test@example.com", + user_id: 1, + }; const mockDriver = { email: "", id: 1 }; // Mocking registration and driver fetch queries (pool.query as Mock) - .mockResolvedValueOnce({ rows: [mockRegistration] }) // Mock registration fetch - .mockResolvedValueOnce({ rows: [mockDriver] }); // Mock driver fetch + .mockResolvedValueOnce({ rows: [mockRegistration] }) // Mock registration fetch + .mockResolvedValueOnce({ rows: [mockDriver] }); // Mock driver fetch // Mock pool.connect to return a mock client const mockClient: MockClient = { - query: vi.fn().mockResolvedValueOnce({}), // Mocking successful query + query: vi.fn().mockResolvedValueOnce({}), // Mocking successful query release: vi.fn(), begin: vi.fn().mockResolvedValueOnce({}), commit: vi.fn().mockResolvedValueOnce({}), @@ -208,7 +220,9 @@ describe("Registration API", () => { }; (pool.connect as Mock).mockResolvedValue(mockClient); - const response = await request(app).post("/approve").send({ license_number }); + const response = await request(app) + .post("/approve") + .send({ license_number }); expect(response.status).toBe(200); expect(response.body).toEqual({ @@ -216,10 +230,10 @@ describe("Registration API", () => { message: "Driver's email and user_id have been updated successfully.", }); - expect(pool.query).toHaveBeenCalledTimes(3); // Expect 3 queries: registration, driver, deletion + expect(pool.query).toHaveBeenCalledTimes(3); // Expect 3 queries: registration, driver, deletion expect(pool.connect).toHaveBeenCalledOnce(); - expect(mockClient.begin).toHaveBeenCalledOnce(); // Ensure transaction start - expect(mockClient.commit).toHaveBeenCalledOnce(); // Ensure transaction commit + expect(mockClient.begin).toHaveBeenCalledOnce(); // Ensure transaction start + expect(mockClient.commit).toHaveBeenCalledOnce(); // Ensure transaction commit }); }); }); diff --git a/backend/src/__tests__/violation.test.ts b/backend/src/__tests__/violation.test.ts index 61635a57..19ee8bac 100644 --- a/backend/src/__tests__/violation.test.ts +++ b/backend/src/__tests__/violation.test.ts @@ -16,94 +16,93 @@ vi.mock("..", () => ({ })); describe("Violation API", () => { - describe("POST /add", () => { - it("should add a violation when the driver exists", async () => { - const violationData: Violation = { - id: "1", // Add id - driver_id: "1", // driver_id as string - violation_type: "Speeding", - violation_date: "2024-12-19", - description: "Exceeding the speed limit", - paid_status: false, // Add paid_status - }; - - // Mock driver found in the database - (pool.query as Mock).mockResolvedValueOnce({ - - rows: [ - { id: 1, - first_name: "John", - last_name: "Doe" - } - ], - }); - - // Mock insertion of the violation - (pool.query as Mock).mockResolvedValueOnce({ - rows: [ - { - driver_id: 1, - violation_type: "Speeding" - } - ], - }); - - const response = await request(app).post("/violations/add").send(violationData); - - expect(response.status).toBe(200); - expect(response.body).toEqual({ - title: "Violation Added!", - message: "Violation has been added for John Doe, Speeding.", - }); - }); - - it("should return 404 when the driver does not exist", async () => { - const violationData: Violation = { - id: "1", // Add id - driver_id: "999", // Non-existent driver (as a string) - violation_type: "Speeding", - violation_date: "2024-12-19", - description: "Exceeding the speed limit", - paid_status: false, // Add paid_status - }; - - // Mock driver not found in the database - (pool.query as Mock).mockResolvedValueOnce({ - rows: [], - }); - - const response = await request(app).post("/violations/add").send(violationData); - - expect(response.status).toBe(404); - expect(response.body).toEqual({ - title: "No Driver Found", - message: "Driver is not found.", - }); - }); - - it("should return 500 if an error occurs", async () => { - const violationData: Violation = { - id: "1", // Add id - driver_id: "1", // driver_id as string + describe("POST /add", () => { + it("should add a violation when the driver exists", async () => { + const violationData: Violation = { + id: "1", // Add id + driver_id: "1", // driver_id as string + violation_type: "Speeding", + violation_date: "2024-12-19", + description: "Exceeding the speed limit", + paid_status: false, // Add paid_status + }; + + // Mock driver found in the database + (pool.query as Mock).mockResolvedValueOnce({ + rows: [{ id: 1, first_name: "John", last_name: "Doe" }], + }); + + // Mock insertion of the violation + (pool.query as Mock).mockResolvedValueOnce({ + rows: [ + { + driver_id: 1, violation_type: "Speeding", - violation_date: "2024-12-19", - description: "Exceeding the speed limit", - paid_status: false, // Add paid_status - }; - - // Mock error during query - (pool.query as Mock).mockRejectedValueOnce(new Error("Database error")); - - const response = await request(app).post("/violations/add").send(violationData); - - expect(response.status).toBe(500); - expect(response.body).toEqual({ - title: "Error", - message: "Database error", - }); - }); + }, + ], }); - + + const response = await request(app) + .post("/violations/add") + .send(violationData); + + expect(response.status).toBe(200); + expect(response.body).toEqual({ + title: "Violation Added!", + message: "Violation has been added for John Doe, Speeding.", + }); + }); + + it("should return 404 when the driver does not exist", async () => { + const violationData: Violation = { + id: "1", // Add id + driver_id: "999", // Non-existent driver (as a string) + violation_type: "Speeding", + violation_date: "2024-12-19", + description: "Exceeding the speed limit", + paid_status: false, // Add paid_status + }; + + // Mock driver not found in the database + (pool.query as Mock).mockResolvedValueOnce({ + rows: [], + }); + + const response = await request(app) + .post("/violations/add") + .send(violationData); + + expect(response.status).toBe(404); + expect(response.body).toEqual({ + title: "No Driver Found", + message: "Driver is not found.", + }); + }); + + it("should return 500 if an error occurs", async () => { + const violationData: Violation = { + id: "1", // Add id + driver_id: "1", // driver_id as string + violation_type: "Speeding", + violation_date: "2024-12-19", + description: "Exceeding the speed limit", + paid_status: false, // Add paid_status + }; + + // Mock error during query + (pool.query as Mock).mockRejectedValueOnce(new Error("Database error")); + + const response = await request(app) + .post("/violations/add") + .send(violationData); + + expect(response.status).toBe(500); + expect(response.body).toEqual({ + title: "Error", + message: "Database error", + }); + }); + }); describe("PATCH /update", () => { it("should update a violation successfully", async () => { @@ -117,15 +116,17 @@ describe("Violation API", () => { (pool.query as Mock).mockResolvedValueOnce({ rowCount: 1, rows: [ - { - id: 1, - violation_type: "Speeding", - description: "Exceeded speed limit by 20 mph" - } + { + id: 1, + violation_type: "Speeding", + description: "Exceeded speed limit by 20 mph", + }, ], }); - const response = await request(app).patch("/violations/update").send(violationData); + const response = await request(app) + .patch("/violations/update") + .send(violationData); expect(response.status).toBe(200); expect(response.body).toEqual({ @@ -147,7 +148,9 @@ describe("Violation API", () => { rows: [], }); - const response = await request(app).patch("/violations/update").send(violationData); + const response = await request(app) + .patch("/violations/update") + .send(violationData); expect(response.status).toBe(404); expect(response.body).toEqual({ @@ -167,7 +170,9 @@ describe("Violation API", () => { rows: [{ id: 1 }], }); - const response = await request(app).delete("/violations/delete").send(violationData); + const response = await request(app) + .delete("/violations/delete") + .send(violationData); expect(response.status).toBe(200); expect(response.body).toEqual({ @@ -185,7 +190,9 @@ describe("Violation API", () => { rows: [], }); - const response = await request(app).delete("/violations/delete").send(violationData); + const response = await request(app) + .delete("/violations/delete") + .send(violationData); expect(response.status).toBe(404); expect(response.body).toEqual({ diff --git a/backend/src/index.ts b/backend/src/index.ts index f1dcbf64..92e94438 100644 --- a/backend/src/index.ts +++ b/backend/src/index.ts @@ -36,7 +36,7 @@ server.use( } }, optionsSuccessStatus: 200, - }) + }), ); // For Cookies @@ -64,6 +64,6 @@ const PORT = Number(process.env.PORT) || 3000; server.listen(PORT, "0.0.0.0", () => { console.log( - `The Server for CodeGreen has Started at http://localhost:${PORT}` + `The Server for CodeGreen has Started at http://localhost:${PORT}`, ); }); diff --git a/backend/src/middlewares/credentials.ts b/backend/src/middlewares/credentials.ts index e2e9316a..f134027d 100644 --- a/backend/src/middlewares/credentials.ts +++ b/backend/src/middlewares/credentials.ts @@ -4,7 +4,7 @@ import allowedOrigins from "../config/allowedOrigins"; export const credentials = ( req: Request, res: Response, - next: NextFunction + next: NextFunction, ) => { const origin = req.headers.origin; if (allowedOrigins.includes(origin!)) { diff --git a/backend/src/middlewares/validateAuth.ts b/backend/src/middlewares/validateAuth.ts index 12ff125a..7076c84b 100644 --- a/backend/src/middlewares/validateAuth.ts +++ b/backend/src/middlewares/validateAuth.ts @@ -15,7 +15,7 @@ const validateAuth = (req: Request, res: Response, next: NextFunction) => { if ( ![first_name, last_name, email, password, confirm_password].every( - Boolean + Boolean, ) ) { res.status(401).json({ @@ -43,7 +43,7 @@ const validateAuth = (req: Request, res: Response, next: NextFunction) => { } } break; - + case "/login": { const { email, password } = req.body; if (![email, password].every(Boolean)) { diff --git a/backend/src/middlewares/validateDriver.ts b/backend/src/middlewares/validateDriver.ts index f5e3815b..429726aa 100644 --- a/backend/src/middlewares/validateDriver.ts +++ b/backend/src/middlewares/validateDriver.ts @@ -3,11 +3,11 @@ import { NextFunction, Request, Response } from "express"; const validateDriver = ( req: Request, res: Response, - next: NextFunction + next: NextFunction, ): void => { const validateEmail = (email: string) => { return email.match( - "[-a-zA-Z0-9~!$%^&*_=+}{'?]+(.[-a-zA-Z0-9~!$%^&*_=+}{'?]+)*@[a-zA-Z0-9_][-a-zA-Z0-9_]*(.[-a-zA-Z0-9_]+)*.[cC][oO][mM](:[0-9]{1,5})?" + "[-a-zA-Z0-9~!$%^&*_=+}{'?]+(.[-a-zA-Z0-9~!$%^&*_=+}{'?]+)*@[a-zA-Z0-9_][-a-zA-Z0-9_]*(.[-a-zA-Z0-9_]+)*.[cC][oO][mM](:[0-9]{1,5})?", ); }; @@ -65,4 +65,3 @@ const validateDriver = ( }; export default validateDriver; - \ No newline at end of file diff --git a/backend/src/middlewares/verifyToken.ts b/backend/src/middlewares/verifyToken.ts index 8478a757..a6a562b4 100644 --- a/backend/src/middlewares/verifyToken.ts +++ b/backend/src/middlewares/verifyToken.ts @@ -16,13 +16,11 @@ const verifyToken = async (req: Request, res: Response, next: NextFunction) => { try { const payload = jwt.verify( token, - process.env.ACCESS_TOKEN_SECRET! + process.env.ACCESS_TOKEN_SECRET!, ) as JwtPayload; req.user = payload.userId; } catch (error) { - res - .status(403) - .json({ title: "Token Invalid", message: error }); + res.status(403).json({ title: "Token Invalid", message: error }); return; } next(); diff --git a/backend/src/routes/auth.ts b/backend/src/routes/auth.ts index 7090af39..1af438e3 100644 --- a/backend/src/routes/auth.ts +++ b/backend/src/routes/auth.ts @@ -15,7 +15,7 @@ router.post("/signup", validateAuth, async (req: Request, res: Response) => { const existingUser = await pool.query( "SELECT * FROM users WHERE email = $1", - [email] + [email], ); if (existingUser.rowCount !== 0) { @@ -38,7 +38,7 @@ router.post("/signup", validateAuth, async (req: Request, res: Response) => { const hashedPassword = await bcrypt.hash(password!, salt); await pool.query( "INSERT INTO users (first_name, last_name, email, password, salt) VALUES ($1, $2, $3, $4, $5)", - [first_name, last_name, email, hashedPassword, salt] + [first_name, last_name, email, hashedPassword, salt], ); res.status(200).json({ title: "Account Created Successfully", @@ -55,7 +55,7 @@ router.post("/login", validateAuth, async (req: Request, res: Response) => { const { rows: users } = await pool.query( "SELECT * FROM users WHERE email = $1", - [email] + [email], ); const user = (await users[0]) as User; @@ -78,7 +78,6 @@ router.post("/login", validateAuth, async (req: Request, res: Response) => { }); return; } - const refreshToken = generateRefreshToken(user.id!); const accessToken = generateAccessToken(user.id!); @@ -116,7 +115,6 @@ router.get("/refresh", async (req: Request, res: Response) => { ]) ).rows[0]; - if (!foundUser) { res.status(403).json({ title: "No Access Rights", @@ -129,7 +127,7 @@ router.get("/refresh", async (req: Request, res: Response) => { try { const payload = jwt.verify( refreshToken, - process.env.REFRESH_TOKEN_SECRET! + process.env.REFRESH_TOKEN_SECRET!, ) as JwtPayload; const accessToken = generateAccessToken(payload.userId); @@ -165,7 +163,7 @@ router.get("/logout", async (req: Request, res: Response) => { const { rows: users } = await pool.query( "SELECT * FROM users WHERE refresh_token = $1", - [refreshToken] + [refreshToken], ); const foundUser = users[0]; diff --git a/backend/src/routes/cars.ts b/backend/src/routes/cars.ts index 82fe6a23..ad66d08f 100644 --- a/backend/src/routes/cars.ts +++ b/backend/src/routes/cars.ts @@ -10,7 +10,7 @@ router.post("/check-license", async (req: Request, res: Response) => { const { rows: drivers } = await pool.query( `SELECT * FROM drivers WHERE license_number = $1`, - [license_number] + [license_number], ); const driverFound = drivers[0]; @@ -41,12 +41,11 @@ router.post("/add", async (req: Request, res: Response) => { license_number, }: Cars = req.body; - const { rows: drivers } = await pool.query( `SELECT id FROM drivers WHERE id = $1`, - [driver_id] + [driver_id], ); const driverFound = await drivers[0]; @@ -68,7 +67,7 @@ router.post("/add", async (req: Request, res: Response) => { license_number) VALUES($1, $2, $3, $4, $5, $6)`, - [driver_id, car_model, license_plate, brand, color, license_number] + [driver_id, car_model, license_plate, brand, color, license_number], ); res.status(200).json({ title: "Car Added!", @@ -84,7 +83,6 @@ router.get("/get", async (req: Request, res: Response) => { try { const { driverId } = req.query; - if (!driverId) { res.status(400).json({ title: "Driver ID is required", @@ -99,7 +97,7 @@ router.get("/get", async (req: Request, res: Response) => { `SELECT car_model, license_plate, brand, color, license_number FROM cars WHERE driver_id = $1`, - [driverIdStr] + [driverIdStr], ); if (cars.length === 0) { @@ -165,14 +163,13 @@ router.patch("/update", async (req: Request, res: Response) => { router.delete("/delete", async (req: Request, res: Response) => { try { - await pool.query( `DELETE FROM cars WHERE id = $1 RETURNING *`, - [req.body.id] + [req.body.id], ); res.status(200).json({ message: "Car Added Successfully" }); diff --git a/backend/src/routes/driver.ts b/backend/src/routes/driver.ts index 21a16298..9b6ad033 100644 --- a/backend/src/routes/driver.ts +++ b/backend/src/routes/driver.ts @@ -41,7 +41,7 @@ router.post("/add", validateDriver, async (req: Request, res: Response) => { driver_type, license_number, license_expiration_date, - ] + ], ); res.status(200).json({ @@ -58,10 +58,9 @@ router.post("/add", validateDriver, async (req: Request, res: Response) => { router.get("/get", async (req: Request, res: Response) => { try { - const { rows: drivers } = await pool.query( `SELECT * - FROM drivers` + FROM drivers`, ); // Send the drivers list as a response @@ -79,7 +78,7 @@ router.get("/get/:driverId", async (req: Request, res: Response) => { const { rows: users } = await pool.query( "SELECT * FROM users WHERE id = $1", - [req.user] + [req.user], ); const foundUser = users[0]; @@ -94,7 +93,7 @@ router.get("/get/:driverId", async (req: Request, res: Response) => { const { rows: drivers } = await pool.query( "SELECT * FROM drivers WHERE id = $1", - [driverId] + [driverId], ); const foundDriver = await drivers[0]; @@ -106,12 +105,12 @@ router.get("/get/:driverId", async (req: Request, res: Response) => { const { rows: violations } = await pool.query( "SELECT * FROM violations WHERE driver_id = $1", - [foundDriver.id] + [foundDriver.id], ); const { rows: cars } = await pool.query( "SELECT * FROM cars WHERE driver_id = $1", - [foundDriver.id] + [foundDriver.id], ); res.status(200).json({ ...foundDriver, violations, cars }); @@ -176,7 +175,7 @@ router.patch("/update", async (req: Request, res: Response) => { driver_type, license_expiration_date, id, - ] + ], ); res.status(200).json({ @@ -207,7 +206,7 @@ router.delete("/delete", async (req: Request, res: Response) => { const resultDriver = await pool.query( `DELETE FROM drivers WHERE id = $1 RETURNING *`, - [id] + [id], ); if (resultDriver.rowCount === 0) { diff --git a/backend/src/routes/notification.ts b/backend/src/routes/notification.ts index 0a70454d..6533f36a 100644 --- a/backend/src/routes/notification.ts +++ b/backend/src/routes/notification.ts @@ -9,7 +9,7 @@ router.get("/get-by-user", async (req: Req, res: Response) => { const { rows: drivers } = await pool.query( "SELECT * FROM drivers WHERE user_id = $1", - [id] + [id], ); const foundDriver = await drivers[0]; @@ -17,7 +17,7 @@ router.get("/get-by-user", async (req: Req, res: Response) => { try { const { rows: notifications } = await pool.query( "SELECT * FROM notifications WHERE driver_id = $1", - [foundDriver.id] + [foundDriver.id], ); if (notifications.length === 0) { @@ -40,7 +40,7 @@ router.post("/add", async (req: Req, res: Response) => { const { rows: drivers } = await pool.query( "SELECT * FROM drivers WHERE id = $1", - [driver_id] + [driver_id], ); if (drivers.length === 0) { @@ -55,7 +55,7 @@ router.post("/add", async (req: Req, res: Response) => { const { rows: notifications } = await pool.query( "INSERT INTO notifications (driver_id, title, message) VALUES ($1, $2, $3) RETURNING *", - [driver.id, title, message] + [driver.id, title, message], ); if (notifications.length === 0) { @@ -84,7 +84,7 @@ router.delete("/delete", async (req: Req, res: Response) => { try { const { rows: notifications } = await pool.query( "DELETE FROM notifications WHERE id = $1 RETURNING *", - [id] + [id], ); if (notifications.length === 0) { res.status(404).json({ error: "Notification not found." }); diff --git a/backend/src/routes/profile.ts b/backend/src/routes/profile.ts index 7a3651b9..285da3e6 100644 --- a/backend/src/routes/profile.ts +++ b/backend/src/routes/profile.ts @@ -9,7 +9,7 @@ router.get("/get/:id", async (req: Request, res: Response) => { const { rows: drivers } = await pool.query( "SELECT * FROM drivers WHERE user_id = $1", - [id] + [id], ); const foundDriver = await drivers[0]; @@ -21,12 +21,12 @@ router.get("/get/:id", async (req: Request, res: Response) => { const { rows: violations } = await pool.query( "SELECT * FROM violations WHERE driver_id = $1", - [foundDriver.id] + [foundDriver.id], ); const { rows: cars } = await pool.query( "SELECT * FROM cars WHERE driver_id = $1", - [foundDriver.id] + [foundDriver.id], ); res.status(200).json({ ...foundDriver, violations, cars }); @@ -35,5 +35,4 @@ router.get("/get/:id", async (req: Request, res: Response) => { } }); - export default router; diff --git a/backend/src/routes/registration.ts b/backend/src/routes/registration.ts index cd31dad2..c770bd91 100644 --- a/backend/src/routes/registration.ts +++ b/backend/src/routes/registration.ts @@ -8,7 +8,7 @@ const router = express.Router(); const fetchRegistrationByLicense = async (license_number: string) => { const { rows } = await pool.query( `SELECT school_email, user_id FROM registrations WHERE license_number = $1`, - [license_number] + [license_number], ); return rows[0]; }; @@ -17,7 +17,7 @@ const fetchRegistrationByLicense = async (license_number: string) => { router.get("/get", async (_req: Request, res: Response) => { try { 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" + "SELECT user_id, license_number, school_email, first_name, last_name, middle_name, date_of_birth, driver_type, sex FROM registrations", ); res.json(registrations); // Send the registration list as a response @@ -77,7 +77,7 @@ router.post("/add", async (req: Request, res: Response) => { date_of_birth, driver_type, sex, - ] + ], ); res.status(201).json({ @@ -105,7 +105,7 @@ router.delete("/delete", async (req: Request, res: Response): Promise => { // Attempt to delete the registration await pool.query( `DELETE FROM registrations WHERE license_number = $1 RETURNING *`, - [license_number] + [license_number], ); // If deletion was successful, return a success response @@ -154,7 +154,7 @@ router.post("/approve", async (req: Request, res: Response) => { const { rows: existingDrivers } = await client.query( `SELECT id, email FROM drivers WHERE license_number = $1`, - [license_number] + [license_number], ); if (existingDrivers.length > 0) { @@ -164,12 +164,12 @@ router.post("/approve", async (req: Request, res: Response) => { if (!existingDriver.email) { await client.query( `UPDATE drivers SET email = $1, user_id = $2 WHERE license_number = $3`, - [school_email, user_id, license_number] + [school_email, user_id, license_number], ); await client.query( `DELETE FROM registrations WHERE license_number = $1`, - [license_number] + [license_number], ); res.status(200).json({ @@ -183,12 +183,12 @@ router.post("/approve", async (req: Request, res: Response) => { if (existingDriver.email) { await client.query( `UPDATE drivers SET user_id = $1 WHERE license_number = $2`, - [user_id, license_number] + [user_id, license_number], ); await client.query( `DELETE FROM registrations WHERE license_number = $1`, - [license_number] + [license_number], ); res.status(200).json({ diff --git a/backend/src/routes/user.ts b/backend/src/routes/user.ts index 957818dc..192d4ea4 100644 --- a/backend/src/routes/user.ts +++ b/backend/src/routes/user.ts @@ -11,17 +11,17 @@ router.get("/get", async (req: Request, res: Response) => { const { rows: users } = await pool.query( "SELECT id, first_name, last_name FROM users WHERE id = $1", - [userId] + [userId], ); const { rows: registrations } = await pool.query( "SELECT * FROM registrations WHERE user_id = $1", - [userId] + [userId], ); const { rows: drivers } = await pool.query( "SELECT * FROM drivers WHERE user_id = $1", - [userId] + [userId], ); res.status(200).json({ @@ -30,7 +30,7 @@ router.get("/get", async (req: Request, res: Response) => { isDriver: drivers[0] ? true : false, }); // Send the user data as a response } catch (error) { - console.error(error) + console.error(error); const errorMessage = (error as Error).message; console.error("Error fetching the user:", errorMessage); res.status(500).json({ title: "Unknown Error", message: errorMessage }); @@ -52,7 +52,7 @@ router.patch("/change-password", async (req: Request, res: Response) => { const { rows: users } = await pool.query( "SELECT * FROM users WHERE id = $1", - [userId] + [userId], ); if (users.length === 0) { @@ -67,7 +67,7 @@ router.patch("/change-password", async (req: Request, res: Response) => { const matchPassword = await bcrypt.compare( currentPassword, - foundUser.password + foundUser.password, ); if (!matchPassword) { diff --git a/backend/src/routes/violation.ts b/backend/src/routes/violation.ts index 6fdee654..4bc33c6d 100644 --- a/backend/src/routes/violation.ts +++ b/backend/src/routes/violation.ts @@ -17,7 +17,7 @@ router.post("/add", async (req: Request, res: Response) => { `SELECT * FROM drivers WHERE id = $1`, - [driver_id] + [driver_id], ); const driverFound = await drivers[0]; @@ -29,7 +29,6 @@ router.post("/add", async (req: Request, res: Response) => { return; } - await pool.query( `INSERT INTO violations ( driver_id, @@ -38,10 +37,9 @@ router.post("/add", async (req: Request, res: Response) => { description ) VALUES($1, $2, $3, $4)`, - [driver_id, violation_type, violation_date, description] + [driver_id, violation_type, violation_date, description], ); - res.status(200).json({ title: "Violation Added!", message: `Violation has been added for ${driverFound.first_name} ${driverFound.last_name}, ${violation_type}.`, @@ -93,7 +91,6 @@ router.patch("/update", async (req: Request, res: Response) => { router.delete("/delete", async (req: Request, res: Response) => { try { - const { violationId } = req.body; const violations = await pool.query( @@ -102,7 +99,7 @@ router.delete("/delete", async (req: Request, res: Response) => { WHERE id = $1 RETURNING *`, - [violationId] + [violationId], ); if (violations.rowCount === 0) { diff --git a/backend/src/routes/violators.ts b/backend/src/routes/violators.ts index c998589c..cc2ef6af 100644 --- a/backend/src/routes/violators.ts +++ b/backend/src/routes/violators.ts @@ -11,17 +11,17 @@ router.get("/get", async (_req: Request, res: Response) => { const driversWithViolations = drivers.map(async (driver) => { const { rows: violations } = await pool.query( "SELECT * FROM violations WHERE driver_id = $1", - [driver.id] + [driver.id], ); return await { ...driver, violations: violations }; }); const unpromisedDriversWithViolations = await Promise.all( - driversWithViolations + driversWithViolations, ); const violators = unpromisedDriversWithViolations.filter( - (driver) => driver.violations[0] + (driver) => driver.violations[0], ); if (violators.length === 0) { diff --git a/eslint.config.js b/eslint.config.js index 0bbf074e..29d196c1 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -23,6 +23,7 @@ export default tseslint.config( "warn", { allowConstantExport: true }, ], + "no-console": 1, }, - } + }, ); diff --git a/frontend/src/hooks/car-hooks/useAddCar.ts b/frontend/src/hooks/car-hooks/useAddCar.ts index ea1553e4..a5724746 100644 --- a/frontend/src/hooks/car-hooks/useAddCar.ts +++ b/frontend/src/hooks/car-hooks/useAddCar.ts @@ -6,9 +6,8 @@ import { LoadingContextType } from "../../types/loading.types"; import useLoading from "../context-hooks/useLoading"; const useAddCar = () => { - const { auth, refresh, navigate} = useFetchWithAuthExports() - const { setAppLoading }: LoadingContextType = useLoading() - + const { auth, refresh, navigate } = useFetchWithAuthExports(); + const { setAppLoading }: LoadingContextType = useLoading(); const postCar = async (formData: Car) => { setAppLoading!(true); @@ -20,30 +19,27 @@ const useAddCar = () => { auth, "/car/add", "post", - formData + formData, ); - if (!response.ok) { const errorData = await response.json(); console.error("Error response from server:", errorData); // Log server response - toast.error(errorData.message) + toast.error(errorData.message); return; } - const notificationAPI = await response.json() + const notificationAPI = await response.json(); - toast.success(notificationAPI.message) + toast.success(notificationAPI.message); return; // Return true on success - } - - catch (err: unknown) { + } catch (err: unknown) { // Narrow down `err` to ensure it has a `message` property const errorMessage = err instanceof Error ? err.message : "Failed to connect to the server"; - toast.error(errorMessage) + toast.error(errorMessage); } finally { - setAppLoading!(false) + setAppLoading!(false); } }; diff --git a/frontend/src/hooks/car-hooks/useCars.ts b/frontend/src/hooks/car-hooks/useCars.ts index 0cfd8e9a..f7ce7f25 100644 --- a/frontend/src/hooks/car-hooks/useCars.ts +++ b/frontend/src/hooks/car-hooks/useCars.ts @@ -19,7 +19,7 @@ const useCars = (driverId: string) => { refresh, auth, `/car/get?driverId=${driverId}`, - "get" + "get", ); if (!response.ok) { diff --git a/frontend/src/hooks/car-hooks/useCheckLicenseNumber.ts b/frontend/src/hooks/car-hooks/useCheckLicenseNumber.ts index 233892c7..8b6acb52 100644 --- a/frontend/src/hooks/car-hooks/useCheckLicenseNumber.ts +++ b/frontend/src/hooks/car-hooks/useCheckLicenseNumber.ts @@ -10,7 +10,7 @@ const useCheckLicenseNumber = () => { const { auth, refresh, navigate } = useFetchWithAuthExports(); const checkLicenseNumber = async ( - license_number: string + license_number: string, ): Promise => { setLoading(true); @@ -24,7 +24,7 @@ const useCheckLicenseNumber = () => { "post", { license_number, - } + }, ); if (!response.ok) { diff --git a/frontend/src/hooks/car-hooks/useDeleteCar.ts b/frontend/src/hooks/car-hooks/useDeleteCar.ts index a82a7d77..29b3761a 100644 --- a/frontend/src/hooks/car-hooks/useDeleteCar.ts +++ b/frontend/src/hooks/car-hooks/useDeleteCar.ts @@ -4,50 +4,49 @@ import useLoading from "../context-hooks/useLoading"; import { LoadingContextType } from "../../types/loading.types"; import { toast } from "react-toastify"; -export const useDeleteCar = () => { - const { auth, refresh, navigate } = useFetchWithAuthExports(); - const { setAppLoading }: LoadingContextType = useLoading() - - const deleteCar = async (carId: string) => { - setAppLoading!(true) - try { - - const response = await fetchWithAuth( - navigate, - refresh, - auth, - "/car/delete", - "delete", - { id: carId } - ); - - if (!response.ok) { - const errorData = await response.json(); - console.error("Error response from server:", errorData); // Log server response - - toast.error(errorData.message) - - return ; - } - - const notificationAPI = await response.json() - toast.success(notificationAPI.message) - - return ; - } catch (err: unknown) { - console.error("Network error:", err); - - // Narrow down `err` to ensure it has a `message` property - const errorMessage = err instanceof Error ? err.message : "Failed to connect to the server"; - - toast.error(errorMessage) - - return ; - } finally { - setAppLoading!(false) - } - }; - - return { deleteCar }; - }; - \ No newline at end of file +export const useDeleteCar = () => { + const { auth, refresh, navigate } = useFetchWithAuthExports(); + const { setAppLoading }: LoadingContextType = useLoading(); + + const deleteCar = async (carId: string) => { + setAppLoading!(true); + try { + const response = await fetchWithAuth( + navigate, + refresh, + auth, + "/car/delete", + "delete", + { id: carId }, + ); + + if (!response.ok) { + const errorData = await response.json(); + console.error("Error response from server:", errorData); // Log server response + + toast.error(errorData.message); + + return; + } + + const notificationAPI = await response.json(); + toast.success(notificationAPI.message); + + return; + } catch (err: unknown) { + console.error("Network error:", err); + + // Narrow down `err` to ensure it has a `message` property + const errorMessage = + err instanceof Error ? err.message : "Failed to connect to the server"; + + toast.error(errorMessage); + + return; + } finally { + setAppLoading!(false); + } + }; + + return { deleteCar }; +}; diff --git a/frontend/src/hooks/car-hooks/useEditCars.ts b/frontend/src/hooks/car-hooks/useEditCars.ts index 0f06169e..72b203e5 100644 --- a/frontend/src/hooks/car-hooks/useEditCars.ts +++ b/frontend/src/hooks/car-hooks/useEditCars.ts @@ -6,8 +6,8 @@ import { LoadingContextType } from "../../types/loading.types"; import useLoading from "../context-hooks/useLoading"; const useEditCar = () => { - const { auth, refresh, navigate} = useFetchWithAuthExports() - const { setAppLoading }: LoadingContextType = useLoading() + const { auth, refresh, navigate } = useFetchWithAuthExports(); + const { setAppLoading }: LoadingContextType = useLoading(); const updateCar = async (formData: Car) => { setAppLoading!(true); @@ -19,27 +19,27 @@ const useEditCar = () => { auth, "/car/update", "patch", - formData + formData, ); if (!response.ok) { const errorData = await response.json(); console.error("Error response from server:", errorData); // Log server response - toast.error(errorData.message) + toast.error(errorData.message); return; } - const notificationAPI = await response.json() + const notificationAPI = await response.json(); - toast.success(notificationAPI.message) + toast.success(notificationAPI.message); return; // Return true on success - } catch (err: unknown) { + } catch (err: unknown) { // Narrow down `err` to ensure it has a `message` property const errorMessage = err instanceof Error ? err.message : "Failed to connect to the server"; - toast.error(errorMessage) + toast.error(errorMessage); } finally { - setAppLoading!(false) + setAppLoading!(false); } }; diff --git a/frontend/src/hooks/context-hooks/useAuth.ts b/frontend/src/hooks/context-hooks/useAuth.ts index 3287470e..dfc6b1af 100644 --- a/frontend/src/hooks/context-hooks/useAuth.ts +++ b/frontend/src/hooks/context-hooks/useAuth.ts @@ -1,8 +1,8 @@ -import { useContext } from 'react' -import AuthContext from '../../context/AuthContext'; +import { useContext } from "react"; +import AuthContext from "../../context/AuthContext"; const useAuth = () => { return useContext(AuthContext); -} +}; -export default useAuth \ No newline at end of file +export default useAuth; diff --git a/frontend/src/hooks/driver-hooks/useAddDriver.ts b/frontend/src/hooks/driver-hooks/useAddDriver.ts index af89a007..5bd516bb 100644 --- a/frontend/src/hooks/driver-hooks/useAddDriver.ts +++ b/frontend/src/hooks/driver-hooks/useAddDriver.ts @@ -20,7 +20,7 @@ export const useAddDriver = () => { auth, "/driver/add", "POST", - formData + formData, ); if (!response.ok) { diff --git a/frontend/src/hooks/driver-hooks/useDeleteDriver.ts b/frontend/src/hooks/driver-hooks/useDeleteDriver.ts index 86b5f04e..080bb7dc 100644 --- a/frontend/src/hooks/driver-hooks/useDeleteDriver.ts +++ b/frontend/src/hooks/driver-hooks/useDeleteDriver.ts @@ -6,40 +6,39 @@ import { toast } from "react-toastify"; export const useDeleteDriver = () => { const { auth, refresh, navigate } = useFetchWithAuthExports(); - const { setAppLoading }: LoadingContextType = useLoading() + const { setAppLoading }: LoadingContextType = useLoading(); const deleteDriver = async (driverId: string) => { - setAppLoading!(true) + setAppLoading!(true); try { - const response = await fetchWithAuth( navigate, refresh, auth, "/driver/delete", "delete", - { id: driverId } + { id: driverId }, ); if (!response.ok) { const errorData = await response.json(); console.error("Error response from server:", errorData); // Log server response - toast.error(errorData.message) + toast.error(errorData.message); return; } - const notificationAPI = await response.json() + const notificationAPI = await response.json(); - toast.success(notificationAPI.message) + toast.success(notificationAPI.message); return; } catch (err: unknown) { // Narrow down `err` to ensure it has a `message` property const errorMessage = err instanceof Error ? err.message : "Failed to connect to the server"; - toast.error(errorMessage) + toast.error(errorMessage); } finally { - setAppLoading!(false) + setAppLoading!(false); } }; diff --git a/frontend/src/hooks/driver-hooks/useDrivers.ts b/frontend/src/hooks/driver-hooks/useDrivers.ts index f47f69a0..9bf111dd 100644 --- a/frontend/src/hooks/driver-hooks/useDrivers.ts +++ b/frontend/src/hooks/driver-hooks/useDrivers.ts @@ -18,7 +18,7 @@ const useDrivers = () => { refresh, auth, "/driver/get", - "get" + "get", ); if (!response.ok) { diff --git a/frontend/src/hooks/driver-hooks/useEditDriver.ts b/frontend/src/hooks/driver-hooks/useEditDriver.ts index 847e5d75..aead0fa7 100644 --- a/frontend/src/hooks/driver-hooks/useEditDriver.ts +++ b/frontend/src/hooks/driver-hooks/useEditDriver.ts @@ -19,7 +19,7 @@ export const useEditDriver = () => { auth, "/driver/update", "PATCH", - updatedDriver + updatedDriver, ); if (!response.ok) { diff --git a/frontend/src/hooks/driver-hooks/useGetDriver.ts b/frontend/src/hooks/driver-hooks/useGetDriver.ts index 20f80138..58fdc0ce 100644 --- a/frontend/src/hooks/driver-hooks/useGetDriver.ts +++ b/frontend/src/hooks/driver-hooks/useGetDriver.ts @@ -19,7 +19,7 @@ const useGetDriver = (id: string) => { refresh, auth, auth?.isAdmin ? `/driver/get/${id}` : `/profile/get/${auth?.id}`, - "get" + "get", ); if (response.status === 401) { diff --git a/frontend/src/hooks/registration-hooks/useAddRegistration.ts b/frontend/src/hooks/registration-hooks/useAddRegistration.ts index 30cb6f94..f578127c 100644 --- a/frontend/src/hooks/registration-hooks/useAddRegistration.ts +++ b/frontend/src/hooks/registration-hooks/useAddRegistration.ts @@ -19,7 +19,7 @@ export const useAddRegistration = () => { auth, "/registration/add", "POST", - formData + formData, ); if (!response.ok) { diff --git a/frontend/src/hooks/registration-hooks/useApproveRegistration.ts b/frontend/src/hooks/registration-hooks/useApproveRegistration.ts index fa23c6b3..4d89e1d4 100644 --- a/frontend/src/hooks/registration-hooks/useApproveRegistration.ts +++ b/frontend/src/hooks/registration-hooks/useApproveRegistration.ts @@ -23,7 +23,7 @@ export const useApproveRegistration = () => { auth, "/registration/approve", "POST", - { license_number: licenseNumber } + { license_number: licenseNumber }, ); if (!response.ok) { @@ -37,7 +37,7 @@ export const useApproveRegistration = () => { } catch (error) { console.error("Error approving registration:", error); toast.error( - "Network error occurred. Could not connect to the server. Please try again." + "Network error occurred. Could not connect to the server. Please try again.", ); } finally { setAppLoading!(false); diff --git a/frontend/src/hooks/registration-hooks/useDeleteRegistration.ts b/frontend/src/hooks/registration-hooks/useDeleteRegistration.ts index a74823e0..501aa799 100644 --- a/frontend/src/hooks/registration-hooks/useDeleteRegistration.ts +++ b/frontend/src/hooks/registration-hooks/useDeleteRegistration.ts @@ -12,7 +12,6 @@ export const useDeleteRegistration = () => { setdeleteLoading(true); try { - // Send license_number in the request body as JSON const response = await fetchWithAuth( navigate, @@ -22,7 +21,7 @@ export const useDeleteRegistration = () => { "delete", { license_number: licenseNumber, - } + }, ); // Log the response status diff --git a/frontend/src/hooks/registration-hooks/useGetRegistration.ts b/frontend/src/hooks/registration-hooks/useGetRegistration.ts index 2641d4d9..4b763a14 100644 --- a/frontend/src/hooks/registration-hooks/useGetRegistration.ts +++ b/frontend/src/hooks/registration-hooks/useGetRegistration.ts @@ -21,7 +21,7 @@ const useGetRegistration = () => { refresh, auth, "/registration/get", - "get" + "get", ); if (!response.ok) { diff --git a/frontend/src/hooks/useAddRegistration.ts b/frontend/src/hooks/useAddRegistration.ts index 1787de64..f9b631fe 100644 --- a/frontend/src/hooks/useAddRegistration.ts +++ b/frontend/src/hooks/useAddRegistration.ts @@ -19,7 +19,7 @@ export const useAddRegistration = () => { auth, "/registration/add", "POST", - formData + formData, ); if (!response.ok) { diff --git a/frontend/src/hooks/useChangePassword.ts b/frontend/src/hooks/useChangePassword.ts index 021ad07b..19e6278b 100644 --- a/frontend/src/hooks/useChangePassword.ts +++ b/frontend/src/hooks/useChangePassword.ts @@ -20,7 +20,7 @@ const useChangePassword = () => { auth, "/user/change-password", "patch", - data + data, ); if (!response.ok) { diff --git a/frontend/src/hooks/useGetRegistration.ts b/frontend/src/hooks/useGetRegistration.ts index 2a2a3f0b..56da27a0 100644 --- a/frontend/src/hooks/useGetRegistration.ts +++ b/frontend/src/hooks/useGetRegistration.ts @@ -21,7 +21,7 @@ const useGetRegistration = () => { refresh, auth, "/registration/get", - "get" + "get", ); if (!response.ok) { diff --git a/frontend/src/hooks/useGetViolators.ts b/frontend/src/hooks/useGetViolators.ts index 596d4b07..4ba5d59a 100644 --- a/frontend/src/hooks/useGetViolators.ts +++ b/frontend/src/hooks/useGetViolators.ts @@ -19,7 +19,7 @@ const useGetViolators = () => { refresh, auth, "/violator/get", - "get" + "get", ); if (!response.ok) { diff --git a/frontend/src/hooks/useNotifications.ts b/frontend/src/hooks/useNotifications.ts index 1f748200..cb94f89f 100644 --- a/frontend/src/hooks/useNotifications.ts +++ b/frontend/src/hooks/useNotifications.ts @@ -18,7 +18,7 @@ const useNotifications = () => { refresh, auth, "/notification/get-by-user", - "get" + "get", ); if (response.status === 404) { diff --git a/frontend/src/hooks/useSendNotifications.ts b/frontend/src/hooks/useSendNotifications.ts index f11c6757..6792043e 100644 --- a/frontend/src/hooks/useSendNotifications.ts +++ b/frontend/src/hooks/useSendNotifications.ts @@ -19,7 +19,7 @@ const useSendNotification = () => { auth, "/notification/add", "post", - formData + formData, ); if (!response.ok) { diff --git a/frontend/src/hooks/useSignUp.ts b/frontend/src/hooks/useSignUp.ts index fd5b1ae6..a56996e2 100644 --- a/frontend/src/hooks/useSignUp.ts +++ b/frontend/src/hooks/useSignUp.ts @@ -20,7 +20,7 @@ const useSignUp = () => { const notification = await response.json(); toast.success(`${notification.message}!`); - return true + return true; } catch (error) { alert(error); return false; diff --git a/frontend/src/hooks/useUser.ts b/frontend/src/hooks/useUser.ts index 0138a18c..e7d33f1d 100644 --- a/frontend/src/hooks/useUser.ts +++ b/frontend/src/hooks/useUser.ts @@ -19,7 +19,7 @@ const useUser = () => { refresh, auth, "/user/get", - "get" + "get", ); if (!response.ok) { const error: BackendMessage = await response.json(); diff --git a/frontend/src/hooks/violation-hooks/useAddViolation.ts b/frontend/src/hooks/violation-hooks/useAddViolation.ts index eff5d412..75d58a3b 100644 --- a/frontend/src/hooks/violation-hooks/useAddViolation.ts +++ b/frontend/src/hooks/violation-hooks/useAddViolation.ts @@ -19,7 +19,7 @@ const useAddViolation = () => { auth, "/violation/add", "POST", - formData + formData, ); if (!response.ok) { diff --git a/frontend/src/hooks/violation-hooks/useDeleteViolation.ts b/frontend/src/hooks/violation-hooks/useDeleteViolation.ts index c85fb6c6..d1dd85ca 100644 --- a/frontend/src/hooks/violation-hooks/useDeleteViolation.ts +++ b/frontend/src/hooks/violation-hooks/useDeleteViolation.ts @@ -11,14 +11,13 @@ export const useDeleteViolation = () => { const deleteViolation = async (violationId: string) => { setAppLoading!(true); try { - const response = await fetchWithAuth( navigate, refresh, auth, "/violation/delete", "delete", - { violationId } + { violationId }, ); if (!response.ok) { @@ -38,8 +37,9 @@ export const useDeleteViolation = () => { console.error("Network error:", err); // Narrow down `err` to ensure it has a `message` property - const errorMessage = err instanceof Error ? err.message : "Failed to connect to the server"; - + const errorMessage = + err instanceof Error ? err.message : "Failed to connect to the server"; + toast.error(errorMessage); return; diff --git a/frontend/src/hooks/violation-hooks/useEditViolation.ts b/frontend/src/hooks/violation-hooks/useEditViolation.ts index 1a42e7e7..c7d8cbfb 100644 --- a/frontend/src/hooks/violation-hooks/useEditViolation.ts +++ b/frontend/src/hooks/violation-hooks/useEditViolation.ts @@ -19,7 +19,7 @@ export const useEditViolation = () => { auth, "/violation/update", "patch", - formData + formData, ); if (!response.ok) { diff --git a/package.json b/package.json index 034d8053..73f745ba 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,8 @@ "backend": "cd backend && npm run dev", "frontend": "cd frontend && npm run dev", "allinstall": "npm install && cd frontend && npm install && cd ../backend && npm install", - "allupdate": "npm update && cd frontend && npm update && cd ../backend && npm update" + "allupdate": "npm update && cd frontend && npm update && cd ../backend && npm update", + "prettier-format": "prettier --config .prettierrc frontend/src/**/*.ts --write && prettier --config .prettierrc backend/src/**/*.ts --write" }, "keywords": [], "author": "",