jsrdriguez / app-nodejs-codechallenge

Code challenge for potential Yaperos :rocket:

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Yape Code Challenge - Jesus Rodriguez

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

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

Problem

Every time a financial transaction is created it must be validated by our anti-fraud microservice and then the same service sends a message back to update the transaction status. For now, we have only three transaction statuses:

  1. pending
  2. approved
  3. rejected

Every transaction with a value greater than 1000 should be rejected.

  flowchart LR
    Transaction -- Save Transaction with pending Status --> transactionDatabase[(Database)]
    Transaction --Send transaction Created event--> Anti-Fraud
    Anti-Fraud -- Send transaction Status Approved event--> Transaction
    Anti-Fraud -- Send transaction Status Rejected event--> Transaction
    Transaction -- Update transaction Status event--> transactionDatabase[(Database)]
Loading

Tech Stack

  1. Node. You can use any framework you want (i.e. Nestjs with an ORM like TypeOrm or Prisma)
  2. Any database
  3. Kafka

We do provide a Dockerfile to help you get started with a dev environment.

You must have two resources:

  1. Resource to create a transaction that must containt:
{
  "accountExternalIdDebit": "Guid",
  "accountExternalIdCredit": "Guid",
  "tranferTypeId": 1,
  "value": 120
}
  1. Resource to retrieve a transaction
{
  "transactionExternalId": "Guid",
  "transactionType": {
    "name": ""
  },
  "transactionStatus": {
    "name": ""
  },
  "value": 120,
  "createdAt": "Date"
}

Optional

You can use any approach to store transaction data but you should consider that we may deal with high volume scenarios where we have a huge amount of writes and reads for the same data at the same time. How would you tackle this requirement?

You can use Graphql;

Send us your challenge

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

  • Clone the project.
  • Copy .env.example to .env. It will be used as environment variables source.

Run docker-compose command inside folder.

  • Building the containers: docker-compose build

  • Starting the services: docker-compose up -d

  • Stoping the services: docker-compose stop

By default the api will run under the following port:

You must have three resources:

  1. Resource to create a transaction:
mutation Mutation($input: TransactionInput) {
  createTransaction(input: $input) {
    code
    message
    success
  }
}
{
  "input": {
    "accountExternalIdCredit": "b511ddbe-6a5b-4c31-8db8-a8e8237bd44b",
    "accountExternalIdDebit": "da24cfb3-71e3-49b4-b408-e85d53c2a5c3",
    "tranferTypeId": 1,
    "value": 500
  }
}
  1. Search a transaction:
query SearchTransaction($transactionId: GUID!) {
  searchTransaction(transactionId: $transactionId) {
    message
    success
    code
    result {
      transactionExternalId
      tranferTypeId
      status
      value
      createdAt
    }
  }
}
{
  "transactionId": "1a920c5c-56ed-4a17-b0cc-cb7a5b2e1091"
}
  1. Get all transactions, limited per ten rows (Optional):
query AllTransaction {
  allTransaction {
    transactionExternalId
    tranferTypeId
    status
    value
    createdAt
  }
}

About

Code challenge for potential Yaperos :rocket:


Languages

Language:TypeScript 96.6%Language:Dockerfile 3.4%