{
  "name": "Query: Current Status",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "GET",
        "path": "current",
        "options": {}
      },
      "id": "webhook-current",
      "name": "Webhook Get Current",
      "type": "n8n-nodes-base.webhook",
      "position": [
        250,
        300
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "jsCode": "const Database = require('better-sqlite3');\nconst db = new Database('e:/repos/golearn/data/curriculum.db');\n\nconst row = db.prepare('SELECT * FROM cycles WHERE status=? ORDER BY id DESC LIMIT 1').get('active');\ndb.close();\n\nreturn {\n  json: row || {}\n};",
        "mode": "runOnceForAllItems"
      },
      "id": "get-active-cycle",
      "name": "Get Active Cycle",
      "type": "n8n-nodes-base.code",
      "position": [
        450,
        300
      ],
      "typeVersion": 2
    },
    {
      "parameters": {
        "jsCode": "const Database = require('better-sqlite3');\nconst db = new Database('e:/repos/golearn/data/curriculum.db');\n\nconst rows = db.prepare('SELECT * FROM assessments ORDER BY id DESC LIMIT 5').all();\ndb.close();\n\nreturn {\n  json: rows\n};",
        "mode": "runOnceForAllItems"
      },
      "id": "get-recent-assessments",
      "name": "Get Recent Assessments",
      "type": "n8n-nodes-base.code",
      "position": [
        650,
        300
      ],
      "typeVersion": 2
    },
    {
      "parameters": {
        "jsCode": "const Database = require('better-sqlite3');\nconst db = new Database('e:/repos/golearn/data/curriculum.db');\n\nconst rows = db.prepare('SELECT concept_name, current_score, times_seen FROM concept_mastery ORDER BY concept_name').all();\ndb.close();\n\nreturn {\n  json: rows\n};",
        "mode": "runOnceForAllItems"
      },
      "id": "get-concept-mastery",
      "name": "Get Concept Mastery",
      "type": "n8n-nodes-base.code",
      "position": [
        650,
        450
      ],
      "typeVersion": 2
    },
    {
      "parameters": {
        "jsCode": "// Build comprehensive status response\nconst activeCycle = $input.first().json;\nconst assessments = $input.all()[1].json;\nconst concepts = $input.all()[2].json;\n\nconst currentCurriculum = activeCycle.curriculum_json ? \n  JSON.parse(activeCycle.curriculum_json) : null;\n\nconst recentAssessments = Array.isArray(assessments) ? \n  assessments.map(a => ({\n    id: a.id,\n    cycle_id: a.cycle_id,\n    submitted_at: a.submitted_at,\n    assessment: a.assessment_json ? JSON.parse(a.assessment_json) : null\n  })) : [];\n\n// Group concepts by mastery level\nconst conceptsByLevel = {\n  untaught: concepts.filter(c => c.current_score === 0),\n  learning: concepts.filter(c => c.current_score > 0 && c.current_score < 3),\n  developing: concepts.filter(c => c.current_score === 3),\n  proficient: concepts.filter(c => c.current_score >= 4),\n  plateau: concepts.filter(c => c.times_seen >= 3 && c.current_score < 3)\n};\n\nreturn {\n  json: {\n    success: true,\n    current_curriculum: currentCurriculum,\n    current_cycle: activeCycle.cycle_num || 1,\n    cycle_status: activeCycle.status,\n    recent_assessments: recentAssessments,\n    concept_mastery: {\n      total: concepts.length,\n      by_level: {\n        untaught: conceptsByLevel.untaught.length,\n        learning: conceptsByLevel.learning.length,\n        developing: conceptsByLevel.developing.length,\n        proficient: conceptsByLevel.proficient.length,\n        plateau: conceptsByLevel.plateau.length\n      },\n      concepts: concepts\n    }\n  }\n};"
      },
      "id": "build-status",
      "name": "Build Status Response",
      "type": "n8n-nodes-base.code",
      "position": [
        850,
        300
      ],
      "typeVersion": 2
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ $json }}",
        "options": {}
      },
      "id": "respond-status",
      "name": "Respond Status",
      "type": "n8n-nodes-base.respondToWebhook",
      "position": [
        1050,
        300
      ],
      "typeVersion": 1
    }
  ],
  "connections": {
    "Webhook Get Current": {
      "main": [
        [
          {
            "node": "Get Active Cycle",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Active Cycle": {
      "main": [
        [
          {
            "node": "Get Recent Assessments",
            "type": "main",
            "index": 0
          },
          {
            "node": "Get Concept Mastery",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Recent Assessments": {
      "main": [
        [
          {
            "node": "Build Status Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Concept Mastery": {
      "main": [
        [
          {
            "node": "Build Status Response",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Build Status Response": {
      "main": [
        [
          {
            "node": "Respond Status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionTimeout": 30
  }
}