Skip to content

erick-tmr/contracts-api

Repository files navigation

contracts-api

An API to handle contracts from home equity loans.

This is a proposed solution to this challenge.

Tools

This project uses Claudia.JS to deploy to AWS. Configure it and run the script npm run deploy to deploy or claudia create to deploy first time.

It is necessary to configure an env.json file to set the Lambdas environment variables. The only required variable is the "NODE_ENV" to route the database endpoint to the correct value.

URL

This project is live in https://479p120d33.execute-api.sa-east-1.amazonaws.com/latest/.

Specifications

This is a Restful API, so it follows it conventions for routes.

Endpoints

GET /users

curl -X GET \
  https://479p120d33.execute-api.sa-east-1.amazonaws.com/latest/users

Response format:

{
  "success": "bool",
  "resources": [
    {
      "id": "uuid",
      "firstName": "text",
      "lastName": "text",
      "cpf": "text",
      "email": "text",
      "montlyIncome": "number",
      "dateOfBirth": "timestamp",
      "maritalStatus": "text",
      "address": {
        "street": "text",
        "zipCode": "text",
        "city": "text",
        "state": "text",
        "country": "text"
      }
    }
  ],
  "count": "number"
}

POST /users

curl -X POST \
  https://479p120d33.execute-api.sa-east-1.amazonaws.com/latest/users \
  -H 'Content-Type: application/json' \
  -d '{
    "firstName": "text",
    "lastName": "text",
    "cpf": "text",
    "email": "text",
    "montlyIncome": "number",
    "dateOfBirth": "timestamp",
    "maritalStatus": "text",
    "address": {
      "street": "text",
      "zipCode": "text",
      "city": "text",
      "state": "text",
      "country": "text"
    }
  }'

Response format:

{
  "success": "bool",
  "resources": {
    "id": "uuid",
    "firstName": "text",
    "lastName": "text",
    "cpf": "text",
    "email": "text",
    "montlyIncome": "number",
    "dateOfBirth": "timestamp",
    "maritalStatus": "text",
    "address": {
      "street": "text",
      "zipCode": "text",
      "city": "text",
      "state": "text",
      "country": "text"
    }
  }
}

POST /users/:user_id/contracts

curl -X POST \
  https://479p120d33.execute-api.sa-east-1.amazonaws.com/latest/users/user_id/contracts \
  -H 'Content-Type: application/json' \
  -d '{
    "amount": "number"
  }'

Response format:

{
  "success": "bool",
  "resource": {
    "id": "uuid",
    "amount": "number",
    "status": "text",
    "userId": "uuid",
    "approvalState": "text",
    "userSnapshot": {
      "...ofTypeUser"
    }
  }
}

GET /users/:user_id/contracts

curl -X GET \
  https://479p120d33.execute-api.sa-east-1.amazonaws.com/latest/users/user_id/contracts

Response format:

{
  "success": "bool",
  "resources": [
    {
      "id": "uuid",
      "amount": "number",
      "status": "text",
      "userId": "uuid",
      "approvalState": "text",
      "userSnapshot": {
        "...ofTypeUser"
      }
    }
  ],
  "count": "number"
}

PUT /contracts/:contract_id

Possible approvalStates:

  • "approved"
  • "rejected"
curl -X PUT \
  https://479p120d33.execute-api.sa-east-1.amazonaws.com/latest/contracts/contract_id \
  -H 'Content-Type: application/json' \
  -d '{
    "amount": "number",
    "approvalState": "text"
  }'

Response format:

{
  "success": "bool",
  "resource": {
    "id": "uuid",
    "amount": "number",
    "status": "text",
    "userId": "uuid",
    "approvalState": "text",
    "userSnapshot": {
      "...ofTypeUser"
    }
  }
}

POST /contracts/:contract_id/documents

Possible types:

  • "cpf",
  • "cnh",
  • "proof_of_income",
  • "property_photo"
curl -X POST \
  https://479p120d33.execute-api.sa-east-1.amazonaws.com/latest/contracts/contract_id/documents \
  -H 'Content-Type: application/json' \
  -d '{
    "type": "text",
    "publicUrl": "text"
  }'

Response format:

{
  "success": "bool",
  "resource": {
    "id": "uuid",
    "type": "text",
    "publicUrl": "text",
    "contractId": "uuid"
  }
}

GET /contracts/:contract_id/documents

curl -X GET \
  https://479p120d33.execute-api.sa-east-1.amazonaws.com/latest/contracts/contract_id/documents

Response format:

{
  "success": "bool",
  "resources": [
    {
      "id": "uuid",
      "type": "text",
      "publicUrl": "text",
      "contractId": "uuid"
    }
  ],
  "count": "number"
}

Tests

This project uses Jest as its testing tool.

To run the entire test suite, run:

npm run test

License

Licensed under the MIT license, see the separate LICENSE file.

About

An API to handle contracts from home equity loans.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published