Skip to content

eduraio/tasks-api

Repository files navigation

Tasks API

Description

Tasks API is a simples project to create tasks with users permissions.

Technologies

  • Nest.js
  • Prisma (With PostgresSQL)
  • Docker

My Requirements

  • Task name must be unique
  • Only allowed users can create tasks

Installation

1 - Clone the repository

git clone https://github.com/eduraio/tasks-api.git

2 - Install Dependecies

yarn install

3 - Populate .env file based on .env.example

DATABASE_URL="postgresql://user:password@localhost:5432/database?schema=public"
JWT_SECRET=

Postgres User, Password and Database available on docker-compose.yml

Generate a JWT Secret, you can run the following script to generate yours:

node -e "console.log(require('crypto').randomBytes(32).toString('hex'))"

4 - Run docker-compose

docker-compose up

5 - Run Prisma Migrations

yarn prisma migrate dev

6 - Run Prisma Seed

yarn prisma db seed

Usage

To start the project use:

yarn start

To access the API Documentation

http://localhost:3000/docs

Note that all routes, except login, are protected.

Use admin credentials to login and get the AccessToken. This user is created running Prisma Seed. Check Installation Step 6

e-mail: [email protected]
password: admin

AccessTokens are valid for 10 minutes

You will need the AccessToken to authenticate on other routes

Routes

Here goes all the routes. You can also check Docs for full details.

Included with the files, has an Insomnia Workspace with all routes as well. Just import it inside Insomnia.

πŸ”’ All routes, except login, must have an Authorization header containing the accessToken

{
  "Authorization": "Bearer {accessToken}"
}

Login

🟒 POST /auth/login

Request Body

{
  "email": "string",
  "password": "string"
}

Response Application/json

{
  "accessToken": "string"
}

πŸ”’ Users

Parameter Description
id User UUID
email UNIQUE User e-mail
password User password
permissions Array of permissions. All permissions: READ_USERS CREATE_USERS UPDATE_USERS DELETE_USERS READ_TASKS CREATE_TASKS UPDATE_TASKS DELETE_TASKS
tasks? Array of tasks created by this user
created_at Date of creation
updated_at Last updated date

πŸ”΅ GET /users

Request Body

{}

Response Application/json

{
  [
    {
      "id": "string",
      "email": "string",
      "password": "string", (omitted)
      "permissions": [
        "READ_USERS",
        "CREATE_USERS",
        "UPDATE_USERS",
        "DELETE_USERS",
        "READ_TASKS",
        "CREATE_TASKS",
        "UPDATE_TASKS",
        "DELETE_TASKS"
      ],
      "tasks": [],
      "created_at": "date",
      "updated_at": "date"
    }
  ]
}

πŸ”΅ GET /users/{id}

Request Body

  {}

Response Application/json

[
  {
    "id": "string",
    "email": "string",
    "password": "string", (omitted)
    "permissions": [
      "READ_USERS",
      "CREATE_USERS",
      "UPDATE_USERS",
      "DELETE_USERS",
      "READ_TASKS",
      "CREATE_TASKS",
      "UPDATE_TASKS",
      "DELETE_TASKS"
    ],
    "tasks": [],
    "created_at": "date",
    "updated_at": "date"
  }
]

🟒 POST /users

Request Body

{
  "email": "string",
  "password": "string",
  "permissions": [
    "READ_USERS",
    "CREATE_USERS",
    "UPDATE_USERS",
    "DELETE_USERS",
    "READ_TASKS",
    "CREATE_TASKS",
    "UPDATE_TASKS",
    "DELETE_TASKS"
  ]
}

Response Application/json

{
  "id": "string",
  "email": "string",
  "password": "string", (omitted)
  "permissions": [
    "READ_USERS",
    "CREATE_USERS",
    "UPDATE_USERS",
    "DELETE_USERS",
    "READ_TASKS",
    "CREATE_TASKS",
    "UPDATE_TASKS",
    "DELETE_TASKS"
  ],
  "tasks": [],
  "created_at": "date",
  "updated_at": "date"
}

🟣 PATCH /users/{id}

Request Body

{
  "email": "string",
  "password": "string",
  "permissions": [
    "READ_USERS",
    "CREATE_USERS",
    "UPDATE_USERS",
    "DELETE_USERS",
    "READ_TASKS",
    "CREATE_TASKS",
    "UPDATE_TASKS",
    "DELETE_TASKS"
  ]
}

Response Application/json

{
  "id": "string",
  "email": "string",
  "password": "string", (omitted)
  "permissions": [
    "READ_USERS",
    "CREATE_USERS",
    "UPDATE_USERS",
    "DELETE_USERS",
    "READ_TASKS",
    "CREATE_TASKS",
    "UPDATE_TASKS",
    "DELETE_TASKS"
  ],
  "tasks": [],
  "created_at": "date",
  "updated_at": "date"
}

πŸ”΄ DELETE /users/{id}

Request Body

{}

Response Application/json

{
  "id": "string",
  "email": "string",
  "password": "string", (omitted)
  "permissions": [
    "READ_USERS",
    "CREATE_USERS",
    "UPDATE_USERS",
    "DELETE_USERS",
    "READ_TASKS",
    "CREATE_TASKS",
    "UPDATE_TASKS",
    "DELETE_TASKS"
  ],
  "tasks": [],
  "created_at": "date",
  "updated_at": "date"
}

πŸ”’ Tasks

Parameter Description
id Task UUID
name UNIQUE Task name
description Task description
created_by_user_id? Id of the user who created the task. If the user is deleted, field set to null. Note: Automatically populated based on logged in user
created_by_user? User who created the task
created_at Date of creation
updated_at Last updated date

πŸ”΅ GET /tasks

Request Body

{}

Response Application/json

{
  [
    {
      "id": "string",
      "name": "string",
      "description": "string",
      "created_by_user_id": "string",
      "created_by_user": "User",
      "created_at": "date",
      "updated_at": "date"
    }
  ]
}

πŸ”΅ GET /tasks/{id}

Request Body

  {}

Response Application/json

[
  {
    "id": "string",
    "name": "string",
    "description": "string",
    "created_by_user_id": "string",
    "created_by_user": "User",
    "created_at": "date",
    "updated_at": "date"
  }
]

🟒 POST /tasks

Request Body

{
  "name": "string",
  "description": "string",
}

Response Application/json

{
  "id": "string",
  "name": "string",
  "description": "string",
  "created_by_user_id": "string",
  "created_by_user": "User",
  "created_at": "date",
  "updated_at": "date"
}

🟣 PATCH /tasks/{id}

Request Body

{
  "name": "string",
  "description": "string",
}

Response Application/json

{
  "id": "string",
  "name": "string",
  "description": "string",
  "created_by_user_id": "string",
  "created_by_user": "User",
  "created_at": "date",
  "updated_at": "date"
}

πŸ”΄ DELETE /tasks/{id}

Request Body

{}

Response Application/json

{
  "id": "string",
  "name": "string",
  "description": "string",
  "created_by_user_id": "string",
  "created_by_user": "User",
  "created_at": "date",
  "updated_at": "date"
}

About

Tasks API

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published