n8n-backend-workflow.json•8.66 kB
{
  "name": "Human Design Backend (Full)",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "human-design",
        "responseMode": "responseNode",
        "options": {}
      },
      "name": "Webhook - Main Entry",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [240, 300],
      "webhookId": "human-design-backend"
    },
    {
      "parameters": {
        "jsCode": "// Валидация входных данных\nconst { birthDate, birthTime, birthLocation } = $input.item.json;\n\nif (!birthDate || !birthTime || !birthLocation) {\n  return {\n    json: {\n      success: false,\n      error: 'Missing required fields: birthDate, birthTime, birthLocation',\n      code: 'VALIDATION_ERROR'\n    }\n  };\n}\n\n// Проверка формата даты\nif (!/^\\d{4}-\\d{2}-\\d{2}$/.test(birthDate)) {\n  return {\n    json: {\n      success: false,\n      error: 'Invalid date format. Use YYYY-MM-DD',\n      code: 'INVALID_DATE'\n    }\n  };\n}\n\n// Проверка формата времени\nif (!/^\\d{2}:\\d{2}$/.test(birthTime)) {\n  return {\n    json: {\n      success: false,\n      error: 'Invalid time format. Use HH:MM',\n      code: 'INVALID_TIME'\n    }\n  };\n}\n\nreturn {\n  json: {\n    success: true,\n    birthDate,\n    birthTime,\n    birthLocation\n  }\n};"
      },
      "name": "Validate Input",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [460, 300]
    },
    {
      "parameters": {
        "conditions": {
          "boolean": [
            {
              "value1": "={{ $json.success }}",
              "value2": true
            }
          ]
        }
      },
      "name": "Is Valid?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [680, 300]
    },
    {
      "parameters": {
        "url": "={{ $env.RAILWAY_API_URL || 'https://balanced-generosity-test.up.railway.app' }}/api/human-design",
        "authentication": "none",
        "sendBody": true,
        "method": "POST",
        "jsonParameters": true,
        "bodyParametersJson": "={\n  \"birthDate\": \"{{ $json.birthDate }}\",\n  \"birthTime\": \"{{ $json.birthTime }}\",\n  \"birthLocation\": \"{{ $json.birthLocation }}\"\n}",
        "options": {
          "timeout": 15000
        }
      },
      "name": "Calculate Swiss Ephemeris",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [900, 200],
      "notes": "Вызов Railway API с Swiss Ephemeris"
    },
    {
      "parameters": {
        "conditions": {
          "boolean": [
            {
              "value1": "={{ $json.success }}",
              "value2": true
            }
          ]
        }
      },
      "name": "Calculation Success?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [1120, 200]
    },
    {
      "parameters": {
        "jsCode": "// Обогащение данных для дальнейшей обработки\nconst hd = $input.item.json.data;\n\n// Определяем ключевые характеристики\nconst characteristics = {\n  type_name: hd.type.name,\n  type_ru: hd.type.ru_name,\n  strategy_ru: hd.strategy,\n  authority_name: hd.authority.name,\n  authority_ru: hd.authority.ru_name,\n  profile_number: hd.profile.number,\n  gates_count: hd.gates.length,\n  centers_count: hd.definedCenters.length,\n  defined_centers: hd.definedCenters.map(c => c.name),\n  prominent_gates: hd.gates.slice(0, 3).map(g => g.gate),\n  calculation_method: hd.calculationSource || 'Swiss Ephemeris'\n};\n\n// Добавляем расчетные характеристики\nconst allGateNumbers = hd.gates.map(g => g.gate);\n\nreturn {\n  json: {\n    ...hd,\n    characteristics,\n    summary: `Human Design карта: ${hd.type.ru_name}. Стратегия: ${hd.strategy}. Профиль: ${hd.profile.number}.`\n  }\n};"
      },
      "name": "Enrich Data",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [1340, 100]
    },
    {
      "parameters": {
        "jsCode": "// Функция для форматирования Human Design карты\nconst hd = $input.item.json;\n\nconst formatted = {\n  // Базовая информация\n  basic: {\n    type: `${hd.type.ru_name} (${hd.type.name})`,\n    strategy: hd.strategy,\n    authority: `${hd.authority.ru_name} (${hd.authority.name})`,\n    profile: hd.profile.number\n  },\n  \n  // Описание типа\n  type_info: {\n    name: hd.type.ru_name,\n    description: hd.type.description || '',\n    strategy: hd.strategy\n  },\n  \n  // Активные ворота (первые 5)\n  prominent_gates: hd.gates.slice(0, 5).map(g => ({\n    gate: g.gate,\n    planet: g.planet,\n    name: g.name || g.ru_name || 'Unknown',\n    line: g.line\n  })),\n  \n  // Определенные центры\n  defined_centers: hd.definedCenters.map(c => c.name),\n  \n  // Статистика\n  stats: {\n    total_gates: hd.gates.length,\n    defined_centers_count: hd.definedCenters.length,\n    open_centers_count: 9 - hd.definedCenters.length\n  },\n  \n  // Метод расчета\n  source: hd.calculationSource || 'Swiss Ephemeris'\n};\n\nreturn { json: formatted };"
      },
      "name": "Format Output",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [1560, 100]
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ $json }}"
      },
      "name": "Respond Success",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1,
      "position": [1780, 100]
    },
    {
      "parameters": {
        "jsCode": "// Обработка ошибок\nconst error = $input.item.json.error || 'Unknown error';\n\nreturn {\n  json: {\n    success: false,\n    error: error,\n    message: 'Failed to calculate Human Design',\n    timestamp: new Date().toISOString()\n  }\n};"
      },
      "name": "Format Error",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [1340, 300]
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ $json }}"
      },
      "name": "Respond Error",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1,
      "position": [1780, 300]
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ $json }}"
      },
      "name": "Respond Validation Error",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1,
      "position": [900, 300]
    }
  ],
  "connections": {
    "Webhook - Main Entry": {
      "main": [
        [
          {
            "node": "Validate Input",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Validate Input": {
      "main": [
        [
          {
            "node": "Is Valid?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Is Valid?": {
      "main": [
        [
          {
            "node": "Calculate Swiss Ephemeris",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Respond Validation Error",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Calculate Swiss Ephemeris": {
      "main": [
        [
          {
            "node": "Calculation Success?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Calculation Success?": {
      "main": [
        [
          {
            "node": "Enrich Data",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Format Error",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Enrich Data": {
      "main": [
        [
          {
            "node": "Format Output",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format Output": {
      "main": [
        [
          {
            "node": "Respond Success",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format Error": {
      "main": [
        [
          {
            "node": "Respond Error",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "staticData": null,
  "tags": [],
  "triggerCount": 1,
  "updatedAt": "2024-01-01T00:00:00.000Z",
  "versionId": "1"
}