Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Editor configuration, see https://editorconfig.org
root = true

[*]
charset = utf-8
indent_style = space
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true

[*.ts]
quote_type = single

[*.md]
max_line_length = off
trim_trailing_whitespace = false
14 changes: 8 additions & 6 deletions .env-example
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
PORT=3000
MONGO_USER=
MONGO_PASSWORD=
PORT=
API_KEY=
JWT_SECRET=

MONGO_INITDB_ROOT_USERNAME=
MONGO_INITDB_ROOT_PASSWORD=
MONGO_DB=
MONGO_HOST=
MONGO_DB_NAME=
MONGO_PORT=
MONGO_CONNECTION=
MONGO_CONNECTION=
24 changes: 24 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
sourceType: 'module',
},
plugins: ['@typescript-eslint/eslint-plugin'],
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
],
root: true,
env: {
node: true,
jest: true,
},
ignorePatterns: ['.eslintrc.js'],
rules: {
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-explicit-any': 'off',
},
};
23 changes: 23 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,26 @@ typings/

# next.js build output
.next

# compiled output
/dist

# OS
.DS_Store

# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace
/mongo_data

# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
40 changes: 40 additions & 0 deletions .gitignore copy
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# compiled output
/dist
/node_modules

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# OS
.DS_Store

# Tests
/coverage
/.nyc_output

# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace

# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json

# Enviroments
*.env

# Mongo data
/mongo_data
4 changes: 4 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"singleQuote": true,
"trailingComma": "all"
}
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: npm run start:prod
110 changes: 72 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,65 +1,99 @@
# Prueba de Backend NodeJS
Crear un CRUD para crear productos conectado a MongoDB.
# Backend App
Create a CRUD to create products connected to MongoDB.

### Instalación
## App Deploy Heroku
[Heroku link](https://fast-everglades-22989.herokuapp.com/docs/#/)

## Build

* Copy the sample configuration file and fill the right values according to your environment

```bash

# develop
cp .env-example .env

# staging
cp .env-sample .stag.env

# production
cp .env-sample .prod.env
```
npm install

## Installation

```bash
$ npm install
```

### Ejecución
## Running the app

```bash
# development
$ npm run start

# watch mode
$ npm run start:dev

# production mode
$ npm run start:prod
```
npm run start

## Build the app

```bash
$ npm run build
```

## Modelos
## Models

### Product
Un Producto debe tener los siguientes atributos:
A Product must have the following attributes:
- name
- price
- description
- stock
- categoryId
- image

### Category
Una Categoría debe tener los siguientes atributos:
A Category must have the following attributes:
- name
- image

## Requerimientos
## Requirements

### CRUD de productos
- [ ] GET `/api/products/` Endpoint para retornar la lista de productos.
- [ ] GET `/api/products/{id}/` Endpoint para retornar un producto.
- [ ] POST `/api/products/` Endpoint para crear un producto.
- [ ] PUT `/api/products/{id}/` Endpoint para modificar un producto.
- [ ] DELETE `/api/products/{id}/` Endpoint para eliminar un producto.
### CRUD of products
- [ ] GET `/api/products/` Endpoint to return list of products.
- [ ] GET `/api/products/{id}/` Endpoint to return a product.
- [ ] POST `/api/products/` Endpoint to create a product.
- [ ] PUT `/api/products/{id}/` Endpoint to modify a product.
- [ ] DELETE `/api/products/{id}/` Endpoint to delete a product.

### CRUD de categorías
- [ ] GET `/api/categories/` Endpoint para retornar la lista de categorías.
- [ ] GET `/api/categories/{id}/` Endpoint para retornar un categoría.
- [ ] POST `/api/categories/` Endpoint para crear un categoría.
- [ ] PUT `/api/categories/{id}/` Endpoint para modificar un categoría.
- [ ] DELETE `/api/categories/{id}/` Endpoint para eliminar un categoría.
- [ ] GET `/api/categories/{id}/products` Endpoint para retornar la lista de productos que pertenecen a una categoría.
### CRUD of categories
- [ ] GET `/api/categories/` Endpoint to return list of categories.
- [ ] GET `/api/categories/{id}/` Endpoint to return a category.
- [ ] POST `/api/categories/` Endpoint to create a category.
- [ ] PUT `/api/categories/{id}/` Endpoint to modify a category.
- [ ] DELETE `/api/categories/{id}/` Endpoint to delete a category.
- [ ] GET `/api/categories/{id}/products` Endpoint to return the list of products belonging to a category.

## Instrucciones
## Test

1. Utilizando el archivo `.env-example` realiza la configuración para tu archivo `.env`.
2. Proponer una arquitectura la aplicación.
3. Verificar que la conexión de tu aplicación a MongoDBAtlas funcione.
4. Realizar el deploy de tu aplicación.
```bash
# unit tests
$ npm run test

### Correr pruebas en local
```
npm run test:e2e
```
1. Debes tener mongoDB en local corriendo para hacer las pruebas.
2. Y poner las variables de ambiente en el archivo `.env`.
# e2e tests
$ npm run test:e2e

# test coverage
$ npm run test:cov
```

## Enviar solución de reto
Debes de crear un "Fork" de este proyecto, revolverlo desde tu cuenta personal.
## Evidence
* Local enviromente
![alt backend-api](/docs/images/api.png)

### Licencia
La licencia [MIT](https://opensource.org/licenses/MIT).
* Production enviromente
![alt backend-api](/docs/images/heroku.png)
4 changes: 3 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ services:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: root
ports:
- 27017:27017
- 27017:27017
volumes:
- ./mongo_data:/data/db
Binary file added docs/images/api.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/heroku.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions nest-cli.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"collection": "@nestjs/schematics",
"sourceRoot": "src",
"compilerOptions": {
"plugins": ["@nestjs/swagger"]
}
}
Loading