An open API service indexing awesome lists of open source software.

https://github.com/tfd-ed/tfd-nest-blog-api

API for TFD E-Learning
https://github.com/tfd-ed/tfd-nest-blog-api

docker e-learning nestjs postgresql rest-api typeorm typescript

Last synced: about 1 year ago
JSON representation

API for TFD E-Learning

Awesome Lists containing this project

README

          

TFD E-Learning API













NPM Version
Package License
YouTube Channel Subscribers

## Features

This is a NestJS boilerplate code with preconfigured libraries and packages with the following features:
- One-click setup with [Docker](https://www.docker.com/)
- [Typeorm](https://typeorm.io/) for Object–relational mapping, use **Postgres DB** by default
- Sample data generation with typeorm-fixture (generate fixture based on .yaml file), visit [RobinCK/typeorm-fixtures](https://github.com/RobinCK/typeorm-fixtures).
- Preconfigured Caching Mechanism ([Redis Store](https://redis.io/))
- [Swagger UI](https://swagger.io/) (Express)
- Authentication with JWT
- Basic RBAC implementation ( You'll have to attach user object to your request manually )

## TFD E-Learning
- TFD Blog (Now TFD E-Learning) : https://github.com/tfd-ed/tfd-blog
- TFD E-Learning Admin: https://github.com/tfd-ed/tfd-elearning-admin
- TFD E-Learning API: https://github.com/tfd-ed/tfd-nest-blog-api

## Setup Guide
**Be aware that** putting **DB_SYNC** to true in your production may result in irreversible data lost.
**DB_SYNC** should only be put to true in development to skip the necessity of doing migrations.
### Without Docker

- Create .env file with command `cp .env.example .env` and replace with your own env variable
- `yarn install`
- `yarn start` (Your API will be exposed through port 3000)

### With Docker
Run the following scripts for UNIX (Mac,Linux)
```bash
$ cp .env.example .env
$ docker-compose up -d
```
DOS(Windows)
```bash
$ copy .env.example .env
$ docker-compose up -d
```

## Available Services with Docker Container
Once you managed to run the docker container, the following service will be available:
- Nginx will serve as a reverse proxy and will be exposed through port 80 (http://localhost)
- Swagger API Docs (http://localhost/docs/)
- Database (Postgres 12) (http://localhost:5432)
- Redis Commander (http://localhost:8081)
- Redis Store (Only Available in internal docker network) (http://0.0.0.0:6379)
- NestJs Server (Only Available in internal docker network) (http://0.0.0.0:3000)
## Migration Guide
New migration with typeorm-cli:
```bash
$ docker exec -it tfd-api-server yarn migration:create -n {CreateTable}
```
Migration file will be inside `src/migrations`.
Note that you will have to write migration code inside up and down method on your own.
To generate migration for new database or from the changes in database schema(entities) use:
```bash
$ docker exec -it tfd-api-server yarn migration:generate -n {GenerateTable}
```
#### Run Migrations
```bash
$ docker exec -it tfd-api-server yarn migration:run
```
#### Revert Migrations
```bash
$ docker exec -it tfd-api-server yarn migration:revert
```

## Generate Fixture
Fixture lets you play around with sample data. It's not recommended generating in production since it may erase real data. visit [RobinCK/typeorm-fixtures](https://github.com/RobinCK/typeorm-fixtures) for more info.
#### Generate Sample Data Make sure the docker container is running
```bash
$ docker exec -it tfd-api-server yarn fixture:generate
```