{
  "name": "Issue Reporting - Reports API",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "GET",
        "path": "issue-reports",
        "responseMode": "responseNode",
        "options": {
          "allowedOrigins": "*"
        }
      },
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        0,
        0
      ],
      "id": "c3d4e5f6-3333-4c44-9a55-cccc00003333",
      "name": "GET /issue-reports"
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "SELECT\n  id,\n  reporter_name,\n  issue_summary,\n  to_char(report_date, 'YYYY-MM-DD') AS report_date,\n  image_filename,\n  image_mimetype,\n  CASE WHEN image_data IS NULL THEN NULL\n       ELSE 'data:' || coalesce(image_mimetype, 'image/png') || ';base64,' || encode(image_data, 'base64')\n  END AS image_data_uri,\n  to_char(created_at, 'YYYY-MM-DD\"T\"HH24:MI:SSOF') AS created_at\nFROM issue_reports\nORDER BY created_at DESC\nLIMIT 200;",
        "options": {}
      },
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.6,
      "position": [
        220,
        0
      ],
      "id": "d4e5f6a7-4444-4d55-9b66-dddd00004444",
      "name": "Select Reports",
      "alwaysOutputData": true,
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "// Runs once even when the SELECT returns zero rows, so the\n// webhook always responds with valid JSON ({ count, reports }).\nconst reports = $input.all()\n  .map((item) => item.json)\n  .filter((row) => row && row.id !== undefined && row.id !== null);\n\nreturn [{ json: { count: reports.length, reports } }];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        440,
        0
      ],
      "id": "e5f6a7b8-5555-4e66-9c77-eeee00005555",
      "name": "Build Response"
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ $json }}",
        "options": {
          "responseHeaders": {
            "entries": [
              {
                "name": "Access-Control-Allow-Origin",
                "value": "*"
              }
            ]
          }
        }
      },
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.1,
      "position": [
        660,
        0
      ],
      "id": "f6a7b8c9-6666-4f77-9d88-ffff00006666",
      "name": "Respond JSON"
    }
  ],
  "connections": {
    "GET /issue-reports": {
      "main": [
        [
          {
            "node": "Select Reports",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Select Reports": {
      "main": [
        [
          {
            "node": "Build Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build Response": {
      "main": [
        [
          {
            "node": "Respond JSON",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "a7b8c9d0-7777-4a88-9e99-000011112222",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "id": "73khFQZJhLumudnG",
  "tags": []
}