Ride-sharing REST API for Node.js Express API in Typescript with jsonwebtoken, joi, Knex, and Objection.js
- A user can be a driver, admin, or customer
- signup is not available to the public.
- No real ride is booked
Clone the repository, install the dependencies.
$ git clone git@github.com:ong-gtp/ride-share.git <application-name>
$ cd <application-name>
$ cp .env.example .env # Update database credentials
$ npm install mysql --save # mysql driver for Knex.
$ yarn install
$ yarn migrate # migrate database
Load fake data in database.
$ yarn load:fake Ride 10 # CREATES 10 RIDES IN THE DB
Start the application.
$ yarn start # For development
$ yarn build # For production
Using Docker (OPTIONAL)
Make a copy of .env.docker
and save as .env
.
$ cp .env.docker .env
Install dependencies and run the application locally.
$ docker compose up -d postgres
$ docker compose up -d api
$ docker compose exec api sh yarn migrate # Make sure server is started checking logs before running this command
View logs of the container.
$ docker compose logs -f
To stop the services.
$ docker compose stop api postgres
To create migration use make:migration
and seed use make:seeder
:
$ yarn make:migration create_{table_name}_table
$ yarn make:seeder {table_name}_table_seeder
Example,
$ yarn make:migration create_vehicles_table
$ yarn make:seeder rides_table_seeder
Modify migration and seeder file as per the requirement. Then finally:
$ yarn migrate # to migrate
$ yarn seed # to seed
App endpoints can be found in api.rest file
#### Routes ⚡
| Routes | HTTP Methods | Params | Description |
| :--------------- | :----------- | :--------------------------------------- | :----------------------------------------------------------------------------------------------------------- |
| / | GET | none | Displays application infomation |
| /login | POST | `email` `password` | Logs in a user and returns the jwt session token |
| /logout | POST | none | Logs out a user |
| /refresh | POST | none | Refresh a user jwt token |
| /start-ride | POST | `customerId` `driverId`, `destination`, `startedFrom | Start a ride |
| /stop-ride | POST | `ride_id` | Stop a ride |
First install Rest Client from vscode extensions
Create a file or add following lines in .vscode
> settings.json
and switch an environment Cmd/Ctrl + Shift + P
> REST Client: Switch Environment
. Then, you can request APIs from api.rest
file.
{
"rest-client.environmentVariables": {
"$shared": {
"refreshToken": "foo",
"accessToken": "bar",
"email": "sgr.raee@gmail.com",
"password": "secret"
},
"local": {
"host": "localhost",
"refreshToken": "{{$shared refreshToken}}",
"accessToken": "{{$shared accessToken}}",
"email": "{{$shared email}}",
"password": "{{$shared password}}"
}
}
}
ride-share is under MIT License.