Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/yougotnothing/nestjs-todo-api


https://github.com/yougotnothing/nestjs-todo-api

Last synced: about 2 months ago
JSON representation

Awesome Lists containing this project

README

        

# NestJS API

Docs
Configuration
Installation
Running the app
Types

---

## This is a NestJS todo Rest API


## Configuration

- in the **root folder** *create* a `.env` file and add the followind ***variables***:

`.env`
```env
DB_NAME=... #your postgres database name
DB_PASSWORD=... #your postgres password
DB_USERNAME=... #your postgres username
DB_PORT=... #your postgres port
DB_HOST=localhost #this is default value, you can change it if you run don't run app on localhost

CORS_ORIGIN=... #your frontend URL/URLS

MAIL_HOST=... #your mail smtp host
MAIL_PORT=465 #your mail smtp port
MAIL_USER=... #your mail (example: [email protected])
MAIL_PASSWORD=... #your mail password
MAIL_SECURE=true

JWT_SECRET=... #your jwt secret key
JWT_ACCESS_EXPIRES-IN=... #time whem access token expires in (default: 900s)
JWT_REFRESH_EXPIRES-IN=... #time when refresh token expires in (default: 7d)
```


## Installation

- to ***run*** the app you ***need to install*** all **dependencies**:

`bash`
```bash
yarn install
```

---


## Running the app

`bash`
- to ***run app*** in *`dev`* mode:
```bash
yarn start:dev
```

`bash`
- to ***run app*** in *`prod`* mode:
```bash
yarn start:prod
```

`bash`
- to ***`build`*** the app:
```bash
yarn build
```

---


# ***API Documentation***

Auth
User
Tasks


## **Auth**

- ***`POST`*** `/auth/register`
- register a new user
- **Request Body**
- `name`: *string*
- `email`: *string*
- `password`: *string*
- **Response**
- `status`: *number*
- `message`: *string*

- ***`POST`*** `/auth/login`
- login a user
- **Request Body**
- `login`: *string*
- `password`: *string*
- **Response**
- `status`: *number*
- `message`: *string*
- `access_token`: *string*


## **User**

- ***`POST`*** `/user/change-avatar`
- changes user avatar
- **Request Headers**
- `Authorization`: *`Bearer` string*
- **Request Body**
- `avatar`: *string*
- **Response**
- `status`: *number*
- `message`: *string*

- ***`PATCH`*** `/user/change-name`
- changes user name
- **Request Headers**
- `Authorization`: *`Bearer` string*
- **Request Body**
- `id`: *number*
- `name`: *string*
- **Response**
- `status`: *number*
- `message`: *string*

- ***`GET`*** `/user/get-tasks`
- get all user tasks
- **Request Headers**
- `Authorization`: *`Bearer` string*
- **Response**
- `status`: *number*
- `message`: *string*
- `tasks`: *Task[]*

- ***`GET`*** `/user/get-avatar`
- get user avatar file by user id
- **Query**
- `id`: *number*
- **Response**
- `status`: *number*
- `avatar`: *Buffer*

- ***`GET`*** `/user/get-user`
- get public user DTO by user id
- **Query**
- `id`: *number*
- **Response**
- `status`: *number*
- `message`: *string*
- `user`: *PublicUserDto*

### Task[]

- ***`GET`*** `/user/get-user`
- get public user DTO by token
- **Request Headers**
- `Authorization`: *`Bearer` string*
- **Response**
- `status`: *number*
- `message`: *string*
- `user`: *PublicUserDto*

### PublicUserDto

- ***`GET`*** `/user/get-avatar`
- get user avatar url by token
- **Query**
- `id`: *number*
- `time`: *Date*
- **Response**
- `status`: *number*
- `message`: *string*
- `avatar`: *string*

