Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
84c6026
chore: update .gitignore
Quiddlee Mar 5, 2024
b8a9d99
refactor: change app to listen on port from .env
Quiddlee Mar 5, 2024
e89a662
refactor: change to use port from .env
Quiddlee Mar 5, 2024
ddce60f
feat: implement user endpoint CRUD
Quiddlee Mar 5, 2024
d893a65
feat: implement id error handling
Quiddlee Mar 6, 2024
72136b6
feat: implement user dto validation
Quiddlee Mar 6, 2024
9a29acb
refactor: change db to be a separate module
Quiddlee Mar 6, 2024
550f1b6
chore: update npm dependencies
Quiddlee Mar 6, 2024
1a28ff3
chore: update eslint config
Quiddlee Mar 6, 2024
ec670ec
chore: add eslint rules dependencies
Quiddlee Mar 6, 2024
cb1e528
chore: include project files in tsconfig
Quiddlee Mar 6, 2024
2156df0
chore: disable unnecessary eslint rules
Quiddlee Mar 6, 2024
523952b
chore: update tsconfig include folders
Quiddlee Mar 6, 2024
a6a4eee
refactor: fix eslint problems
Quiddlee Mar 6, 2024
e071066
feat: exclude user password from response
Quiddlee Mar 6, 2024
e075f1e
fix: user dto validation to use MinLength
Quiddlee Mar 6, 2024
7b4fbd2
feat: implement update user password
Quiddlee Mar 6, 2024
d351b34
refactor: change to return 204 status on delete
Quiddlee Mar 6, 2024
0ac12f9
chore: change to not touch test files
Quiddlee Mar 7, 2024
39c89f7
refactor: change userDB to utilize the db abstract class
Quiddlee Mar 7, 2024
a95ee9b
refactor: migrate userDB to one DB class
Quiddlee Mar 7, 2024
af7e58b
feat: add track module
Quiddlee Mar 7, 2024
ee40265
fix: to generate track uuid on create
Quiddlee Mar 7, 2024
eeec5a5
fix: to return results from track service
Quiddlee Mar 7, 2024
a31844a
feat: implement basic create track dto validation
Quiddlee Mar 7, 2024
253fa1f
feat: apply validation to track controller
Quiddlee Mar 7, 2024
881d5e8
fix: create track dto to throw error on empty field
Quiddlee Mar 8, 2024
e264a4b
feat: implement track route validation and exceptions
Quiddlee Mar 8, 2024
2826532
feat: implement artist module
Quiddlee Mar 8, 2024
c213d73
refactor: remove console log
Quiddlee Mar 8, 2024
013dc4c
feat: implement albums module
Quiddlee Mar 8, 2024
2b2e9d8
refactor: move db outside the src folder
Quiddlee Mar 8, 2024
44ae7a2
chore: add missing lint folders
Quiddlee Mar 8, 2024
cd79c33
refactor: break db into smaller db entity pieces
Quiddlee Mar 8, 2024
e7d429e
fix: find user wrong password
Quiddlee Mar 8, 2024
15e3eea
refactor: rename file to be in lower case
Quiddlee Mar 8, 2024
1f5862b
chore: update typescript version
Quiddlee Mar 8, 2024
645f197
fix: artistId to match declared type in constructor
Quiddlee Mar 8, 2024
fd72820
fix: typescript to check null & undefined values
Quiddlee Mar 8, 2024
f4f91cc
fix: to delete artist from track if artist has been deleted
Quiddlee Mar 9, 2024
55ce579
fix: to delete album from track if album has been deleted
Quiddlee Mar 9, 2024
c289060
fix: to delete album from track if album has been deleted
Quiddlee Mar 9, 2024
ab8f303
fix: change albumId and artistId to be possible empty
Quiddlee Mar 9, 2024
1b1d4e0
feat: implement favorite module
Quiddlee Mar 9, 2024
0a1e191
fix: to delete all relation entities if it was deleted in other entities
Quiddlee Mar 9, 2024
f5a3ca0
docs: fix open API docs
Quiddlee Mar 9, 2024
c0d0205
fix: update album dto type
Quiddlee Mar 9, 2024
d27851f
fix: entities update dto to not be partial
Quiddlee Mar 9, 2024
42f4b59
fix: relation entity fields to be optional
Quiddlee Mar 9, 2024
cd2e803
refactor: remove TODOs
Quiddlee Mar 9, 2024
ed8cc42
chore: add script to run tests excluding auth
Quiddlee Mar 10, 2024
2d43257
feat: add custom decorator for validation relation entities ids
Quiddlee Mar 10, 2024
b460014
feat: add more dto validation
Quiddlee Mar 10, 2024
5a76172
docs: update readme
Quiddlee Mar 10, 2024
06add57
chore: add nestjs/swagger package
Quiddlee Mar 10, 2024
6f58c91
feat: implement to automatically generate swagger docs
Quiddlee Mar 10, 2024
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
73 changes: 70 additions & 3 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,91 @@
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
project: ['tsconfig.json'],
tsconfigRootDir: __dirname,
ecmaVersion: 'latest',
sourceType: 'module',
},
plugins: ['@typescript-eslint/eslint-plugin'],
plugins: ['import', 'prettier', '@typescript-eslint'],
extends: [
'airbnb',
'airbnb-typescript',
'airbnb/hooks',
'plugin:@typescript-eslint/recommended',
'plugin:import/recommended',
'plugin:node/recommended',
'plugin:prettier/recommended',
],
root: true,
env: {
node: true,
jest: true,
},
ignorePatterns: ['.eslintrc.js'],
ignorePatterns: [
'.eslintrc.cjs',
'prettier.config.js',
'node_modules',
'environment.d.ts',
'test',
],
rules: {
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/naming-convention': 'off',
'no-underscore-dangle': 'off',
'no-void': 'off',
'class-methods-use-this': 'off',
'import/prefer-default-export': 'off',
'import/no-extraneous-dependencies': 'off',
'import/extensions': ['error', 'never'],
'no-process-exit': 'off',
'no-restricted-syntax': 'off',
'node/no-unpublished-import': 'off',
'node/no-missing-import': 'off',
'node/no-extraneous-import': 'off',
'node/no-unsupported-features/es-syntax': [
'error',
{
ignores: ['modules'],
},
],
'sort-imports': [
'error',
{ ignoreCase: true, ignoreDeclarationSort: true },
],
'import/order': [
'error',
{
groups: [
'builtin',
'external',
'internal',
['sibling', 'parent'],
'index',
],
pathGroups: [
{
pattern: 'node',
group: 'external',
position: 'before',
},
],
pathGroupsExcludedImportTypes: ['internal'],
'newlines-between': 'always',
alphabetize: {
order: 'asc',
caseInsensitive: true,
},
},
],
},
settings: {
'import/resolver': {
node: {
extensions: ['.js', '.jsx', '.ts', '.tsx'],
},
},
},
};
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,7 @@ lerna-debug.log*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
!.vscode/extensions.json

