File size: 4,545 Bytes
fcf8749
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
const axios = require('axios');
const fs = require('fs');
const path = require('path');

const BASE_URL = 'http://localhost:3000/api';

const endpoints = [
    // Auth (Public)
    { method: 'POST', url: '/auth/register', label: 'Auth Register' },
    { method: 'POST', url: '/auth/login', label: 'Auth Login' },
    { method: 'POST', url: '/auth/verify-otp', label: 'Auth Verify OTP' },
    { method: 'POST', url: '/auth/refresh-token', label: 'Auth Refresh Token' },
    
    // Auth (Protected)
    { method: 'GET', url: '/auth/profile', label: 'Auth Profile' },

    // Dashboard
    { method: 'GET', url: '/dashboard/stats', label: 'Dashboard Stats' },
    { method: 'GET', url: '/dashboard/activity', label: 'Dashboard Activity' },
    { method: 'GET', url: '/dashboard/live-tracking', label: 'Dashboard Live Tracking (Mobile)' },
    { method: 'GET', url: '/dashboard/live-tracking-web', label: 'Dashboard Live Tracking (Web)' },
    { method: 'GET', url: '/dashboard/recent-absorptions', label: 'Dashboard Recent Absorptions' },

    // Drivers
    { method: 'GET', url: '/drivers', label: 'Get All Drivers' },
    { method: 'POST', url: '/drivers', label: 'Create Driver' },
    
    // E-Way Bills
    { method: 'GET', url: '/eway-bills', label: 'Get E-Way Bills' },
    { method: 'GET', url: '/eway-bills/stats', label: 'Get E-Way Bills Stats' },
    { method: 'POST', url: '/eway-bills', label: 'Create E-Way Bill' },

    // Packages
    { method: 'GET', url: '/packages/history', label: 'Package History (Mobile)' },
    { method: 'GET', url: '/packages/history-web', label: 'Package History (Web)' },

    // Deliveries
    { method: 'POST', url: '/deliveries/create', label: 'Create Delivery (Public)' },
    { method: 'GET', url: '/deliveries/assigned', label: 'Assigned Deliveries' },

    // Absorption
    { method: 'GET', url: '/absorption/map-data', label: 'Absorption Map Data' },
    { method: 'GET', url: '/absorption/active', label: 'Absorption Active' },
    
    // Virtual Hubs
    { method: 'GET', url: '/virtual-hubs', label: 'Virtual Hubs List' },
];

async function checkEndpoints() {
    let output = '# API Verification Results (With JSON Body)\n\n';
    console.log('Checking API Endpoints...');

    for (const ep of endpoints) {
        try {
            const config = {
                method: ep.method,
                url: BASE_URL + ep.url,
                validateStatus: function (status) {
                    return status < 600; // Resolve all status codes
                }
            };
            
            const response = await axios(config);
            let statusLabel = 'Unknown';
            let icon = '❓';
            
            if (response.status >= 200 && response.status < 300) {
                statusLabel = 'Success';
                icon = '✅';
            } else if (response.status === 401 || response.status === 403) {
                statusLabel = 'Protected (Auth Required)';
                icon = '🔒';
            } else if (response.status === 400) {
                statusLabel = 'Bad Request (Endpoint Active)';
                icon = '⚠️';
            } else if (response.status === 404) {
                statusLabel = 'Not Found';
                icon = '❌';
            } else {
                statusLabel = `Error ${response.status}`;
                icon = '⚠️';
            }

            // Section Header
            output += `### ${icon} ${ep.label}\n`;
            output += `**Endpoint**: \`${ep.method} ${ep.url}\`\n`;
            output += `**Status**: ${response.status} (${statusLabel})\n`;

            // Display Body for GET requests if successful
            if (ep.method === 'GET' && response.status >= 200 && response.status < 300) {
                output += `**Response Body**:\n`;
                output += '```json\n';
                output += JSON.stringify(response.data, null, 2);
                output += '\n```\n';
            } else if (ep.method === 'POST') {
                output += `**Response**: ${statusLabel}\n`;
            }

            output += '---\n\n';

        } catch (error) {
             output += `### 🛑 ${ep.label}\n`;
             output += `**Endpoint**: \`${ep.method} ${ep.url}\`\n`;
             output += `**Error**: Network Error (${error.message})\n\n`;
        }
    }

    fs.writeFileSync(path.join(__dirname, 'api_verification_results.md'), output);
    console.log('Verification complete. Detailed results saved to api_verification_results.md');
}

checkEndpoints();