Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solution Challenge by Jakeline Campos #441

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
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
7 changes: 7 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
node_modules
dist
.git
.gitignore
Dockerfile
docker-compose.yml
*.md
6 changes: 6 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
DB_TYPE=postgres
DB_HOST=localhost
DB_PORT=
DB_USER=
DB_PASSWORD=
DB_NAME=
25 changes: 25 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
tsconfigRootDir: __dirname,
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',
},
};
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"
}
20 changes: 20 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Usar la imagen oficial de Node.js 20
FROM node:20

# Establecer el directorio de trabajo dentro del contenedor
WORKDIR /app

# Copiar package.json y yarn.lock
COPY package.json yarn.lock ./

# Instalar las dependencias
RUN yarn install

# Copiar el resto de los archivos del proyecto
COPY . .

# Exponer el puerto 3000
EXPOSE 3000

# Comando para ejecutar la aplicación
CMD ["yarn", "run", "start:prod"]
267 changes: 264 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,30 @@
# Yape Code Challenge :rocket:

Our code challenge will let you marvel us with your Jedi coding skills :smile:.
Our code challenge will let you marvel us with your Jedi coding skills :smile:.

Don't forget that the proper way to submit your work is to fork the repo and create a PR :wink: ... have fun !!

- [Yape Code Challenge :rocket:](#yape-code-challenge-rocket)
- [Problem](#problem)
- [Tech Stack](#tech_stack)
- [Send us your challenge](#send_us_your_challenge)
- [Tech Stack](#tech-stack)
- [Optional](#optional)
- [Send us your challenge](#send-us-your-challenge)
- [Solution Challenge](#solution-challenge)
- [Instructions for compile](#instructions-for-compile)
- [1. Installation](#1-installation)
- [2. Config .env](#2-config-env)
- [3. Run containers in the background](#3-run-containers-in-the-background)
- [4. Run project](#4-run-project)
- [5. Check swagger documentation in http://localhost:3000/api](#5-check-swagger-documentation-in-httplocalhost3000api)
- [6. Check graphql documentation in http://localhost:3000/graphql](#6-check-graphql-documentation-in-httplocalhost3000graphql)
- [Troubleshooting](#troubleshooting)
- [ Postman: Colección y Entornos](#-postman-colección-y-entornos)
- [Ubicación de los archivos](#ubicación-de-los-archivos)
- [GraphQL API Usage](#graphql-api-usage)
- [Crear transacción](#crear-transacción)
- [Actualizar una transacción](#actualizar-una-transacción)
- [Obtener una transacción por id](#obtener-una-transacción-por-id)
- [Obtener transacciones con paginación y filtros](#obtener-transacciones-con-paginación-y-filtros)

# Problem

@@ -80,3 +98,246 @@ You can use Graphql;
When you finish your challenge, after forking a repository, you **must** open a pull request to our repository. There are no limitations to the implementation, you can follow the programming paradigm, modularization, and style that you feel is the most appropriate solution.

If you have any questions, please let us know.

# Solution Challenge

## Instructions for compile

### 1. Installation

```bash
$ yarn install
```

A default option and an alternative option (option 2) are presented, choose the one that suits you best.

- Default option: Default option: Dockerize services and project run outside of docker
- Alternative option (option 2): Dockerize entire project

### 2. Config .env

Create a .env file in the root of the project and place all the keys that appear in it .env.example and complete theys values

```
# docker-compose.yml
DB_TYPE=postgres
DB_HOST=localhost
DB_PORT=
DB_USER=
DB_PASSWORD=
DB_NAME=
```

or

option 2: Dockerize the entire project (In DB_HOST use name service of databse when dockerize entire project)

```
# docker-compose.dev.yml
DB_TYPE=postgres
DB_HOST=postgres
DB_PORT=
DB_USER=
DB_PASSWORD=
DB_NAME=
```

### 3. Run containers in the background

```bash
$ docker-compose -f docker-compose.yml up -d
```

or option 2: use docker-compose.dev.yml to dockerize the entire project

```bash
$ docker-compose -f docker-compose.dev.yml up -d
```

### 4. Run project

```bash
# development
$ yarn run start

# watch mode
$ yarn run start:dev

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

### 5. Check swagger documentation in http://localhost:3000/api

### 6. Check graphql documentation in http://localhost:3000/graphql

## Troubleshooting

If you had this message when trying to launch the project with step 4

```
ERROR [TypeOrmModule] Unable to connect to the database. Retrying (2)...
error: ������������ "admin" �� ������ �������� ����������� (�� ������)
at Parser.parseErrorMessage
```

Make sure you don't have any resource conflicts.
Solve fix: Please uninstall postgress if you have it installed on your PC and cannot resolve the resource conflict.

```bash
$ psql --version
```

If installed, you will see something like:

```scss
psql (PostgreSQL) 14.4
```

Check if it is active:

```bash
$ service postgresql status
```

Check ports:

```bash
$ netstat -an | grep 5432
```

More info about fix, check: https://stackoverflow.com/questions/73906739/nestjs-app-cant-connect-to-postgresql-docker-container

## [![Postman](https://img.shields.io/badge/Postman-F38020.svg?logo=postman&logoColor=white)](#) Postman: Colección y Entornos

### Ubicación de los archivos

- **Colección y variables de entorno Postman**: [postman/](./postman/)

## GraphQL API Usage

Este proyecto expone un API GraphQL. A continuación, se muestran ejemplos de queries y mutaciones que puedes utilizar.
http://localhost:3000/graphql

### Crear transacción

```graphql
mutation createTransaction($inputCreate: CreateTransactionDTO!) {
createTransaction(input: $inputCreate) {
createdAt
transactionExternalId
transactionType {
name
}
transactionStatus {
name
}
value
}
}
```

Variables:

```json
{
"inputCreate": {
"accountExternalIdDebit": "32a1c938-4882-4dcd-9746-f57d9c96b3db",
"accountExternalIdCredit": "4444c938-4882-4dcd-9746-f57d9c96b3db",
"transferTypeId": "BANK_TRANSFER",
"value": 100.5
}
}
```

### Actualizar una transacción

```graphql
mutation patchTransaction($id: String!, $inputPatch: PatchTransactionDTO!) {
patchTransaction(id: $id, input: $inputPatch) {
createdAt
transactionExternalId
transactionType {
name
}
transactionStatus {
name
}
value
}
}
```

Variables:
Reemplazar el valor de id por un el transactionExternalId que retorne la query createTransaction()

```json
{
"id": "f86157d5-6ef2-49f1-b2ba-be490655673d",
"inputPatch": {
"transactionStatus": "APPROVED"
}
}
```

### Obtener una transacción por id

```graphql
query getTransaction($id: String!) {
getTransaction(id: $id) {
transactionExternalId
transactionType {
name
}
transactionStatus {
name
}
value
createdAt
}
}
```

Variables:

```grapql
{
"id":"f86157d5-6ef2-49f1-b2ba-be490655673d"
}
```

### Obtener transacciones con paginación y filtros

```graphql
query getTransactions($inputFilter: GetTransactionsInputDTO) {
getTransactions(input: $inputFilter) {
limit
page
totalCount
data {
transactionExternalId
transactionType {
name
}
transactionStatus {
name
}
value
}
}
}
```

Variables:

```grapql
{
"inputFilter":{
"offset": 0,
"limit": 5,
"filters": {
"transactionStatus": "APPROVED"
}
}
}
```
Loading