diff --git a/backend/src/app.js b/backend/src/app.js index 4f063cbb..236f0849 100644 --- a/backend/src/app.js +++ b/backend/src/app.js @@ -9,7 +9,6 @@ import v1Routes from "./routes/v1/index.js"; const app = express(); const frontendRoute = urls[1]; -const backendRoute = urls[0]; const authRoute = urls[2]; app.use(express.json()); diff --git a/backend/src/db/chargningStation.js b/backend/src/db/chargningStation.js index da8e64d7..50db9f93 100644 --- a/backend/src/db/chargningStation.js +++ b/backend/src/db/chargningStation.js @@ -27,7 +27,7 @@ export async function cityCharging(cityId) { * @async * @param {number} cityId Id of the city. * @param {string} chargingId Id of the charging station. - * @returns {Object} Charging station object. + * @returns {object} Charging station object. */ export async function cityChargingId(cityId, chargingId) { let conn; diff --git a/backend/src/db/customer.js b/backend/src/db/customer.js index f0ad11a8..71511142 100644 --- a/backend/src/db/customer.js +++ b/backend/src/db/customer.js @@ -25,7 +25,7 @@ export async function showCustomers() { * Retrieves a customer by ID. * @async * @param {number} customerId Id of the customer. - * @returns {Object} Customer object. + * @returns {object} Customer object. */ export async function showCustomersId(customerId) { let conn; @@ -42,7 +42,7 @@ export async function showCustomersId(customerId) { * Retrieves a customer by email. * @async * @param {string} email Email of the customer. - * @returns {Object} Customer object. + * @returns {object} Customer object. */ export async function showCustomerEmail(email) { let conn; @@ -77,13 +77,13 @@ export async function customerTripsId(customerId) { /** * Adds a new customer. * @async - * @param {Object} data Customer data. + * @param {object} data Customer data. * @param {string} data.name Name of the customer. * @param {string} data.email Email of the customer. * @param {string} data.password Password of the customer. * @param {number} data.balance Starting balance. * @param {string} data.type Type of customer. - * @returns {Object} Result from the database. + * @returns {object} Result from the database. */ export async function addCustomer(data) { let conn; @@ -106,7 +106,7 @@ export async function addCustomer(data) { * Deletes a customer by ID. * @async * @param {number} id Id of the customer. - * @returns {Object} Result from the database. + * @returns {object} Result from the database. */ export async function deleteCustomer(id) { let conn; @@ -123,14 +123,14 @@ export async function deleteCustomer(id) { * Updates a customer by ID. * @async * @param {number} id Id of the customer. - * @param {Object} data Customer data. + * @param {object} data Customer data. * @param {string} data.name Name of the customer. * @param {string} data.email Email of the customer. * @param {number} data.balance Balance of the customer. * @param {string} data.type Type of the customer. * @param {string} data.subscription Subscription status. * @param {number} data.subscription_amount Subscription amount. - * @returns {Object} Result from the database. + * @returns {object} Result from the database. */ export async function updateCustomer(id, data) { let conn; diff --git a/backend/src/db/parkingSation.js b/backend/src/db/parkingSation.js index 824d868d..5a43bab9 100644 --- a/backend/src/db/parkingSation.js +++ b/backend/src/db/parkingSation.js @@ -27,7 +27,7 @@ export async function cityParking(cityId) { * @async * @param {number} cityId Id of the city. * @param {string} parkingId Id of the parking station. - * @returns {Object} Parking station object. + * @returns {object} Parking station object. */ export async function cityParkingId(cityId, parkingId) { let conn; diff --git a/backend/src/db/payment.js b/backend/src/db/payment.js index 4199c9a6..3d27e065 100644 --- a/backend/src/db/payment.js +++ b/backend/src/db/payment.js @@ -9,9 +9,9 @@ import pool from "./pool.js"; * Adds or updates a user's subscription. * @async * @param {number} id Id of the user. - * @param {Object} data Subscription data. + * @param {object} data Subscription data. * @param {number} data.amount Amount of subscription. - * @returns {Object} Updated subscription object. + * @returns {object} Updated subscription object. */ export async function userSub(id, data) { let conn; @@ -33,7 +33,7 @@ export async function userSub(id, data) { * Cancels a user's subscription by ID. * @async * @param {number} id Id of the user. - * @returns {Object} Result from the database. + * @returns {object} Result from the database. */ export async function cancelSub(id) { let conn; @@ -51,7 +51,7 @@ export async function cancelSub(id) { * @async * @param {number} id Id of the user. * @param {number} amount Amount to add. - * @returns {Object} Updated user object with new balance. + * @returns {object} Updated user object with new balance. */ export async function addBalance(id, amount) { let conn; diff --git a/backend/src/db/scooter.js b/backend/src/db/scooter.js index 134b620c..4be4e91d 100644 --- a/backend/src/db/scooter.js +++ b/backend/src/db/scooter.js @@ -8,12 +8,12 @@ import pool from "./pool.js"; /** * Adds a new scooter. * @async - * @param {Object} data Scooter data. + * @param {object} data Scooter data. * @param {number} data.city_id Id of the city. * @param {string} data.name Name of the scooter. * @param {number} data.latitude Latitude coordinate. * @param {number} data.longitude Longitude coordinate. - * @returns {Object} Result from the database. + * @returns {object} Result from the database. */ export async function addScooter(data) { let conn; @@ -35,12 +35,12 @@ export async function addScooter(data) { * Updates a scooter by ID. * @async * @param {string} id Id of the scooter. - * @param {Object} data Scooter data. + * @param {object} data Scooter data. * @param {number} data.battery Battery percentage. * @param {number} data.latitude Latitude coordinate. * @param {number} data.longitude Longitude coordinate. * @param {string} data.status Status of the scooter. - * @returns {Object} Result from the database. + * @returns {object} Result from the database. */ export async function updateScooter(id, data) { let conn; @@ -63,7 +63,7 @@ export async function updateScooter(id, data) { * Deletes a scooter by ID. * @async * @param {string} id Id of the scooter. - * @returns {Object} Result from the database. + * @returns {object} Result from the database. */ export async function deleteScooter(id) { let conn; @@ -98,7 +98,7 @@ export async function cityScooters(cityId) { * @async * @param {number} cityId Id of the city. * @param {string} scooterId Id of the scooter. - * @returns {Object} Scooter object. + * @returns {object} Scooter object. */ export async function cityScootersId(cityId, scooterId) { let conn; diff --git a/backend/src/db/trip.js b/backend/src/db/trip.js index 5ebced87..56aa2e13 100644 --- a/backend/src/db/trip.js +++ b/backend/src/db/trip.js @@ -25,7 +25,7 @@ export async function showTrips() { * Retrieves a specific trip by ID. * @async * @param {number} tripId Id of the trip. - * @returns {Object} Trip object. + * @returns {object} Trip object. */ export async function showTripsId(tripId) { let conn; diff --git a/backend/src/db/zone.js b/backend/src/db/zone.js index dfd63024..90a5ce11 100644 --- a/backend/src/db/zone.js +++ b/backend/src/db/zone.js @@ -27,7 +27,7 @@ export async function cityZone(cityId) { * @async * @param {number} cityId Id of the city. * @param {string} zoneId Id of the zone. - * @returns {Object} Zone object. + * @returns {object} Zone object. */ export async function cityZoneId(cityId, zoneId) { let conn; diff --git a/backend/src/events/bus.js b/backend/src/events/bus.js index 76351209..89ef0842 100644 --- a/backend/src/events/bus.js +++ b/backend/src/events/bus.js @@ -12,7 +12,7 @@ export default bus; /** * A listener for Scooter-rent that triggers an emit to start rent process. * @param {string} event The scooter-rent event. - * @param {Function} listener Arrow function triggering events. + * @param {bus} listener Arrow function triggering events. */ bus.on("scooter-rent", async (data) => { try { diff --git a/backend/src/modules/auth/loginAttempt.js b/backend/src/modules/auth/loginAttempt.js index a2907f3e..7aefe154 100644 --- a/backend/src/modules/auth/loginAttempt.js +++ b/backend/src/modules/auth/loginAttempt.js @@ -1,9 +1,10 @@ /** * Attempts to log in a user with a given token. - * @param {Object} user The user object. + * @param {object} user The user object. * @param {string} token The authentication token. * @returns {string} A placeholder string. */ +// eslint-disable-next-line no-unused-vars export async function loginAttempt(user, token) { return "placeholder"; } diff --git a/backend/src/modules/user/checkBalance.js b/backend/src/modules/user/checkBalance.js index c777c428..3b56c247 100644 --- a/backend/src/modules/user/checkBalance.js +++ b/backend/src/modules/user/checkBalance.js @@ -3,7 +3,6 @@ import { userModel } from "../../models/user"; /** * Check if user has balance that exceeds minimum sum to start a trip. - * * @async * @param {number} userId A userId used to check that users balance. * @throws {Error} If users balance if below minimum constant, throw error. diff --git a/backend/src/routes/v1/authRoute.js b/backend/src/routes/v1/authRoute.js index ddb3278c..62e15d92 100644 --- a/backend/src/routes/v1/authRoute.js +++ b/backend/src/routes/v1/authRoute.js @@ -1,9 +1,7 @@ import express from "express"; import axios from "axios"; -import urls from "../../utils/baseUrl.js"; const router = express.Router(); -const frontendRoute = urls[1]; /** * Post data used in auth route. diff --git a/backend/src/routes/v1/sessionRoute.js b/backend/src/routes/v1/sessionRoute.js index 9c7baf97..2e080647 100644 --- a/backend/src/routes/v1/sessionRoute.js +++ b/backend/src/routes/v1/sessionRoute.js @@ -4,16 +4,6 @@ import urls from "../../utils/baseUrl.js"; const router = express.Router(); const frontendRoute = urls[1]; -/** - * Post data used in auth route. - */ -const postData = { - client_id: process.env.GOOGLE_CLIENT_ID, - client_secret: process.env.GOOGLE_CLIENT_SECRET, - refresh_token: process.env.GOOGLE_REFRESH_TOKEN, - grant_type: "refresh_token", -}; - /** * Route to check if there is a user logged into session. */ diff --git a/backend/src/simulation/simulation.js b/backend/src/simulation/simulation.js index a3cd6175..b64ed486 100644 --- a/backend/src/simulation/simulation.js +++ b/backend/src/simulation/simulation.js @@ -84,6 +84,11 @@ export function beginTrip(scooter, user) { }, speedInterval); } +/** + * A function that returns correct scooter routes from its citys dataset. + * @param {number} cityId Takes a number and chooses a dataset to get a route from. + * @returns {JSON} A random route as a variable containing JSON format route information + */ function chooseRoute(cityId) { let navigationRoutes = ""; switch (cityId) { @@ -102,11 +107,20 @@ function chooseRoute(cityId) { return route.routes[0].geometry.coordinates; } +/** + * Choose a random user + * @returns {number} Returns a random number between 1 and 1001 which + * is starting database customer safe + */ function chooseUserId() { let userId = Math.floor(Math.random() * 1001); return userId + 1; // Num can never be more than 1001 but can be 0, +1 normalize } +/** + * Chooses a city by random and returns it by index in cities + * @returns {string} Return string of its name + */ function chooseCity() { // const cities = Object.keys(scootersSorted); const cities = { @@ -126,8 +140,11 @@ function chooseCity() { export async function simulationRunning(numberSimulations = 500) { let simulatedTrips = 0; - /* Release one scooter with status 'available' from random city to random user for demo - Sets a interval to 0.8 seconds for every scooter release */ + /** + * + * Sets a interval to 1 seconds for every scooter release + * Release one scooter with status 'available' from random city to random user for demo + */ function releaseScooter() { const status = "available"; if (simulatedTrips > numberSimulations) { diff --git a/backend/test/app.test.js b/backend/test/app.test.js index de6c3c9f..86d7d668 100644 --- a/backend/test/app.test.js +++ b/backend/test/app.test.js @@ -7,8 +7,8 @@ import { fakedata } from './../src/mockData/fakeData.js'; describe('Faker Functions', function() { /** - * Tests for generated user data. - */ + * Tests for generated user data. + */ describe('users', function() { it('should return an array', function() { assert.isArray(fakedata.user()); diff --git a/frontend/src/Verification/verifyGoogleToken.js b/frontend/src/Verification/verifyGoogleToken.js index 896a1837..79f8ebd2 100644 --- a/frontend/src/Verification/verifyGoogleToken.js +++ b/frontend/src/Verification/verifyGoogleToken.js @@ -49,6 +49,7 @@ export async function verifyGoogleToken(accessToken, expectedClientId) { /** * Checks if a valid user session exists. + * @returns {boolean} Returns True if user has token */ export async function verifyToken() { const sessionData = await fetch(`${baseUrl}/auth/session`); @@ -60,6 +61,7 @@ export async function verifyToken() { /** * Fetch session data from the backend. + * @returns {JSON} Sessiondata */ export async function getData() { const sessionData = await fetch(`${baseUrl}/auth/session`); diff --git a/frontend/src/components/Admin/AdminMenu.jsx b/frontend/src/components/Admin/AdminMenu.jsx index d04297a6..b86d3f9a 100644 --- a/frontend/src/components/Admin/AdminMenu.jsx +++ b/frontend/src/components/Admin/AdminMenu.jsx @@ -77,6 +77,9 @@ export default function AdminMenu() { onClick={(e) => { if (e.target === e.currentTarget) closeDrawer(); }} + onKeyDown={(e) => { + if (e.key === "Escape") closeDrawer(); + }} >