{
  "name": "Workflow 11 - Recipe Comments",
  "nodes": [
    {
      "parameters": {
        "operation": "getAll",
        "tableId": "users",
        "returnAll": true
      },
      "type": "n8n-nodes-base.supabase",
      "typeVersion": 1,
      "position": [
        768,
        672
      ],
      "id": "0a990d5a-3a91-4c11-9b8b-1304b5a936bb",
      "name": "Get Users",
      "credentials": {
        "supabaseApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "community/comment",
        "responseMode": "responseNode",
        "options": {}
      },
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2.1,
      "position": [
        320,
        464
      ],
      "id": "55268967-110a-4a32-8ad4-28d74ed6ebe2",
      "name": "Add Comment Webhook1"
    },
    {
      "parameters": {
        "tableId": "interactions",
        "fieldsUi": {
          "fieldValues": [
            {
              "fieldId": "user_id",
              "fieldValue": "={{ $json.body.user_id }}"
            },
            {
              "fieldId": "recipe_id",
              "fieldValue": "={{ $json.body.recipe_id }}"
            },
            {
              "fieldId": "type",
              "fieldValue": "=comment"
            },
            {
              "fieldId": "comment",
              "fieldValue": "={{ $json.body.comment }}"
            }
          ]
        }
      },
      "type": "n8n-nodes-base.supabase",
      "typeVersion": 1,
      "position": [
        544,
        464
      ],
      "id": "a048a051-970d-4cda-88b0-63d9bfeef909",
      "name": "Add Comment1",
      "credentials": {
        "supabaseApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={\n  \"success\": true,\n  \"message\": \"Comment added!\",\n  \"comment_id\": \"{{ $json.id }}\"\n}",
        "options": {}
      },
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.4,
      "position": [
        768,
        464
      ],
      "id": "682ab965-e46f-4c12-b85c-0a91157415c1",
      "name": "Respond Add1"
    },
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "community/comments",
        "responseMode": "responseNode",
        "options": {}
      },
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2.1,
      "position": [
        320,
        672
      ],
      "id": "d91c2abd-560a-4b36-b7b9-f790753b13fb",
      "name": "Get Comments Webhook1"
    },
    {
      "parameters": {
        "operation": "getAll",
        "tableId": "interactions",
        "limit": 100,
        "filterType": "string",
        "filterString": "=recipe_id=eq.{{ $json.body.recipe_id }}&type=eq.comment"
      },
      "type": "n8n-nodes-base.supabase",
      "typeVersion": 1,
      "position": [
        544,
        672
      ],
      "id": "621a1d7e-e355-4834-ac35-dd8e59154f2b",
      "name": "Get Comments1",
      "credentials": {
        "supabaseApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "const comments = $('Get Comments1').all();\nconst users = $('Get Users').all();\n\n// Build user lookup map\nconst userMap = {};\nfor (const u of users) {\n  userMap[u.json.id] = u.json.username || 'User';\n}\n\nconst formattedComments = comments.map(item => ({\n  id: item.json.id,\n  user_id: item.json.user_id,\n  comment: item.json.comment,\n  created_at: item.json.created_at,\n  username: userMap[item.json.user_id] || 'User'\n}));\n\nreturn [{\n  json: {\n    success: true,\n    comments: formattedComments,\n    count: formattedComments.length\n  }\n}];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        992,
        672
      ],
      "id": "01a7e5b0-b9d1-4cc6-be64-d5c713c28730",
      "name": "Format Comments1"
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ JSON.stringify($json) }}",
        "options": {}
      },
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.4,
      "position": [
        1200,
        672
      ],
      "id": "ec5670f8-101b-4967-93fa-d18562d1b6de",
      "name": "Respond Get1"
    }
  ],
  "connections": {
    "Get Users": {
      "main": [
        [
          {
            "node": "Format Comments1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Add Comment Webhook1": {
      "main": [
        [
          {
            "node": "Add Comment1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Add Comment1": {
      "main": [
        [
          {
            "node": "Respond Add1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Comments Webhook1": {
      "main": [
        [
          {
            "node": "Get Comments1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Comments1": {
      "main": [
        [
          {
            "node": "Get Users",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format Comments1": {
      "main": [
        [
          {
            "node": "Respond Get1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": true,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "49ff075b-a396-45f3-8935-390533ee0c64",
  "id": "yStHXIeZyrfaclic",
  "tags": []
}