# .env
.env
237 changes: 214 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,106 @@
# Home Library Service
# 🏡📚 Home Library Service

## Prerequisites
*🦥 RS-School task.*

- Git - [Download & Install Git](https://git-scm.com/downloads).
- Node.js - [Download & Install Node.js](https://nodejs.org/en/download/) and the npm package manager.
# 🚀 Getting Started
To run the project locally, you would have to download zip file with the repository or clone it to your computer. ✨

## Downloading
## ⚠️ Setup and Running

🤔 What things do you need to do in order to run our project locally?

* ⚡ Use node 20 LTS
* ✌️ Installed [.git](https://git-scm.com/) on your computer.
* 📝 Code Editor of your choice.

## 🔮 Installation And Preparation

First make sure you have all the things listed in the previous section. Then clone our repository to your computer: 👌

```
git clone {repository URL}
git clone https://github.com/Quiddlee/nodejs2024Q1-service.git
```

## Installing NPM modules
or download zip file manually with the repository.

📦 Navigate into project folder and run:

```
npm install
```

## Running application
Create ```.env``` file in the root of the project and add all the necessary variables 🔥.

You can find ```.env.example``` as an example file in the project root or follow the lines below 🐺:

```dotenv
PORT=4000

CRYPT_SALT=10
JWT_SECRET_KEY=secret123123
JWT_SECRET_REFRESH_KEY=secret123123
TOKEN_EXPIRE_TIME=1h
TOKEN_REFRESH_EXPIRE_TIME=24h
```

🤩 Finally run a development server:
```
npm start
npm run start:dev
```
Aaaaand you're done! 🎉🥳

After starting the app on port (4000 as default) you can open
in your browser OpenAPI documentation by typing http://localhost:4000/doc/.
For more information about OpenAPI/Swagger please visit https://swagger.io/.

## Testing
After starting the app on port from ```.env``` you can open
in your browser ```OpenAPI``` documentation by typing http://localhost:4000/doc.
For more information about OpenAPI/Swagger please visit https://swagger.io. 🙂

## 🥑 Available Scripts

🦚 Here you can find all the scripts that are available in the project.

✅ Start the app in `base` mode:

```
npm run start
```

Start the app in `dev` mode:

```
npm run start:dev
```

Start the app in `prod` mode:

```
npm run start:prod
```

Start the app in `debug` mode:

```
npm run start:debug
```

Lint adn fix the app errors with `eslint`:

```
npm run lint
```

Format the App with `Prettier`:

```
npm run format
```

Type check the App with `TypeScript`:

```
npm run type-check
```

## 🧪 Testing

After application running open new terminal and enter:

Expand Down Expand Up @@ -55,18 +128,136 @@ To run only specific test suite with authorization
npm run test:auth -- <path to suite>
```

### Auto-fix and format
# ⚙️ Technology Stack

```
npm run lint
```
## 🦈 Developing
* 🦅 **Nest.js** - The Backend Framework
* 💖 **TypeScript** - The Language
* 🦄 **Prisma** - The ORM
* 🔒 **bcrypt** - The Password Hasher
* 🎫 **jsonwebtoken** - The JWT Token Generator
* 📖 **Nest.js/Swagger** - The OpenAPI Documentation

```
npm run format
```
## 🧹 Code Quality
* 🧪 **Jest** - The Test Runner
* 🫂 **Supertest** - The Testing Framework
* 🔔 **ESLint** — Air-bnb base - The Linter
* 👏 **Prettier** - The Code Formatter
* 😎 **EditorConfig** - The Code Style Enforcer

## 📚 External Libraries
* ✌️ **dotenv** - The Environment Variables Library
* 🌐 **cross-env** - The Environment Variables Loader


# 📍 Working with the API
🙏 Following the link below, you can find ```Postman``` collection that will make your life easier while working with the API! [postman collection](https://www.postman.com/bold-spaceship-739379/workspace/node-js-service/overview)

![img.png](./public/img.png)

### Debugging in VSCode
## 🌊 API endpoints
The API has the following endpoints:

Press <kbd>F5</kbd> to debug.
### 🙍‍♂️ /user

For more information, visit: https://code.visualstudio.com/docs/editor/debugging
| Method | Endpoint | Description |
|--------|:----------:|------------------------------------:|
| GET | /user | Get all the users from the database |
| GET | /user/:id | Get a single user by ID |
| POST | /user | Create a new user in the database |
| PUT | /user/:id | Update a user by ID |
| DELETE | /user/:id | Delete a user by ID |


### 📀️ /track

| Method | Endpoint | Description |
|--------|:-----------:|-------------------------------------:|
| GET | /track | Get all the tracks from the database |
| GET | /track/:id | Get a single track by ID |
| POST | /track | Create a new track in the database |
| PUT | /track/:id | Update a track by ID |
| DELETE | /track/:id | Delete a track by ID |

### 💽 /album

| Method | Endpoint | Description |
|--------|:-----------:|-------------------------------------:|
| GET | /album | Get all the albums from the database |
| GET | /album/:id | Get a single album by ID |
| POST | /album | Create a new album in the database |
| PUT | /album/:id | Update a album by ID |
| DELETE | /album/:id | Delete a album by ID |

### 👩‍🎤 /artist

| Method | Endpoint | Description |
|--------|:------------:|--------------------------------------:|
| GET | /artist | Get all the artists from the database |
| GET | /artist/:id | Get a single artist by ID |
| POST | /artist | Create a new artist in the database |
| PUT | /artist/:id | Update a artist by ID |
| DELETE | /artist/:id | Delete a artist by ID |

### 📔 /favs

| Method | Endpoint | Description |
|--------|:-----------------:|---------------------------------------------:|
| GET | /favs | Get all the favorites from the database |
| GET | /favs/track/:id | Get a single track from favorites by ID |
| GET | /favs/album/:id | Get a single album from favorites by ID |
| GET | /favs/artist/:id | Get a single artist from favorites by ID |
| POST | /favs/track/:id | Add new track to favorites in the database |
| POST | /favs/album/:id | Add new album to favorites in the database |
| POST | /favs/artist/:id | Add new artist to favorites in the database |
| DELETE | /favs/track/:id | Delete a track by ID from favorites |
| DELETE | /favs/album/:id | Delete a album by ID from favorites |
| DELETE | /favs/artist/:id | Delete a artist by ID from favorites |


## 🍃 Response examples

**GET /users**

```json
[
{
"id": "62a13ccf-6de5-46ae-81dd-81a81301071d",
"login": "loeegin",
"version": 1,
"createdAt": 1710072081506,
"updatedAt": 1710072081506
},
{
"id": "2d2f65be-73af-40d2-842e-4514fc86c664",
"login": "loeegin",
"version": 2,
"createdAt": 1710072083360,
"updatedAt": 1710072913111
},
{
"id": "9fcd76d7-4d5b-45a0-9937-0b7cc9007e52",
"login": "loeegin",
"version": 1,
"createdAt": 1710072084156,
"updatedAt": 1710072084156
},
{
"id": "0d411947-0d1d-495d-aa64-04fe4a9e0549",
"login": "loeegin",
"version": 1,
"createdAt": 1710072084910,
"updatedAt": 1710072084910
}
]
```

**GET /users/:id Error case**

```json
{
"message": "User not found!",
"error": "Not Found",
"statusCode": 404
}
```
Loading