- ***`PATCH`*** `/user/change-password`
- changes user password
- **Request Headers**
- `Authorization`: *`Bearer` string*
- **Query**
- `id`: *number*
- **Request Body**
- `password`: *string*
- `confirmPassword`: *string*
- **Response**
- `status`: *number*
- `message`: *string*
- `token`: *`Basic` string*


## **Tasks**

- ***`PATCH`*** `/tasks/change-header`
- changes task header
- **Request Headers**
- `Authorization`: *`Bearer` string*
- **Request Body**
- `id`: *number*
- `header`: *string*
- **Response**
- `status`: *number*
- `message`: *string*

- ***`DELETE`*** `/tasks/delete-task`
- delete task
- **Request Headers**
- `Authorization`: *`Bearer` string*
- **Query**
- `id`: *number* // task id
- **Response**
- `status`: *number*
- `message`: *string*

- ***`GET`*** `tasks/get-tasks-by-substring`
- get tasks by substring
- **Request Headers**
- `Authorization`: *`Bearer` string*
- **Query**
- `substring`: *string*
- **Response**
- `status`: *number*
- `message`: *string*
- `tasks`: *Task[]*

### Task[]

- ***`GET`*** `tasks/get-tasks-by-type`
- get tasks by type
- **Request Headers**
- `Authorization`: *`Bearer` string*
- **Query**
- `type`: *TodoType*
- **Response**
- `status`: *number*
- `message`: *string*
- `tasks`: *Task[]*

### Task[], TodoType

- ***`GET`*** `tasks/get-today-tasks`
- get today tasks
- **Request Headers**
- `Authorization`: *`Bearer` string*
- **Query**
- `createdAt`: *string*
- **Response**
- `status`: *number*
- `message`: *string*
- `tasks`: *Task[]*

### Task[]

- ***`GET`*** `tasks/get-tasks-by-header`
- get tasks by header
- **Request Headers**
- `Authorization`: *`Bearer` string*
- **Query**
- `header`: *string*
- **Response**
- `status`: *number*
- `message`: *string*
- `tasks`: *Task[]*

### Task[]

- ***`GET`*** `tasks/get-tasks-by-month`
- get tasks by month
- **Request Headers**
- `Authorization`: *`Bearer` string*
- **Query**
- `month`: *string*
- **Response**
- `status`: *number*
- `message`: *string*
- `tasks`: *Task[]*

### Task[]

- ***`GET`*** `tasks/get-tasks-by-week`
- get tasks by week
- **Request Headers**
- `Authorization`: *`Bearer` string*
- **Query**
- `week`: *string*
- **Response**
- `status`: *number*
- `message`: *string*
- `tasks`: *Task[]*

### *Task*

- ***`GET`*** `tasks/get-tasks-length`
- get tasks length
- **Request Headers**
- `Authorization`: *`Bearer` string*
- **Response**
- `status`: *number*
- `message`: *string*
- `tasks`: *Record*

### *TodoType*


# ***Types***

### ***Task***


```typescript
interface Task {
header: string;
isChecked: boolean;
createdAt: string;
from: string;
till: string;
important: boolean;
creator: string; // user name
id: number;
type: TodoType;
tasks: Array<{ isChecked: boolean, content: string }>; // subtasks
}
```


### ***User***

```typescript
interface User {
name: string;
email: string;
password: string;
avatar: Buffer;
isHaveAvatar: boolean;
tasks: Task[];
}
```


### ***CreateTodoDto***

```typescript
interface CreateTodoDto {
isChecked: boolean;
createdAt: string;
from: string;
header: string;
important: boolean;
tasks: Array<{ isChecked: boolean, content: string }>;
till: string;
type: TodoType;
}
```


### ***TodoType***

```typescript
type TodoType =
| 'school'
| 'work'
| 'shop'
| 'read'
| 'work out';
```


### ***PublicUserDto***

```typescript
interface PublicUserDto {
isHaveAvatar: boolean;
name: string;
email: string;
avatar: string; // `${process.env.API_URL}/user/get-avatar?id=${user.id}&time=${new Date()}`
}
```