{
  "name": "Antworten freigeben",
  "nodes": [
    {
      "parameters": {
        "authentication": "n8nUserAuth",
        "formTitle": "Antwort freigeben",
        "formDescription": "Die Nummer steht in der Datentabelle »anfragen« in der Spalte id.",
        "formFields": {
          "values": [
            {
              "fieldLabel": "Nummer",
              "fieldType": "number",
              "requiredField": true
            }
          ]
        },
        "responseMode": "lastNode",
        "options": {}
      },
      "id": "2494fd67-7fc7-4f94-b308-b7d550df59f3",
      "name": "Freigabe starten",
      "type": "n8n-nodes-base.formTrigger",
      "typeVersion": 2.6,
      "position": [
        0,
        0
      ],
      "webhookId": "6a878670-a9af-40fd-b144-faac55d6b5e1"
    },
    {
      "parameters": {
        "resource": "row",
        "operation": "get",
        "dataTableId": {
          "__rl": true,
          "mode": "name",
          "value": "anfragen"
        },
        "matchType": "allConditions",
        "filters": {
          "conditions": [
            {
              "keyName": "id",
              "condition": "eq",
              "keyValue": "={{ $json.Nummer }}"
            },
            {
              "keyName": "status",
              "condition": "eq",
              "keyValue": "offen"
            }
          ]
        },
        "limit": 1
      },
      "id": "352e1484-8eed-483a-97e8-919376b2c27e",
      "name": "Anfrage holen",
      "type": "n8n-nodes-base.dataTable",
      "typeVersion": 1.1,
      "position": [
        220,
        0
      ],
      "alwaysOutputData": true
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "loose",
            "version": 2
          },
          "conditions": [
            {
              "id": "733cac16-c33a-4ba0-a982-906e48a8533b",
              "leftValue": "={{ $json.id }}",
              "rightValue": "",
              "operator": {
                "type": "number",
                "operation": "exists",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "985238ac-1e43-421c-90d7-7f2bce0c65ad",
      "name": "Noch offen?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        440,
        0
      ]
    },
    {
      "parameters": {
        "operation": "page",
        "formFields": {
          "values": [
            {
              "fieldLabel": "Entscheidung",
              "fieldType": "radio",
              "fieldOptions": {
                "values": [
                  {
                    "option": "Freigeben"
                  },
                  {
                    "option": "Ablehnen"
                  }
                ]
              },
              "requiredField": true
            },
            {
              "fieldLabel": "Antwort",
              "fieldType": "textarea",
              "defaultValue": "={{ $json.entwurf }}",
              "requiredField": true
            }
          ]
        },
        "options": {
          "formTitle": "=Anfrage {{ $json.id }} · {{ $json.kategorie }}",
          "formDescription": "=Von {{ $json.name }} ({{ $json.email }}):\n\n{{ $json.anliegen }}",
          "buttonLabel": "Speichern",
          "customCss": "textarea { min-height: 280px; font-size: 15px; line-height: 1.5; }"
        }
      },
      "id": "56699e71-8a37-428d-9854-8128b707cc96",
      "name": "Entwurf prüfen",
      "type": "n8n-nodes-base.form",
      "typeVersion": 2.5,
      "position": [
        680,
        -120
      ],
      "webhookId": "d4691b30-ea46-4112-9ebd-880411211411"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "loose",
            "version": 2
          },
          "conditions": [
            {
              "id": "ecd0d3d5-60a1-4e55-8abb-9c1e151d981f",
              "leftValue": "={{ $json.Entscheidung }}",
              "rightValue": "Freigeben",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            },
            {
              "id": "04bec8bf-a5dc-4e15-bca1-dc18f10a8157",
              "leftValue": "={{ $json.Antwort }}",
              "rightValue": "[",
              "operator": {
                "type": "string",
                "operation": "contains"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "94ddd5c7-bbc1-4767-a04d-1354ba1038ac",
      "name": "Platzhalter übrig?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        900,
        -120
      ]
    },
    {
      "parameters": {
        "operation": "completion",
        "respondWith": "text",
        "completionTitle": "Noch nicht freigegeben",
        "completionMessage": "In der Antwort steht noch ein Platzhalter in eckigen Klammern. Bitte ergänzen und die Freigabe neu starten.",
        "options": {}
      },
      "id": "1c467daf-132d-44d8-99dc-fe06008553f8",
      "name": "Erst ergänzen",
      "type": "n8n-nodes-base.form",
      "typeVersion": 2.5,
      "position": [
        1120,
        -240
      ],
      "webhookId": "ead24624-2c5f-485d-9162-70f542fdc344"
    },
    {
      "parameters": {
        "resource": "row",
        "operation": "update",
        "dataTableId": {
          "__rl": true,
          "mode": "name",
          "value": "anfragen"
        },
        "filters": {
          "conditions": [
            {
              "keyName": "id",
              "condition": "eq",
              "keyValue": "={{ $('Anfrage holen').item.json.id }}"
            }
          ]
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "status": "={{ $('Entwurf prüfen').item.json.Entscheidung === 'Freigeben' ? 'freigegeben' : 'abgelehnt' }}",
            "antwort_final": "={{ $('Entwurf prüfen').item.json.Entscheidung === 'Freigeben' ? $('Entwurf prüfen').item.json.Antwort : '' }}"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "status",
              "displayName": "status",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "antwort_final",
              "displayName": "antwort_final",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            }
          ]
        },
        "options": {}
      },
      "id": "8808ee16-d5e2-42d9-bf95-bc1955b27236",
      "name": "Ergebnis eintragen",
      "type": "n8n-nodes-base.dataTable",
      "typeVersion": 1.1,
      "position": [
        1120,
        -40
      ]
    },
    {
      "parameters": {
        "operation": "completion",
        "respondWith": "text",
        "completionTitle": "Gespeichert",
        "completionMessage": "=Anfrage {{ $('Anfrage holen').item.json.id }} ist jetzt: {{ $json.status }}.",
        "options": {}
      },
      "id": "4d39da9e-25fd-454c-af47-5e8241be9650",
      "name": "Gespeichert",
      "type": "n8n-nodes-base.form",
      "typeVersion": 2.5,
      "position": [
        1340,
        -40
      ],
      "webhookId": "d286f8c7-9860-4bae-a4ed-f748f0e563f3"
    },
    {
      "parameters": {
        "operation": "completion",
        "respondWith": "text",
        "completionTitle": "Nichts zu tun",
        "completionMessage": "Diese Nummer gibt es nicht, oder die Anfrage ist schon erledigt.",
        "options": {}
      },
      "id": "dcd4ff79-a7ec-4dec-b794-f1e6ac483515",
      "name": "Nichts zu tun",
      "type": "n8n-nodes-base.form",
      "typeVersion": 2.5,
      "position": [
        680,
        120
      ],
      "webhookId": "e21b92f9-a8b4-46f7-b466-65f1ece28554"
    }
  ],
  "connections": {
    "Freigabe starten": {
      "main": [
        [
          {
            "node": "Anfrage holen",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Anfrage holen": {
      "main": [
        [
          {
            "node": "Noch offen?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Noch offen?": {
      "main": [
        [
          {
            "node": "Entwurf prüfen",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Nichts zu tun",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Entwurf prüfen": {
      "main": [
        [
          {
            "node": "Platzhalter übrig?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Platzhalter übrig?": {
      "main": [
        [
          {
            "node": "Erst ergänzen",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Ergebnis eintragen",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Ergebnis eintragen": {
      "main": [
        [
          {
            "node": "Gespeichert",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "meta": {
    "templateCredsSetupCompleted": true
  }
}
