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
1 change: 0 additions & 1 deletion backend/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion backend/src/db/chargningStation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 7 additions & 7 deletions backend/src/db/customer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion backend/src/db/parkingSation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions backend/src/db/payment.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down
12 changes: 6 additions & 6 deletions backend/src/db/scooter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion backend/src/db/trip.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion backend/src/db/zone.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion backend/src/events/bus.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion backend/src/modules/auth/loginAttempt.js
Original file line number Diff line number Diff line change
@@ -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";
}
1 change: 0 additions & 1 deletion backend/src/modules/user/checkBalance.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 0 additions & 2 deletions backend/src/routes/v1/authRoute.js
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
10 changes: 0 additions & 10 deletions backend/src/routes/v1/sessionRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
21 changes: 19 additions & 2 deletions backend/src/simulation/simulation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 = {
Expand All @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions backend/test/app.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/Verification/verifyGoogleToken.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
Expand All @@ -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`);
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/components/Admin/AdminMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ export default function AdminMenu() {
onClick={(e) => {
if (e.target === e.currentTarget) closeDrawer();
}}
onKeyDown={(e) => {
if (e.key === "Escape") closeDrawer();
}}
>
<div className="mobile-drawer-panel">
<div className="mobile-drawer-header">
Expand Down Expand Up @@ -141,3 +144,4 @@ export default function AdminMenu() {
</>
);
}

Loading