Skip to content
This repository has been archived by the owner on Jun 6, 2019. It is now read-only.

Latest commit

 

History

History

api

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Arquiyalt Api

Table Of Contents

Development

Clone the repo and cd to api directory

yarn
yarn dev

Environment variables

variable default use
PORT 3000 port in which api will listen for requests
MONGO mongodb://127.0.0.1:27017/IIC2173-Arqui mongodb uri
MONGO_TEST mongodb://127.0.0.1:27017/IIC2173-Arqui-test mongodb uri for running tests
API_MAILER_SECRET apimailersecret certify that the mailer bot is the source of the request for security reasons
API_QUEUE_SECRET apiqueuesecret certify that the order queue is the source of the request for security reasons
API_TELEGRAM_SECRET apitelegramsecret secret key shared between api and telegram
MAILER_URI http://localhost:3001 specifies Mailer's connection's host and port
QUEUE_URI http://localhost:3002 specifies Queue's connection's host and port
API_URI http://localhost:3000 specifies Api's connection's host and port
ARQUITRAN_URI http://arqss17.ing.puc.cl:3000 specifies Arquitran API's connection's host and port
MAX_REQUEST_ATTEMPTS 2 defines how many times the API tries to receive an OK status from Arquitran API
MAX_REQUEST_TIMEOUT 200 defines how long the API waits to receive an OK status from Arquitran API since each request was made
SETTING_CACHE_TIMEOUT 30000 defines how long the API waits to set cache (products or categories) since its last update
PAGE_SIZE 20 defines how many products are sent per page on cache obtained queries.

Api usage

Accounts

Sign up

  • Route: POST /signup

  • Headers:

    • Content-Type: application/json
  • Example Body:

    {
      "firstName": "Franco",
      "lastName": "Méndez",
      "mail": "[email protected]",
      "address": "Louis Pasteur 5418, Vitacura"
      "password": "123456"
    }
  • Success Response:

    • Status: 201

    • Content:

      { "token": "arquiyalt-token" }
  • Error Response:

    • Code: 406

    • Content:

      { "message": "error-message" }

Login

  • Route: POST /login

  • Headers:

    • Content-Type: application/json
  • Example Body:

    {
      "mail": "[email protected]",
      "password": "123456"
    }
  • Success Response:

    • Status: 200

    • Content:

      { "token": "arquiyalt-token" }
  • Error Response:

    • Code: 403

    • Content:

      { "message": "Invalid credentials." }

Products

One product

  • Route: GET /products/:id

  • Headers:

    • Content-Type: application/json

    • Authorization: type <value> (only required for some products)

      → Examples

  • Success Response:

    • Status: 200

    • Example Content:

      {
          "source": "cache",
          "updatedAt": "2017-10-12T17:12:45.359Z",
          "product": {
              "id": 10,
              "category": 10,
              "name": "Paracetamol"
          }
      }
  • Error Response:

    → If the user isn't authenticated

    • Code: 403

    • Content:

      { message: 'The information of this product is private.' }

    → Other error

    • Code: 503

    • Content:

      { "message": "Couldn't resolve request to Arquitran API." }

  • Route: GET /products/search

  • Headers:

    • Content-Type: application/json

    • Authorization: always required to search

      → Examples

      • Authorization: token 19ab28cd37ef46
  • Success Response:

    • Status: 200

    • Example Content:

      {
          "products": [{
              "id": 10,
              "category": 10,
              "name": "Paracetamol",
              "price": 100}
          ]
          "totalPages": 1
      }
  • Error Response:

    → If the user isn't authenticated

    • Code: 403

    • Content:

      { message: 'The information of this product is private.' }

    → Database error

    • Code: 503

    • Content:

      { "message": "Query failed to execute." }

    → No results error error

    • Code: 402

    • Content:

      { "message": "Query has no results." }

All Products

  • Route: GET /products?page=<page_number>

  • Headers:

    • Content-Type: application/json

    • Authorization: type <value> (optional)

      → Examples

  • Query Strings:

    • page: int, page number. If ommited sends all products.
  • Success Response:

    • Status: 200

    • Example Content:

      {
      "source": "api",
      "products": [
          {
              "id": 10,
              "category": 10,
              "name": "Paracetamol"
          },
          {
              "id": 20,
              "category": 10,
              "name": "Dimetilamina"
          },
          {
              "id": 30,
              "category": 11,
              "name": "Ibuprofeno"
          }
        ]
      }
  • Error Response:

    • Code: 503

    • Content:

      { "message": "Couldn't resolve request to Arquitran API." }

Categories

One category

  • Route: GET /categories/:id

  • Headers:

    • Content-Type: application/json

    • Authorization: type <value> (only needed for some categories)

      → Examples

  • Success Response:

    • Status: 200

    • Example Content:

      {
          "source": "api",
          "category":
            {
                "id": 10,
                "context": "MEDICAMENTOS",
                "area": "ANALGESICO",
                "group": "Aminas"
            }
      }
  • Error Response:

    → If the user isn't authenticated

    • Code: 403

    • Content:

      { message: 'The information of this category is private.' }

    → Other error

    • Code: 503

    • Content:

      { "message": "Couldn't resolve request to Arquitran API." }

