backend-api with CRUD operations to make a request. In order to retrieve/get/create/update/delete JWT is required. (Authorization: Bearer {token} attached to the headers). API provides endpoints for registration and token retrieval (access token). With this access token, the user can access data related to the database through the API because the user is authenticated.
- NestJS + MongoDB + Mongoose + Jest
- WebStorm, Swagger
Register User
Register new user.
- Method:
POST - URL:
/auth/register - Body:
{
"username": "string",
"email": "string",
"password": "string"
}- Status Code:
201 Created - Response Format: JSON
{
"token": "string"
}Login
Login user.
- Method:
POST - URL:
/auth/login - Body:
{
"email": "string",
"password": "string"
}- Status Code:
200 OK - Response Format: JSON
{
"token": "string"
}Get User Profle
Get user profile.
- Method:
GET - URL:
/auth/profile - Headers:
Authorization: Bearer {token}
- Status Code:
200 OK - Response Format: JSON
{
"message": "string",
"code": "string",
"data": [
{
"name": "string",
"gender": "string",
"birthday": "string",
"horoscope": "string",
"zodiac": "string",
"height": "string",
"weight": "string",
"interest": ["string"]
}
]
}Create User Profle
Create user profile.
- Method:
POST - URL:
/auth/profile - Headers:
Authorization: Bearer {token}
- Body:
{
"name": "string",
"gender": "string",
"birthday": "string",
"height": "string",
"weight": "string",
"interest": ["string"]
}- Status Code:
201 Created - Response Format: JSON
{
"message": "string",
"code": "string",
"data": [
{
"name": "string",
"gender": "string",
"birthday": "string",
"horoscope": "string",
"zodiac": "string",
"height": "string",
"weight": "string",
"interest": ["string"]
}
]
}Update User Profle
Update user profile.
- Method:
PUT - URL:
/auth/profile - Headers:
Authorization: Bearer {token}
- Body:
{
"name": "string",
"gender": "string",
"birthday": "string",
"height": "string",
"weight": "string",
"interest": ["string"]
}- Status Code:
200 OK - Response Format: JSON
{
"message": "string",
"code": "string",
"data": [
{
"name": "string",
"gender": "string",
"birthday": "string",
"horoscope": "string",
"zodiac": "string",
"height": "string",
"weight": "string",
"interest": ["string"]
}
]
}Unit test and end to end test using Jest. Go to e2e test.
- Register a new user
- Login user
- Not accept invalid email
- Not register duplicate email
- Not login (not register yet)
- Create new profile
- Get data profile
- Update data profile
- Unauthorized in create profile
- Unauthorized in update profile
- Unauthorized in get profile
- Not accept invalid birthday
git clone git@github.com:rizki-nm/nestjs-mongodb.git$ pnpm install# development
$ pnpm run start
# watch mode
$ pnpm run start:dev
# production mode
$ pnpm run start:prod# unit tests
$ pnpm run test
# e2e tests
$ pnpm run test:e2e
# test coverage
$ pnpm run test:cov
