https://github.com/omept/ride-share
Ride sharing API built with Typescript, Knex, Objection, and Jest
https://github.com/omept/ride-share
authentication expressjs jest-tests logging nodejs restful-api ridesharing typescript
Last synced: 5 months ago
JSON representation
Ride sharing API built with Typescript, Knex, Objection, and Jest
- Host: GitHub
- URL: https://github.com/omept/ride-share
- Owner: omept
- License: mit
- Created: 2023-06-01T04:46:04.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-06-02T04:23:21.000Z (about 3 years ago)
- Last Synced: 2024-01-29T21:04:08.300Z (over 2 years ago)
- Topics: authentication, expressjs, jest-tests, logging, nodejs, restful-api, ridesharing, typescript
- Language: TypeScript
- Homepage:
- Size: 194 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Security: SECURITY.md
Awesome Lists containing this project
README
Ride-sharing REST API for Node.js Express API in Typescript with jsonwebtoken, joi, Knex, and Objection.js
## Requirements
- [Node.js](https://yarnpkg.com/en/docs/install)
- [Yarn](https://yarnpkg.com/en/docs/install)
- [NPM](https://docs.npmjs.com/getting-started/installing-node)
- [Docker](https://docs.docker.com/install/)
## Assumptions
- A user can be a driver, admin, or customer
- signup is not available to the public.
- No real ride is booked
## Getting Started
Clone the repository, install the dependencies.
```bash
$ git clone git@github.com:ong-gtp/ride-share.git
$ cd
$ 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.
```bash
$ yarn load:fake Ride 10 # CREATES 10 RIDES IN THE DB
```
Start the application.
```bash
$ yarn start # For development
$ yarn build # For production
```
**Using Docker (OPTIONAL)**
Make a copy of `.env.docker` and save as `.env`.
```bash
$ cp .env.docker .env
```
Install dependencies and run the application locally.
```bash
$ 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.
```bash
$ docker compose logs -f
```
To stop the services.
```bash
$ docker compose stop api postgres
```
## (Development) Generating Migrations and Seeds
To create migration use `make:migration` and seed use `make:seeder`:
```bash
$ yarn make:migration create_{table_name}_table
$ yarn make:seeder {table_name}_table_seeder
```
Example,
```bash
$ yarn make:migration create_vehicles_table
$ yarn make:seeder rides_table_seeder
```
Modify migration and seeder file as per the requirement. Then finally:
```bash
$ yarn migrate # to migrate
$ yarn seed # to seed
```
## REST endpoints
```bash
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 |
```
## Setting up REST Client (OPTIONAL)
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.
```json
{
"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}}"
}
}
}
```
## License
ride-share is under [MIT License](LICENSE).
## Reference
- https://github.com/cham11ng/typescript-api-starter
- https://knexjs.org/
- https://vincit.github.io/objection.js