/** * Test API endpoint for teachers */ const API_BASE = 'http://localhost:4000/api'; async function testTeachersAPI() { console.log('๐Ÿงช Testing Teachers API\n'); console.log('='.repeat(60)); try { // Test 1: Get all teachers with school filter console.log('\n๐Ÿ“ Test 1: GET /api/teachers with school_id filter'); console.log('URL: ' + API_BASE + '/teachers?school_id=95ec32e9-cdcb-4f3a-a8ee-8af20bdfe2cc&page=1&limit=5'); const response1 = await fetch(`${API_BASE}/teachers?school_id=95ec32e9-cdcb-4f3a-a8ee-8af20bdfe2cc&page=1&limit=5`); const data1 = await response1.json(); if (data1.success) { console.log('โœ… Success!'); console.log(` Total: ${data1.data.pagination.total}`); console.log(` Returned: ${data1.data.teachers.length}`); if (data1.data.teachers.length > 0) { const teacher = data1.data.teachers[0]; console.log('\n๐Ÿ“‹ Sample Teacher:'); console.log(` ID: ${teacher.id}`); console.log(` Code: ${teacher.teacher_code}`); console.log(` Type: ${teacher.teacher_type}`); console.log(` Status: ${teacher.status}`); console.log(` Profile: ${teacher.profile ? 'โœ… EXISTS' : 'โŒ NULL'}`); if (teacher.profile) { console.log(` - Full Name: ${teacher.profile.full_name}`); console.log(` - Phone: ${teacher.profile.phone || 'N/A'}`); console.log(` - School ID: ${teacher.profile.school_id}`); } } } else { console.log('โŒ Failed:', data1.message); } // Test 2: Get all teachers without filter console.log('\n\n๐Ÿ“ Test 2: GET /api/teachers (no filter)'); console.log('URL: ' + API_BASE + '/teachers?page=1&limit=3'); const response2 = await fetch(`${API_BASE}/teachers?page=1&limit=3`); const data2 = await response2.json(); if (data2.success) { console.log('โœ… Success!'); console.log(` Total: ${data2.data.pagination.total}`); console.log(` Returned: ${data2.data.teachers.length}`); console.log('\n๐Ÿ“‹ Teachers:'); data2.data.teachers.forEach((t, i) => { console.log(` ${i + 1}. ${t.teacher_code} - Profile: ${t.profile ? 'โœ…' : 'โŒ'}`); if (t.profile) { console.log(` Name: ${t.profile.full_name}`); } }); } else { console.log('โŒ Failed:', data2.message); } console.log('\n' + '='.repeat(60)); console.log('โœ… Tests completed!'); console.log('='.repeat(60) + '\n'); } catch (error) { console.error('\nโŒ Test failed:', error.message); } } // Run test testTeachersAPI();