Skip to content

EduDevHe/challenge-nestJs-postgresql

Repository files navigation

Nest Logo PostgreSql Logo

Challenge NestJS and PostgreSQL

NPM Version Package License

Description

Challenge of building an API using nestjs Nest framework TypeScript and PostgreSql.

Clone

https://github.com/EduDevHe/challenge-nestJs-postgresql.git

Running the app 🚀

# development
$ pnpm run start

# watch mode
$ pnpm run start:dev

# production mode
$ pnpm run start:prod

Docker 🐳

docker-compose up --build

API docs 📚

Get place by id in API

Url example

http://localhost:3000/place/1

Method GET

Return

    {
        "id": 1,
        "name": "rio",
        "state": "bahia",
        "city": "barreiras",
        "createdAt": "2024-01-11T00:28:03.143Z",
        "updatedAt": "2024-01-11T00:28:03.143Z"
    }

Get all places in api

Url example

	http://localhost:3000/place/all

Method GET

Return

[
	{
		"id": 1,
		"name": "rio",
		"state": "bahia",
		"city": "barreiras",
		"createdAt": "2024-01-11T00:28:03.143Z",
		"updatedAt": "2024-01-11T00:28:03.143Z"
	},
	{
		"id": 2,
		"name": "cais",
		"state": "bahia",
		"city": "barreiras",
		"createdAt": "2024-01-11T00:28:19.339Z",
		"updatedAt": "2024-01-11T00:28:19.339Z"
	},
	{
		"id": 3,
		"name": "centro",
		"state": "bahia",
		"city": "barreiras",
		"createdAt": "2024-01-11T00:28:10.101Z",
		"updatedAt": "2024-01-11T01:31:58.283Z"
	}
]

Search places in API

Url example

http://localhost:3000/place?name=barreirinhas
http://localhost:3000/place?name=barreirinhas&state=bahia

Method GET

Return

[
	{
		"id": 5,
		"name": "barreirinhas",
		"state": "bahia",
		"city": "barreiras",
		"createdAt": "2024-01-11T00:28:03.143Z",
		"updatedAt": "2024-01-11T00:28:03.143Z"
	}
]

Create a place in the api

Url example

http://localhost:3000/place/create

Method POST

Header example

method: 'GET',
headers: {
    'Authorization': `Bearer ${token}`,
  },

Body

{
"name":"centro",
"city":"barreiras",
"state":"bahia"
}

Return

{
	"message": "Place created successfully",
	"place": {
		"id": 8,
		"name": "centro",
		"state": "bahia",
		"city": "barreiras",
		"createdAt": "2024-01-11T03:10:31.861Z",
		"updatedAt": "2024-01-11T03:10:31.861Z"
	}
}

Delete a place by id in the API

You need to be authenticated with a valid jwt token

Url example

http://localhost:3000/place/8

Method DELETE

Header example

method: 'DELETE',
headers: {
    'Authorization': `Bearer ${token}`,
  },

Return

{
	"message": "Deleted place",
	"place": {
		"id": 8,
		"name": "centro",
		"state": "bahia",
		"city": "barreiras",
		"createdAt": "2024-01-11T03:10:31.861Z",
		"updatedAt": "2024-01-11T03:10:31.861Z"
	}
}

Upadate a place by id in the API

You need to be authenticated with a valid jwt token

Example

http://localhost:3000/place/7

Method PATCH

Header example

method: 'PATCH',
headers: {
    'Authorization': `Bearer ${token}`,
  },

Body

{
"name":"centro"
}

Return

{
	"message": "Updated place",
	"place": {
		"id": 7,
		"name": "centro",
		"state": "bahia",
		"city": "barreiras",
		"createdAt": "2024-01-11T00:28:19.339Z",
		"updatedAt": "2024-01-11T04:18:01.780Z"
	}
}

Create a user in the API

Url example

http://localhost:3000/auth/register

Method POST

Body

{
	"username":"test",
	"email": "[email protected]",
	"password": "12345"
}

Return

{
	"message": "User created successfully",
	"username": "test",
	"email": "[email protected]",
	"createdAt": "2024-01-11T03:27:02.702Z"
}

Login

Url example

http://localhost:3000/auth/login

Method POST

Body

{
	"email": "[email protected]",
	"password": "12345"

}

Return

{
	"message": "login successfully",
	"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6InRlc3QiLCJzdWIiOjUsImlhdCI6MTcwNDk0MzY1MSwiZXhwIjoxNzA0OTQ3MjUxfQ.Wa3lx6HUv6x5h90HBpb1DdF6ivHa8Ohybgr_ycekNHw",
	"login": true
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published