{
  "name": "Conrad | Document collection | Demonstration",
  "nodes": [
    {
      "id": "document-chase-manual",
      "name": "Run the local example",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        0,
        240
      ],
      "parameters": {}
    },
    {
      "id": "document-chase-1",
      "name": "Load example document metadata",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        280,
        240
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "language": "javaScript",
        "jsCode": "return [{ json: { demonstration: true, externalExecution: false, humanApproval: false, documents: [{id:'bank',label:'Bank statement',period:'January',readable:true},{id:'expenses',label:'Expense summary',period:'December',readable:true},{id:'payroll',label:'Payroll summary',period:null,readable:false}] } }];"
      }
    },
    {
      "id": "document-chase-2",
      "name": "Check the requested month",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        560,
        240
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "language": "javaScript",
        "jsCode": "function documentIssues(documents                  )                   {\n  return documents.filter(document => document.period !== 'January' || !document.readable);\n}\nconst input = $input.all()[0].json;\nreturn [{json:{...input,issues:documentIssues(input.documents)}}];"
      }
    },
    {
      "id": "document-chase-3",
      "name": "Prepare one specific request",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        840,
        240
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "language": "javaScript",
        "jsCode": "const input = $input.all()[0].json;\nconst requested = [...new Set(input.issues.map(document => document.id))];\nreturn [{json:{...input,requested,requestCount:requested.length?1:0,messageSent:false}}];"
      }
    },
    {
      "id": "document-chase-4",
      "name": "Require a complete approved package",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1120,
        240
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "language": "javaScript",
        "jsCode": "const input = $input.all()[0].json;\nconst ready = input.issues.length === 0;\nconst approved = ready && input.humanApproval === true;\nreturn [{json:{...input,ready,approved,package:approved?input.documents.map(document=>document.id):null,externalExecution:false}}];"
      }
    }
  ],
  "connections": {
    "Run the local example": {
      "main": [
        [
          {
            "node": "Load example document metadata",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Load example document metadata": {
      "main": [
        [
          {
            "node": "Check the requested month",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check the requested month": {
      "main": [
        [
          {
            "node": "Prepare one specific request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare one specific request": {
      "main": [
        [
          {
            "node": "Require a complete approved package",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "pinData": {},
  "tags": []
}
