Skip to content
Open
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
17 changes: 17 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
PORT=3000
API_URL=http://localhost:3000

# MySQL Database
MYSQL_HOST=localhost
MYSQL_PORT=3306
MYSQL_USER=root
MYSQL_PASSWORD=
MYSQL_DATABASE=dragonball_api

# JWT Secret (generate a strong random key for production)
JWT_SECRET=change-me-to-a-random-secret

# Cloudinary (image uploads — required for write endpoints)
CLOUDINARY_CLOUD_NAME=
CLOUDINARY_API_KEY=
CLOUDINARY_API_SECRET=
13 changes: 6 additions & 7 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,11 @@ module.exports = {
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'prettier/prettier': [
'error',
{
endOfLine: 'auto',
},
],
},

'prettier/prettier': [
'error',
{
endOfLine: 'auto',
},
],
};
112 changes: 56 additions & 56 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,73 +1,73 @@
<p align="center">
<a href="http://nestjs.com/" target="blank"><img src="https://nestjs.com/img/logo-small.svg" width="200" alt="Nest Logo" /></a>
</p>

[circleci-image]: https://img.shields.io/circleci/build/github/nestjs/nest/master?token=abc123def456
[circleci-url]: https://circleci.com/gh/nestjs/nest

<p align="center">A progressive <a href="http://nodejs.org" target="_blank">Node.js</a> framework for building efficient and scalable server-side applications.</p>
<p align="center">
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/v/@nestjs/core.svg" alt="NPM Version" /></a>
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/l/@nestjs/core.svg" alt="Package License" /></a>
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/dm/@nestjs/common.svg" alt="NPM Downloads" /></a>
<a href="https://circleci.com/gh/nestjs/nest" target="_blank"><img src="https://img.shields.io/circleci/build/github/nestjs/nest/master" alt="CircleCI" /></a>
<a href="https://coveralls.io/github/nestjs/nest?branch=master" target="_blank"><img src="https://coveralls.io/repos/github/nestjs/nest/badge.svg?branch=master#9" alt="Coverage" /></a>
<a href="https://discord.gg/G7Qnnhy" target="_blank"><img src="https://img.shields.io/badge/discord-online-brightgreen.svg" alt="Discord"/></a>
<a href="https://opencollective.com/nest#backer" target="_blank"><img src="https://opencollective.com/nest/backers/badge.svg" alt="Backers on Open Collective" /></a>
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://opencollective.com/nest/sponsors/badge.svg" alt="Sponsors on Open Collective" /></a>
<a href="https://paypal.me/kamilmysliwiec" target="_blank"><img src="https://img.shields.io/badge/Donate-PayPal-ff3f59.svg"/></a>
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://img.shields.io/badge/Support%20us-Open%20Collective-41B883.svg" alt="Support us"></a>
<a href="https://twitter.com/nestframework" target="_blank"><img src="https://img.shields.io/twitter/follow/nestframework.svg?style=social&label=Follow"></a>
</p>
<!--[![Backers on Open Collective](https://opencollective.com/nest/backers/badge.svg)](https://opencollective.com/nest#backer)
[![Sponsors on Open Collective](https://opencollective.com/nest/sponsors/badge.svg)](https://opencollective.com/nest#sponsor)-->

## Description

[Nest](https://github.com/nestjs/nest) framework TypeScript starter repository.

## Installation
# Dragon Ball API

```bash
$ npm install
```
REST API for Dragon Ball characters, planets, and transformations built with NestJS.

## Tech Stack

## Running the app
- **Runtime:** Node.js 20
- **Framework:** NestJS 10 + Express
- **Database:** MySQL 8.0 via TypeORM
- **Auth:** JWT (bcryptjs)
- **Image Upload:** Cloudinary
- **Docs:** Swagger (`/api-docs`)
- **Testing:** Jest (28 unit tests, 4 e2e)

## Setup

```bash
# development
$ npm run start
# 1. Copy env vars and fill them in
cp .env.example .env

# 2. Install
npm install

# 3. Start MySQL and create the database
mysql -u root -e "CREATE DATABASE dragonball_api;"

# watch mode
$ npm run start:dev
# 4. (optional) Import seed data
mysql -u root dragonball_api < "Dump 04112023last.sql"

# production mode
$ npm run start:prod
# 5. Run
npm run start:dev
```

## Test
## API

```bash
# unit tests
$ npm run test
Global prefix: `/api` — Docs at `/api-docs`

# e2e tests
$ npm run test:e2e
### Public Endpoints

# test coverage
$ npm run test:cov
```
| Method | Path | Description |
|--------|------|-------------|
| GET | `/api/characters` | List characters (paginated, filterable) |
| GET | `/api/characters/:id` | Get character with planet + transformations |
| GET | `/api/planets` | List planets (paginated, filterable) |
| GET | `/api/planets/:id` | Get planet with characters |
| GET | `/api/transformations` | List transformations |
| GET | `/api/transformations/:id` | Get transformation with character |

### Auth Endpoints

## Support
| Method | Path | Body | Returns |
|--------|------|------|---------|
| POST | `/api/auth/register` | `{name, email, password}` | User (no password hash) |
| POST | `/api/auth/login` | `{email, password}` | `{access_token, user}` |

Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please [read more here](https://docs.nestjs.com/support).
### Protected Endpoints (require `Authorization: Bearer <token>`)

## Stay in touch
POST/PATCH/DELETE on all `/api/characters`, `/api/planets`, `/api/transformations`

- Author - [Kamil Myśliwiec](https://kamilmysliwiec.com)
- Website - [https://nestjs.com](https://nestjs.com/)
- Twitter - [@nestframework](https://twitter.com/nestframework)
## Scripts

```bash
npm run start:dev # watch mode
npm run test # 28 unit tests
npm run test:e2e # 4 e2e tests (requires MySQL)
npm run lint # eslint
npm run format # prettier
npm run build # compile
```

## License
## Node.js Compatibility

Nest is [MIT licensed](LICENSE).
Node.js 20 is recommended. Node 26+ requires a patch to `buffer-equal-constant-time` (see `node_modules/`).
30 changes: 3 additions & 27 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@
"**/*.(t|j)s"
],
"coverageDirectory": "../coverage",
"testEnvironment": "node"
"testEnvironment": "node",
"moduleNameMapper": {
"^src/(.*)$": "<rootDir>/$1"
}
}
}
3 changes: 2 additions & 1 deletion src/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { AuthModule } from './auth/auth.module';
import { AuthController } from './auth/auth.controller';
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { ConfigModule } from '@nestjs/config';
Expand All @@ -23,6 +22,8 @@ import { UsersModule } from './users/users.module';
password: process.env.MYSQL_PASSWORD,
database: process.env.MYSQL_DATABASE,
entities: [__dirname + '/**/*.entity{.ts,.js}'],
// TODO: synchronize drops and recreates tables on every restart.
// Replace with TypeORM migrations before deploying to production.
synchronize: true,
}),
ServeStaticModule.forRoot({
Expand Down
Loading