/employees-api

A simple Rest-API that allow us to manage a very basic manage application about employees of a company.

Primary LanguageJavaScript

API Rest: Employees - Challenge #02

Index

Goal

Api developed in order to allow CRUD operations (Create - Read - Update - Delete), using two entities: Employees and Occupations. For agility, the occupations table allows the registration of functions that an employee can perform in a company, so the employees table has a 1: 1 relationship with the occupations table.

Entities

Users

Its an entitie that provides access to the endpoits below.

- https://c0mpany-api.herokuapp.com/employees - POST
- https://c0mpany-api.herokuapp.com/employees/edit/{id} - PUT
- https://c0mpany-api.herokuapp.com/employees/{id} - DELETE

- https://c0mpany-api.herokuapp.com/occupations - POST
- https://c0mpany-api.herokuapp.com/occupations/edit/{id} - PATCH
- https://c0mpany-api.herokuapp.com/occupations/{id} - DELETE
- https://c0mpany-api.herokuapp.com/users/login - POST

To have acess to those endpois ts necessary to login in:

Passing the following structure:

{
	"email": "mail@mail.com",
	"password": "123"
}

After that you will received a token that its necessary to insert in your API tool, you can follow the documentation of insmnia if you are new: Tutorial Insomnia.

To create a new user just use this example:

{
	"name":"any_mail",
	"email": "mail@email.com",
	"password": "123"
}

To see all the users in the database.


Employees

Field Value Type
Id Integer Pk, Not Null
name Varchar(128) Not Null
OccupationId Integer Fk, Not Null
createdAt timestamp Not Null
updatedAt timestamp Not Null

Occupations

Field Value Type
Id Integer Pk, Not Null
name Varchar(128) Not Null
createdAt timestamp Not Null
updatedAt timestamp Not Null

How use

Through one of the apis testing tools: Postman or Insomnia. You can download the file and import into some of these programs to have the routes configured. Bearing in mind that to register an employee it is necessary to register an occupation beforehand.

Routes


Employees routes

  • Return all the users in database.
Status Code Description
200 Request returned successfully
500 Internal server error
  • Passing an id to return a specific user
Status Code Description
200 Request returned successfully
400 Invalid request
404 Request not found
500 Internal server error
  • Register an employee in the system

  • Payload

{
    "name":"Kamila",
    "age":23,    
    "OccupationId":4
}
Status Code Description
201 Entity created successfully
400 Invalid request
  • Update an employee data in the system

  • Payload

{
    "name":"Carol",
    "age":23,    
    "OccupationId":4
}
Status Code Description
201 Entity created successfully
400 Invalid request
404 Request not found
  • Deletes an employee from the database
Status Code Description
200 Request returned successfully
400 Invalid request
404 Request not found
500 Internal server error

Occupations routes

  • Returns all occupations registered in the database
Status Code Description
200 Request returned successfully
500 Internal server error
  • Passing an id to return a specific user
Status Code Description
200 Request returned successfully
400 Invalid request
404 Request not found
500 Internal server error
  • Register an occupation in the system

  • Payload

{
    "name":"Estagiário"
}
Status Code Description
201 Entity created successfully
400 Invalid request
  • Edit the selected record.

  • Payload

{
    "name":"Estagiário de Tecnologia"
}
Status Code Description
201 Entity updated successfully
400 Invalid request
404 Request not found
  • Deletes a selected record
Status Code Description
200 Request returned successfully
400 Invalid request
404 Request not found
500 Internal server error
Back to index](#index)