{
  "name": "Lesson 2",
  "nodes": [
    {
      "parameters": {},
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        -544,
        432
      ],
      "id": "b7f382e2-ff74-4bb2-ac27-ae59f35e600a",
      "name": "When clicking ‘Execute workflow’"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "42e627ef-f6cc-48f3-a04a-25a2f38b72f3",
              "leftValue": "={{ $json.city }}",
              "rightValue": "=Alicante",
              "operator": {
                "type": "string",
                "operation": "equals",
                "name": "filter.operator.equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.filter",
      "typeVersion": 2.2,
      "position": [
        256,
        112
      ],
      "id": "43a56017-d622-4641-b36f-267bd0104f3e",
      "name": "Filter"
    },
    {
      "parameters": {},
      "type": "n8n-nodes-base.limit",
      "typeVersion": 1,
      "position": [
        256,
        272
      ],
      "id": "015bc0a2-c13c-40a3-a1b1-cb7cf2c769cf",
      "name": "Limit"
    },
    {
      "parameters": {
        "fieldToSplitOut": "orders",
        "options": {}
      },
      "type": "n8n-nodes-base.splitOut",
      "typeVersion": 1,
      "position": [
        256,
        736
      ],
      "id": "58d96470-1466-49cf-a6f8-94a6d5bf5d90",
      "name": "Split Out"
    },
    {
      "parameters": {
        "aggregate": "aggregateAllItemData",
        "destinationFieldName": "all_users",
        "options": {}
      },
      "type": "n8n-nodes-base.aggregate",
      "typeVersion": 1,
      "position": [
        256,
        592
      ],
      "id": "2cbb70c6-58c7-4699-8f8d-da88d677b438",
      "name": "Aggregate"
    },
    {
      "parameters": {
        "mode": "combine",
        "combineBy": "combineByPosition",
        "options": {}
      },
      "type": "n8n-nodes-base.merge",
      "typeVersion": 3.2,
      "position": [
        256,
        432
      ],
      "id": "f2002918-04b8-43b3-b047-5616acc73325",
      "name": "Merge"
    },
    {
      "parameters": {
        "jsCode": "const user = $json;\nuser.totalOrders = user.orders.reduce((a,b)=>a+b,0);\nreturn [{ json: user }];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        256,
        896
      ],
      "id": "1271d249-2a6e-4320-93ad-580d76b11ee2",
      "name": "Code in JavaScript"
    },
    {
      "parameters": {
        "jsCode": "return [\n  {\n    json: {\n      id: 1,\n      firstName: \"Nikita\",\n      lastName: \"Yefimov\",\n      phone: \"+34611111111\",\n      city: \"Alicante\",\n      orders: [120, 80, 40]\n    }\n  },\n  {\n    json: {\n      id: 2,\n      firstName: \"Maria\",\n      lastName: \"Gomez\",\n      phone: \"+34622222222\",\n      city: \"Elche\",\n      orders: [300, 50]\n    }\n  },\n  {\n    json: {\n      id: 3,\n      firstName: \"John\",\n      lastName: \"Smith\",\n      phone: \"+12025550111\",\n      city: \"New York\",\n      orders: []\n    }\n  },\n  {\n    json: {\n      id: 4,\n      firstName: \"Anna\",\n      lastName: \"Petrova\",\n      phone: \"+34633333333\",\n      city: \"Alicante\",\n      orders: [45]\n    }\n  },\n  {\n    json: {\n      id: 5,\n      firstName: \"Karl\",\n      lastName: \"Meyer\",\n      phone: \"+4989123456\",\n      city: \"Berlin\",\n      orders: [500, 200, 150]\n    }\n  }\n];\n"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -352,
        432
      ],
      "id": "f4dd069d-89b6-4428-9f80-b3122f2d5714",
      "name": "Users list"
    },
    {
      "parameters": {
        "jsCode": "return [\n  {\n    json: {\n      user: \"Nikita\",\n      orders: [\n        { id: \"A1\", amount: 120 },\n        { id: \"A2\", amount: 80 },\n        { id: \"A3\", amount: 40 }\n      ]\n    }\n  }\n];\n"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -352,
        816
      ],
      "id": "bc07a084-a2b0-41ef-aea1-9ae8e587069f",
      "name": "Code One User With Orders"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "1b6d643f-6149-4466-9538-726865a50da2",
              "name": "fullName",
              "value": "={{$json[\"firstName\"] + \" \" + $json[\"lastName\"]}}",
              "type": "string"
            },
            {
              "id": "daab7320-3c8a-45cf-a9cc-70c675f189b7",
              "name": "orderCount",
              "value": "={{$json[\"orders\"].length}}",
              "type": "number"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        256,
        -64
      ],
      "id": "59819bcd-e6c6-4f86-a307-1169bb257bc6",
      "name": "[SET] Edit Fields"
    },
    {
      "parameters": {
        "jsCode": "return [\n  {\n    json: {\n      id: 101,\n      fullName: \"Roberto Diaz\",\n      email: \"roberto@example.com\"\n    }\n  },\n  {\n    json: {\n      id: 102,\n      fullName: \"Jenny Park\",\n      email: \"jenny@example.com\"\n    }\n  }\n];\n"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -352,
        608
      ],
      "id": "ddc7680b-87ac-4796-941b-ed8f1a706aff",
      "name": "Extra Users"
    },
    {
      "parameters": {
        "content": "## Привет от Yefimov_AI\n\nНе забудь подписаться на Youtube и телеграм канал"
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -1760,
        4096
      ],
      "id": "86a7030e-289c-45ec-ae7b-8290b252632a",
      "name": "Sticky Note3"
    }
  ],
  "pinData": {},
  "connections": {
    "When clicking ‘Execute workflow’": {
      "main": [
        [
          {
            "node": "Users list",
            "type": "main",
            "index": 0
          },
          {
            "node": "Extra Users",
            "type": "main",
            "index": 0
          },
          {
            "node": "Code One User With Orders",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Users list": {
      "main": [
        [
          {
            "node": "[SET] Edit Fields",
            "type": "main",
            "index": 0
          },
          {
            "node": "Filter",
            "type": "main",
            "index": 0
          },
          {
            "node": "Limit",
            "type": "main",
            "index": 0
          },
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          },
          {
            "node": "Code in JavaScript",
            "type": "main",
            "index": 0
          },
          {
            "node": "Aggregate",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code One User With Orders": {
      "main": [
        [
          {
            "node": "Split Out",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extra Users": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 1
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "da8d0709-6185-4daf-9928-238657510724",
  "meta": {
    "instanceId": "7ef81a965bb52d3c42bd218dc22fb53205bba7e12a5fda73cdb321bee53a0ffc"
  },
  "id": "WN2oDRWbWO6GM5X4",
  "tags": [
    {
      "updatedAt": "2025-07-26T19:24:38.741Z",
      "createdAt": "2025-07-26T19:24:38.741Z",
      "id": "PhEU8XvMbDgCJtf7",
      "name": "yefimov_ai"
    }
  ]
}