{
  "name": "MainWorkflow",
  "nodes": [
    {
      "parameters": {
        "url": "=https://data.xotelo.com/api/rates?hotel_key={{$json.xotelo_hotel_key}}&chk_in={{new Date().toISOString().slice(0, 10)}}&chk_out={{new Date(Date.now() + 86400000).toISOString().slice(0, 10)}}",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        440,
        0
      ],
      "id": "d7fe6e9f-b6d0-47b9-ab2f-bee916c730ab",
      "name": "HTTP Request"
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "SELECT * FROM hotels WHERE id != 1;",
        "options": {}
      },
      "type": "n8n-nodes-base.mySql",
      "typeVersion": 2.4,
      "position": [
        220,
        0
      ],
      "id": "064a0f02-203f-4953-92ab-ba79119b4f63",
      "name": "Get Hotels",
      "credentials": {
        "mySql": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "SELECT email FROM users WHERE id = {{ $('Get Wishlists').item.json.user_id }};",
        "options": {}
      },
      "type": "n8n-nodes-base.mySql",
      "typeVersion": 2.4,
      "position": [
        1300,
        0
      ],
      "id": "49e45592-b19b-401e-a110-64ebfb8b1968",
      "name": "Get Users",
      "credentials": {
        "mySql": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "fromEmail": "fortnitenotifier.moguism@gmail.com",
        "toEmail": "={{ $('Get Users').item.json.email }}",
        "subject": "Hay hoteles con descuento :D",
        "html": "=<p>Buenos d\u00edas, el siguiente hotel tiene un descuento, tal y como solicitaste:</p>\n<ul>\n<li><strong>{{ $('Get Hotels').item.json.name }}</strong>: {{ $('HTTP Request').item.json.result.rates[0].rate }}\u20ac</li>\n</ul>",
        "options": {}
      },
      "type": "n8n-nodes-base.emailSend",
      "typeVersion": 2.1,
      "position": [
        1540,
        0
      ],
      "id": "bf064405-b50e-47fb-a4c6-142a1e84b23e",
      "name": "Send Email",
      "credentials": {
        "smtp": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "SELECT id FROM hotel_services WHERE service_id = 1 AND hotel_id = {{ $('Get Hotels').item.json.id }};",
        "options": {}
      },
      "type": "n8n-nodes-base.mySql",
      "typeVersion": 2.4,
      "position": [
        640,
        0
      ],
      "id": "05976cdb-7085-4195-b726-dbb8bf0ea3bb",
      "name": "Get Hotel Services",
      "credentials": {
        "mySql": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "table": {
          "__rl": true,
          "value": "date_prices",
          "mode": "list",
          "cachedResultName": "date_prices"
        },
        "dataMode": "defineBelow",
        "valuesToSend": {
          "values": [
            {
              "column": "price",
              "value": "={{ $('HTTP Request').item.json.result.rates[0].rate}}"
            },
            {
              "column": "date",
              "value": "={{ $('HTTP Request').item.json.result.chk_in }}"
            },
            {
              "column": "hotel_service_id",
              "value": "={{ $('Get Hotel Services').item.json.id }}"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.mySql",
      "typeVersion": 2.4,
      "position": [
        840,
        -160
      ],
      "id": "f902f01a-d576-4175-a204-833402bec603",
      "name": "Insert Date Prices",
      "credentials": {
        "mySql": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "SELECT * FROM wishlists WHERE desired_price > '{{ $('HTTP Request').item.json.result.rates[0].rate }}' AND hotel_service_id IN (SELECT id FROM hotel_services WHERE hotel_id IN (SELECT id FROM hotels WHERE xotelo_hotel_key = '{{ $('Get Hotels').item.json.xotelo_hotel_key }}'));",
        "options": {}
      },
      "type": "n8n-nodes-base.mySql",
      "typeVersion": 2.4,
      "position": [
        1060,
        0
      ],
      "id": "600bcb40-2594-4acd-b1bb-316ddd1a39db",
      "name": "Get Wishlists",
      "credentials": {
        "mySql": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "rule": {
          "interval": [
            {}
          ]
        }
      },
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        20,
        0
      ],
      "id": "2402f1cb-aa33-4f11-a9f4-d20ba1858b14",
      "name": "Schedule Trigger"
    }
  ],
  "connections": {
    "HTTP Request": {
      "main": [
        [
          {
            "node": "Get Hotel Services",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Hotels": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Users": {
      "main": [
        [
          {
            "node": "Send Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send Email": {
      "main": [
        []
      ]
    },
    "Get Hotel Services": {
      "main": [
        [
          {
            "node": "Insert Date Prices",
            "type": "main",
            "index": 0
          },
          {
            "node": "Get Wishlists",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Insert Date Prices": {
      "main": [
        []
      ]
    },
    "Get Wishlists": {
      "main": [
        [
          {
            "node": "Get Users",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "Get Hotels",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "6dde4c48-b2f9-4c64-955d-a79e0e9d2a2d",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "id": "tTD1yIkmNVpuoHAU",
  "tags": []
}