-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
142 lines (122 loc) · 5.06 KB
/
Copy pathserver.js
File metadata and controls
142 lines (122 loc) · 5.06 KB
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
const express = require('express');
const cors = require('cors');
const db = require('./db');
const bodyParser = require('body-parser');
// const applicationRoutes = require('./routes/applications'); // Not needed - loaded inline below
const app = express();
const PORT = process.env.PORT || 5000;
// Middleware
app.use(cors());
app.use(bodyParser.json({ limit: '50mb' }));
app.use(bodyParser.urlencoded({ limit: '50mb', extended: true }));
app.use(express.json({ limit: '50mb' }));
// Health check endpoint
app.get('/health', (req, res) => {
res.json({
status: 'OK',
message: 'ILOS Backend Server is running',
timestamp: new Date().toISOString(),
environment: process.env.NODE_ENV || 'development'
});
});
// Customer Status Endpoint
app.get('/customer-status/:cnic', async (req, res) => {
try {
const { cnic } = req.params;
const customerService = require('./customerService');
const customerStatus = await customerService.getCustomerStatus(cnic);
res.json(customerStatus);
} catch (error) {
console.error('Error fetching customer status:', error);
res.status(500).json({ error: 'Failed to fetch customer status' });
}
});
// NTB/ETB Endpoint
app.get('/api/getNTB_ETB/:cnic', async (req, res) => {
try {
const { cnic } = req.params;
if (!cnic || cnic.length !== 13) {
return res.status(400).json({ error: 'Valid 13-digit CNIC is required' });
}
const query = `
SELECT
customer_id, cnic, status, fullname, domicile_country, domicile_state,
city, district, business, industry, created_at
FROM cif_customers
WHERE cnic = $1
`;
const result = await db.query(query, [cnic]);
if (result.rows.length === 0) {
return res.json({
isETB: false,
customer: null,
message: 'New customer'
});
}
const customer = result.rows[0];
const formattedCustomer = {
customerId: customer.customer_id,
cnic: customer.cnic,
status: customer.status,
fullname: customer.fullname,
firstName: customer.fullname?.split(' ')[0] || '',
lastName: customer.fullname?.split(' ').slice(-1)[0] || '',
domicileCountry: customer.domicile_country,
domicileState: customer.domicile_state,
city: customer.city,
district: customer.district,
business: customer.business,
industry: customer.industry,
createdAt: customer.created_at
};
res.json({
isETB: true,
customer: formattedCustomer,
message: 'Existing customer found'
});
} catch (error) {
console.error('Error fetching customer:', error);
res.status(500).json({ error: 'Internal server error' });
}
});
// Test route to verify server works
app.get('/api/test', (req, res) => {
res.json({ message: 'Server test route works!', timestamp: new Date().toISOString() });
});
// Routes - using minimal version for testing
app.use('/api/applications', require('./routes/applications'));
app.use('/api/personal-details', require('./routes/personalDetails'));
app.use('/api/current-address', require('./routes/currentAddress'));
app.use('/api/permanent-address', require('./routes/permanentAddress'));
app.use('/api/employment-details', require('./routes/employmentDetails'));
app.use('/api/vehicle-details', require('./routes/vehicleDetails'));
app.use('/api/reference-contacts', require('./routes/referenceContacts'));
app.use('/api/insurance-details', require('./routes/insuranceDetails'));
app.use('/api/contact-details', require('./routes/contactDetails'));
app.use('/api/verification', require('./routes/verification'));
app.use('/api/spu-officer', require('./routes/spuOfficer'));
app.use('/api/spu', require('./routes/spu'));
app.use('/api/cif', require('./routes/cif'));
app.use('/cif', require('./routes/cif'));
app.use('/api/cashplus', require('./routes/cashplus'));
app.use('/api/autoloan', require('./routes/autoloan'));
app.use('/api/ameendrive', require('./routes/ameendrive'));
app.use('/api/smeasaan', require('./routes/smeasaan'));
app.use('/api/commercialVehicle', require('./routes/commercialVehicle'));
app.use('/api/classic_creditcard', require('./routes/classic_creditcard'));
app.use('/api/platinum_creditcard', require('./routes/platinum_creditcard'));
// Removed duplicate applications route - already mounted above
//EXTERNAL APIs
app.use('/api/sbp-blacklist', require('./routes/sbp_blacklist'));
app.use('/api/pep', require('./routes/pep'));
app.use('/api/internal-watchlist', require('./routes/internal_watchlist'));
app.use('/api/nadra-verisys', require('./routes/nadra_verisys'));
app.use('/api/frms', require('./routes/frms'));
app.use('/api/consumer-companies', require('./routes/consumer_companies_list'));
app.use('/api/ecib-reports', require('./routes/ecib_reports'));
app.use('/api', require('./routes/combineChecks'));
app.use('/api/ccl', require('./routes/consumer_companies_list'));
// Start the server and bind to localhost for development
app.listen(PORT, '0.0.0.0', () => {
console.log(`🟢 Server running at: http://localhost:${PORT}`);
});