All categories

  • Route: GET /categories

  • Headers:

    • Content-Type: application/json

    • Authorization: type <value> (optional)

      → Examples

  • Success Response:

    • Status: 200

    • Example Content:

      {
          "source": "api",
          "categories": [
              {
                  "id": 10,
                  "context": "MEDICAMENTOS",
                  "area": "ANALGESICO",
                  "group": "Aminas"
              },
              {
                  "id": 11,
                  "context": "MEDICAMENTOS",
                  "area": "ANALGESICO",
                  "group": "AINES"
              },
              {
                  "id": 15,
                  "context": "MEDICAMENTOS",
                  "area": "ANALGESICO",
                  "group": "Cannabinoides"
              },
          ]
      }
  • Error Response:

    • Code: 503

    • Content:

      { "message": "Couldn't resolve request to Arquitran API." }

One category with nested products

  • Route: GET /categories/:id/products

  • Headers:

    • Content-Type: application/json

    • Authorization: type <value> (only required for some categories)

      → Examples

  • Success Response:

    • Status: 200

    • Example Content:

      {
          "source": "cache",
          "updatedAt": "2017-10-12T00:25:28.373Z",
          "category": {
              "id": 11,
              "context": "MEDICAMENTOS",
              "area": "ANALGESICO",
              "group": "AINES",
              "products": [
                  {
                      "name": "Ibuprofeno",
                      "category": 11,
                      "id": 30
                  },
                  {
                      "name": "Naproxen",
                      "category": 11,
                      "id": 40
                  }
              ]
          }
      }
  • Error Response:

    → If the user isn't authenticated

    • Code: 403

    • Content:

      { message: 'The information of this category is private.' }

    → Other error

    • Code: 503

    • Content:

      { "message": "Couldn't resolve request to Arquitran API." }

All categories with nested products

  • Route: GET /categories/products

  • Headers:

    • Content-Type: application/json

    • Authorization: type <value> (optional)

      → Examples

  • Success Response:

    • Status: 200

    • Example Content:

      {
          "source": "api",
          "categories": [
              {
                  "id": 111,
                  "context": "BELLEZA",
                  "area": "PRESENTACIÓN",
                  "group": "Desodrante de hombre",
                  "products": [
                      {
                          "id": 1042,
                          "category": 111,
                          "name": "OldSpice"
                      },
                      {
                          "id": 1045,
                          "category": 111,
                          "name": "AXE"
                      },
                      {
                          "id": 1072,
                          "category": 111,
                          "name": "Desodrante Nieve"
                      }
                  ]
              },
              {
                  "id": 112,
                  "context": "BELLEZA",
                  "area": "PRESENTACIÓN",
                  "group": "Desodrante de mujer",
                  "products": [
                      {
                          "id": 1067,
                          "category": 112,
                          "name": "Citric"
                      },
                      {
                          "id": 1073,
                          "category": 112,
                          "name": "Desodrante Nieve"
                      }
                  ]
              },
              {
                  "id": 114,
                  "context": "BELLEZA",
                  "area": "PRESENTACIÓN",
                  "group": "Desodrante ambiental",
                  "products": []
              },
              {
                  "id": 141,
                  "context": "BELLEZA",
                  "area": "PRESENTACIÓN",
                  "group": "Perfume de hombre",
                  "products": []
              },
          ]
      }
  • Error Response:

    • Code: 503

    • Content:

      { "message": "Couldn't resolve request to Arquitran API." }

Orders

Make an order

  • Route: POST /orders

  • Headers:

    • Content-Type: application/json
    • Authorization: type <value>
    • Secret: <secret> (only through email)
      • Example through web
        • Authorization: token 19ab28cd37ef46
      • Example through email
  • Example Body:

    {
      "productsIds": "[10, 105, 1042, 1045]"
    }
  • Success Response:

    • Status: 200

    • Content:

      { "message": "The order has been received." }
  • Error Response:

    • Code: 503

    • Content:

      { "message": "Couldn't resolve the request." }

Confirm an order

  • Route: GET /orders/:token

  • Headers:

    • Content-Type: application/json
    • Authorization: type <value>
    • Secret: <secret> (only through email)
      • Example through web
        • Authorization: token 19ab28cd37ef46
      • Example through email
  • Success Response:

    • Status: 200

    • Content:

      { "message": "The order confirmation was successful." }
  • Error Response:

    • Code: 503

    • Content:

      { "message": "Couldn't process the order confirmation." }

Validate an order

  • Route: POST /orders/resolved

  • Headers:

    • Content-Type: application/json
    • Secret: <secret>
      • Example
        • Secret: apiqueuesecret
  • Example Body:

    {
      "userId": "12abc345edf",
      "productId": "1042",
      "sentAt": "2017-10-16T22:13:31.343Z"
    }
  • Success Response:

    • Status: 200

    • Content:

      { "message": "The validation has been processed." }
  • Error Response:

    • Code: 503

    • Content:

      { "message": "Couldn't process the validation." }

Order history

  • Route: GET /orders?sort=<sorting_order>

  • Headers:

    • Content-Type: application/json

    • Secret: <secret> (only through email)

    • Authorization: type <value> (optional)

      → Examples

  • Query Strings:

    • sort: asc or desc
  • Success Response:

    • Status: 200

    • Example Content:

      {
      "orders": [
          {
              "completed":true,
              "productId": 20,
              "productName": "Dimetilamina",
              "sentAt": "2017-11-05T21:57:18.271Z",
          },
          {
              "completed":true,
              "productId": 10,
              "productName": "Paracetamol",
              "sentAt": "2017-11-05T21:22:34.680Z",
          }]
        }

Contributors: