This is the repository for the CS130 project Grand Valet. The folder frontend
contains the implementation of the frontend web application using React. The folder backend
contains the implementation of the web server using Express. The test
folder contains the unit tests for the backend, implemented with Python.
In this section, we describe the APIs of the application in detail. Our working API consists of two parts: the communication REST API between frontend and backend (Server), and the data passing API between the backend and the Database (Database). The API for the Database is automatically generated by JSDoc, and the API for the Server is written in a similar style since the Server does not use object-oriented programming.
Class wrapping database operations.
Kind: global class
- Database
- .connect()
- .db(dbName) ⇒
database
- .close()
- .store_user(body)
- .read_user(username) ⇒
User
- .read_activeHubs() ⇒
Array.<Hub>
- .read_nearbyHubs(loc, radius) ⇒
Array.<Hub>
- .read_hub(hubId) ⇒
Hub
- .store_hub(body)
- .schedule_jobs()
- .read_assignedJobs(username) ⇒
Array.<Job>
- .read_job(jobId) ⇒
Job
- .store_job(body)
- .read_maxMaxJobId() ⇒
number
- .read_maxMaxHubId() ⇒
number
Connect the database
Kind: static method of Database
Database wrapper
Kind: static method of Database
Returns: database
- - Database for MongoDB operations.
Param | Type | Description |
---|---|---|
dbName | string |
Name of the database. |
Close the connection
Kind: static method of Database
Stores a user
Kind: static method of Database
Param | Type | Description |
---|---|---|
body | User |
JSON of a user file. |
Reads a user
Kind: static method of Database
Returns: User
- - JSON of the requested user file.
Param | Type | Description |
---|---|---|
username | string |
Username of the requested user. |
Returns all currently active hubs.
Kind: static method of Database
Returns: Array.<Hub>
- - Array of JSON of currently active hubs.
Reads nearby hubs
Kind: static method of Database
Returns: Array.<Hub>
- - Array of JSON of hubs satisfying the query.
Param | Type | Description |
---|---|---|
loc | coordinates |
Cordinates of the center of the search. |
radius | number |
Radius of the search in miles. |
Reads a hub
Kind: static method of Database
Returns: Hub
- - JSON of the requested hub.
Param | Type | Description |
---|---|---|
hubId | number |
ID of the requested hub. |
Stores a hub
Kind: static method of Database
Param | Type | Description |
---|---|---|
body | Hub |
JSON of a hub file. |
Schedule unassigned jobs that are within 1 hr from scheduled time.
Kind: static method of Database
Reads jobs assigned to a driver and assign jobs using schedule_jobs.
Kind: static method of Database
Returns: Array.<Job>
- - Array of JSON of jobs assigned to the driver.
Param | Type | Description |
---|---|---|
username | string |
Username of the requested driver. |
Reads a job and assign jobs using schedule_jobs.
Kind: static method of Database
Returns: Job
- - JSON of the requested job.
Param | Type | Description |
---|---|---|
jobId | number |
ID of the requested job. |
Stores a job
Kind: static method of Database
Param | Type | Description |
---|---|---|
body | Job |
JSON of a job file. |
Reads the currect maximum jobId
Kind: static method of Database
Returns: number
- - Currect maximum jobId.
Reads the currect maximum hubId
Kind: static method of Database
Returns: number
- - Currect maximum hubId.
The Backend.
- Server
- GET /login
- POST /login
- GET /api/hubs ⇒
Array.<Hub>
- POST /api/hubs ⇒
Hub
- GET /api/jobs ⇒
Array.<Job>
- POST /api/jobs ⇒
Job
Returns an HTML page containing an HTML form with three input elements: username, usertype, and password. When the user presses the submit button, the page should issue a request POST /login
with username=:username&usertype=:usertype&password=:password
in the body.
Kind: static method of Server
Checks that the provided username, usertype, and password matches the record. If the provided information does not match, returns 401 return code. Otherwise, set an authorization session cookie and return 200.
Kind: static method of Server
Param | Type | Description |
---|---|---|
username | string |
User name |
usertype | string |
"user" or "driver" |
password | string |
Password |
Returns the information of the requested hub(s). If hubid is null
, return all the active hubs in the database.
If long, lat, and rad are also given, only return active hubs that are in the circle centered at (long, lat) with
radius rad.
Kind: static method of Server
Returns: Array.<Hub>
- - Array of JSON of hubs
Param | Type | Description |
---|---|---|
hubid | number |
The unique hub id |
long | number |
A number specifying the longitude of the center of search range |
lat | number |
A number specifying the latitude of the center of search range |
rad | number |
A number specifying the circle of search range |
Create or update a hub entry. If hubId is 0, insert a new hub and return 201. If hubId> 0 and hubIdrecord exists, update the existing hub entry by overwriting the description, location, startTime, endTime fields in the request. Return 200. Otherwise, return 404.
Kind: static method of Server
Returns: Hub
- - The updated or created Hub
Param | Type | Description |
---|---|---|
hubid | number |
The unique hub id |
description | string |
Description of the hub |
startTime | startTime |
When the hub starts |
endTime | endTime |
When the hub ends |
location | array |
Longitude and Latitude of the hub (can be null) |
Get all the jobs associated with username or jobid. If username or jobid does not exist, return 404. If jobid is not null, return the job corresponding to the jobid. If username exists and correspond to a driver, return a JSON containing a sorted list of jobs. If username exists and correspond to a customer, return a JSON containing a single job.
Kind: static method of Server
Returns: Array.<Job>
- - Array of JSON of jobs
Param | Type | Description |
---|---|---|
username | string |
User name |
jobid | number |
The unique job id |
Create a new job or update an existing job. First construct a Job object using the data given. If the jobId is 0, create a new job and add it to the database and return the job with code 201. Otherwise, update the status of an existing job and return the hub with code 200. If the jobId is not 0 and the job is not found, return 400.
Kind: static method of Server
Returns: Job
- - The updated or created job
Param | Type | Description |
---|---|---|
data | JSON |
The data corresponding to a new job or an existing job. |