made compatible t take serve frontend build
This commit is contained in:
parent
4037f68745
commit
a9018ab0ff
BIN
build/assets/images/Re_Logo.png
Normal file
BIN
build/assets/images/Re_Logo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 30 KiB |
BIN
build/assets/images/become_a_dealer.webp
Normal file
BIN
build/assets/images/become_a_dealer.webp
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 255 KiB |
752
build/assets/index-CAe70IkM.js
Normal file
752
build/assets/index-CAe70IkM.js
Normal file
File diff suppressed because one or more lines are too long
6
build/assets/index-DkEVuJwH.css
Normal file
6
build/assets/index-DkEVuJwH.css
Normal file
File diff suppressed because one or more lines are too long
14
build/index.html
Normal file
14
build/index.html
Normal file
@ -0,0 +1,14 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Royal Enfield Onboarding</title>
|
||||
<script type="module" crossorigin src="/assets/index-CAe70IkM.js"></script>
|
||||
<link rel="stylesheet" crossorigin href="/assets/index-DkEVuJwH.css">
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
</body>
|
||||
</html>
|
||||
@ -6,6 +6,7 @@ import compression from 'compression';
|
||||
import rateLimit from 'express-rate-limit';
|
||||
import path from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
import fs from 'fs';
|
||||
import { createServer } from 'http';
|
||||
import { initSocket } from './common/utils/socket.js';
|
||||
|
||||
@ -46,6 +47,9 @@ import logger from './common/utils/logger.js';
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
const frontendBuildPath = path.resolve(process.cwd(), 'build');
|
||||
const frontendIndexPath = path.join(frontendBuildPath, 'index.html');
|
||||
const hasFrontendBuild = fs.existsSync(frontendIndexPath);
|
||||
|
||||
// Initialize Express app
|
||||
const app = express();
|
||||
@ -65,8 +69,16 @@ app.use(helmet({
|
||||
crossOriginEmbedderPolicy: false,
|
||||
crossOriginResourcePolicy: { policy: "cross-origin" }
|
||||
}));
|
||||
const allowedOrigins = new Set<string>([
|
||||
process.env.FRONTEND_URL || 'http://localhost:5173',
|
||||
'http://localhost:5173'
|
||||
]);
|
||||
app.use(cors({
|
||||
origin: process.env.FRONTEND_URL || 'http://localhost:5173',
|
||||
origin: (origin, callback) => {
|
||||
// Allow same-origin/browser requests without explicit Origin and known frontend origins.
|
||||
if (!origin || allowedOrigins.has(origin)) return callback(null, true);
|
||||
return callback(null, false);
|
||||
},
|
||||
credentials: true
|
||||
}));
|
||||
|
||||
@ -146,11 +158,27 @@ app.use('/api/dealers', dealerRoutes);
|
||||
app.use('/api/finance', settlementRoutes);
|
||||
app.use('/api/worknotes', collaborationRoutes);
|
||||
|
||||
// Serve React build from backend in single-domain deployments.
|
||||
if (hasFrontendBuild) {
|
||||
app.use(express.static(frontendBuildPath));
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 404 handler
|
||||
app.use((req: Request, res: Response) => {
|
||||
res.status(404).json({
|
||||
if (req.path.startsWith('/api')) {
|
||||
return res.status(404).json({
|
||||
success: false,
|
||||
message: 'Route not found'
|
||||
});
|
||||
}
|
||||
|
||||
if (hasFrontendBuild) {
|
||||
return res.sendFile(frontendIndexPath);
|
||||
}
|
||||
|
||||
return res.status(404).json({
|
||||
success: false,
|
||||
message: 'Route not found'
|
||||
});
|
||||
|
||||
@ -264,312 +264,312 @@ async function triggerWorkflow() {
|
||||
}, leadToken);
|
||||
const interviewId2 = intv2Response.data.id;
|
||||
|
||||
log(5.1, 'DD-Lead Giving Feedback...');
|
||||
await apiRequest('/assessment/level2-feedback', 'POST', {
|
||||
interviewId: interviewId2,
|
||||
overallScore: 9.5,
|
||||
feedbackItems: [
|
||||
{ type: 'Strategic Vision', comments: 'Excellent strategic planning.' },
|
||||
{ type: 'Management Capabilities', comments: 'Strong team leadership.' },
|
||||
{ type: 'Operational Understanding', comments: 'Knows the local market well.' }
|
||||
],
|
||||
recommendation: 'Selected'
|
||||
}, leadToken);
|
||||
// log(5.1, 'DD-Lead Giving Feedback...');
|
||||
// await apiRequest('/assessment/level2-feedback', 'POST', {
|
||||
// interviewId: interviewId2,
|
||||
// overallScore: 9.5,
|
||||
// feedbackItems: [
|
||||
// { type: 'Strategic Vision', comments: 'Excellent strategic planning.' },
|
||||
// { type: 'Management Capabilities', comments: 'Strong team leadership.' },
|
||||
// { type: 'Operational Understanding', comments: 'Knows the local market well.' }
|
||||
// ],
|
||||
// recommendation: 'Selected'
|
||||
// }, leadToken);
|
||||
|
||||
log(5.15, 'ZBH Giving Feedback...');
|
||||
const zbhToken = await login(zbhUser.email);
|
||||
await apiRequest('/assessment/level2-feedback', 'POST', {
|
||||
interviewId: interviewId2,
|
||||
overallScore: 9.0,
|
||||
feedbackItems: [
|
||||
{ type: 'Strategic Vision', comments: 'Good alignment with brand.' },
|
||||
{ type: 'Key Strengths', comments: 'Great location proposed.' },
|
||||
{ type: 'Areas of Concern', comments: 'None at this time.' }
|
||||
],
|
||||
recommendation: 'Selected'
|
||||
}, zbhToken);
|
||||
// log(5.15, 'ZBH Giving Feedback...');
|
||||
// const zbhToken = await login(zbhUser.email);
|
||||
// await apiRequest('/assessment/level2-feedback', 'POST', {
|
||||
// interviewId: interviewId2,
|
||||
// overallScore: 9.0,
|
||||
// feedbackItems: [
|
||||
// { type: 'Strategic Vision', comments: 'Good alignment with brand.' },
|
||||
// { type: 'Key Strengths', comments: 'Great location proposed.' },
|
||||
// { type: 'Areas of Concern', comments: 'None at this time.' }
|
||||
// ],
|
||||
// recommendation: 'Selected'
|
||||
// }, zbhToken);
|
||||
|
||||
log(5.2, 'DD-Lead Finalizing Level 2 Decision...');
|
||||
await apiRequest('/assessment/decision', 'POST', {
|
||||
interviewId: interviewId2,
|
||||
decision: 'Approved',
|
||||
remarks: 'Cleared Level 2'
|
||||
}, leadToken);
|
||||
log(5, 'Level 2 Complete.');
|
||||
await delay();
|
||||
// log(5.2, 'DD-Lead Finalizing Level 2 Decision...');
|
||||
// await apiRequest('/assessment/decision', 'POST', {
|
||||
// interviewId: interviewId2,
|
||||
// decision: 'Approved',
|
||||
// remarks: 'Cleared Level 2'
|
||||
// }, leadToken);
|
||||
// log(5, 'Level 2 Complete.');
|
||||
// await delay();
|
||||
|
||||
// 6. LEVEL-3 INTERVIEW
|
||||
log(6, 'Scheduling Level 3 Interview...');
|
||||
const headUser = users.data.find(u => u.email === EMAILS.DD_HEAD);
|
||||
const nbhUser = users.data.find(u => u.email === EMAILS.NBH);
|
||||
// // 6. LEVEL-3 INTERVIEW
|
||||
// log(6, 'Scheduling Level 3 Interview...');
|
||||
// const headUser = users.data.find(u => u.email === EMAILS.DD_HEAD);
|
||||
// const nbhUser = users.data.find(u => u.email === EMAILS.NBH);
|
||||
|
||||
const intv3Response = await apiRequest('/assessment/interviews', 'POST', {
|
||||
applicationId: applicationUUID,
|
||||
level: 3,
|
||||
scheduledAt: new Date(Date.now() + 259200000).toISOString(),
|
||||
type: 'In-Person',
|
||||
location: 'HO',
|
||||
participants: [headUser.id, nbhUser.id]
|
||||
}, leadToken);
|
||||
const interviewId3 = intv3Response.data.id;
|
||||
// const intv3Response = await apiRequest('/assessment/interviews', 'POST', {
|
||||
// applicationId: applicationUUID,
|
||||
// level: 3,
|
||||
// scheduledAt: new Date(Date.now() + 259200000).toISOString(),
|
||||
// type: 'In-Person',
|
||||
// location: 'HO',
|
||||
// participants: [headUser.id, nbhUser.id]
|
||||
// }, leadToken);
|
||||
// const interviewId3 = intv3Response.data.id;
|
||||
|
||||
log(6.1, 'NBH Giving Feedback...');
|
||||
const nbhToken = await login(EMAILS.NBH);
|
||||
await apiRequest('/assessment/level2-feedback', 'POST', {
|
||||
interviewId: interviewId3,
|
||||
overallScore: 10,
|
||||
feedbackItems: [
|
||||
{ type: 'Business Vision & Strategy', comments: 'Highly recommended for this market.' },
|
||||
{ type: 'Leadership & Decision Making', comments: 'Shows great potential.' }
|
||||
],
|
||||
recommendation: 'Selected'
|
||||
}, nbhToken);
|
||||
// log(6.1, 'NBH Giving Feedback...');
|
||||
// const nbhToken = await login(EMAILS.NBH);
|
||||
// await apiRequest('/assessment/level2-feedback', 'POST', {
|
||||
// interviewId: interviewId3,
|
||||
// overallScore: 10,
|
||||
// feedbackItems: [
|
||||
// { type: 'Business Vision & Strategy', comments: 'Highly recommended for this market.' },
|
||||
// { type: 'Leadership & Decision Making', comments: 'Shows great potential.' }
|
||||
// ],
|
||||
// recommendation: 'Selected'
|
||||
// }, nbhToken);
|
||||
|
||||
log(6.15, 'DD-Head Giving Feedback...');
|
||||
const headToken = await login(EMAILS.DD_HEAD);
|
||||
await apiRequest('/assessment/level2-feedback', 'POST', {
|
||||
interviewId: interviewId3,
|
||||
overallScore: 9.5,
|
||||
feedbackItems: [
|
||||
{ type: 'Operational & Financial Readiness', comments: 'Financially sound.' },
|
||||
{ type: 'Brand Alignment', comments: 'Understands Royal Enfield ethos perfectly.' }
|
||||
],
|
||||
recommendation: 'Selected'
|
||||
}, headToken);
|
||||
// log(6.15, 'DD-Head Giving Feedback...');
|
||||
// const headToken = await login(EMAILS.DD_HEAD);
|
||||
// await apiRequest('/assessment/level2-feedback', 'POST', {
|
||||
// interviewId: interviewId3,
|
||||
// overallScore: 9.5,
|
||||
// feedbackItems: [
|
||||
// { type: 'Operational & Financial Readiness', comments: 'Financially sound.' },
|
||||
// { type: 'Brand Alignment', comments: 'Understands Royal Enfield ethos perfectly.' }
|
||||
// ],
|
||||
// recommendation: 'Selected'
|
||||
// }, headToken);
|
||||
|
||||
log(6.2, 'Head Finalizing Level 3 Decision...');
|
||||
await apiRequest('/assessment/decision', 'POST', {
|
||||
interviewId: interviewId3,
|
||||
decision: 'Approved',
|
||||
remarks: 'Cleared Level 3. Moving to FDD.'
|
||||
}, headToken);
|
||||
log(6, 'Level 3 Complete. Stage is now FDD Verification.');
|
||||
await delay();
|
||||
// log(6.2, 'Head Finalizing Level 3 Decision...');
|
||||
// await apiRequest('/assessment/decision', 'POST', {
|
||||
// interviewId: interviewId3,
|
||||
// decision: 'Approved',
|
||||
// remarks: 'Cleared Level 3. Moving to FDD.'
|
||||
// }, headToken);
|
||||
// log(6, 'Level 3 Complete. Stage is now FDD Verification.');
|
||||
// await delay();
|
||||
|
||||
// 6.3 FDD ASSIGNMENT
|
||||
log(6.3, 'Admin Assigning Application to FDD Agency...');
|
||||
const fddUser = users.data.find(u => u.email === EMAILS.FDD);
|
||||
await apiRequest('/fdd/assign', 'POST', {
|
||||
applicationId: applicationUUID,
|
||||
assignedToAgency: fddUser.id
|
||||
}, adminToken);
|
||||
log(6.3, 'FDD Agency assigned successfully.');
|
||||
await delay();
|
||||
// // 6.3 FDD ASSIGNMENT
|
||||
// log(6.3, 'Admin Assigning Application to FDD Agency...');
|
||||
// const fddUser = users.data.find(u => u.email === EMAILS.FDD);
|
||||
// await apiRequest('/fdd/assign', 'POST', {
|
||||
// applicationId: applicationUUID,
|
||||
// assignedToAgency: fddUser.id
|
||||
// }, adminToken);
|
||||
// log(6.3, 'FDD Agency assigned successfully.');
|
||||
// await delay();
|
||||
|
||||
// 7. FDD MILESTONE
|
||||
log(7, 'FDD Agency Discovery & Report Upload...');
|
||||
const fddToken = await login(EMAILS.FDD);
|
||||
// // 7. FDD MILESTONE
|
||||
// log(7, 'FDD Agency Discovery & Report Upload...');
|
||||
// const fddToken = await login(EMAILS.FDD);
|
||||
|
||||
// FETCH ASSIGNMENT ID
|
||||
const assignmentRes = await apiRequest(`/fdd/${applicationUUID}`, 'GET', null, fddToken);
|
||||
const assignmentId = assignmentRes.data.id;
|
||||
log(7, `Found Assignment ID: ${assignmentId}`);
|
||||
// // FETCH ASSIGNMENT ID
|
||||
// const assignmentRes = await apiRequest(`/fdd/${applicationUUID}`, 'GET', null, fddToken);
|
||||
// const assignmentId = assignmentRes.data.id;
|
||||
// log(7, `Found Assignment ID: ${assignmentId}`);
|
||||
|
||||
await apiRequest('/fdd/report', 'POST', {
|
||||
assignmentId,
|
||||
findings: 'Finance records clean.',
|
||||
recommendation: 'Approved'
|
||||
}, fddToken);
|
||||
// await apiRequest('/fdd/report', 'POST', {
|
||||
// assignmentId,
|
||||
// findings: 'Finance records clean.',
|
||||
// recommendation: 'Approved'
|
||||
// }, fddToken);
|
||||
|
||||
log(7.1, 'Admin Approving FDD Final Stage...');
|
||||
await apiRequest('/assessment/stage-decision', 'POST', {
|
||||
applicationId: applicationUUID,
|
||||
stageCode: 'FDD_VERIFICATION',
|
||||
decision: 'Approved',
|
||||
remarks: 'FDD documents verified.'
|
||||
}, adminToken);
|
||||
log(7, 'FDD Milestone Complete.');
|
||||
await delay();
|
||||
// log(7.1, 'Admin Approving FDD Final Stage...');
|
||||
// await apiRequest('/assessment/stage-decision', 'POST', {
|
||||
// applicationId: applicationUUID,
|
||||
// stageCode: 'FDD_VERIFICATION',
|
||||
// decision: 'Approved',
|
||||
// remarks: 'FDD documents verified.'
|
||||
// }, adminToken);
|
||||
// log(7, 'FDD Milestone Complete.');
|
||||
// await delay();
|
||||
|
||||
log(7.4, 'Uploading mandatory documents prior to LOI generation...');
|
||||
const requiredDocs = ['CIBIL Report', 'Proposed Site City Map', 'Bank Statement', 'GST Certificate', 'PAN Card'];
|
||||
for (const doc of requiredDocs) {
|
||||
await mockUploadDocument(applicationUUID, adminToken, doc);
|
||||
}
|
||||
await delay(1000);
|
||||
// log(7.4, 'Uploading mandatory documents prior to LOI generation...');
|
||||
// const requiredDocs = ['CIBIL Report', 'Proposed Site City Map', 'Bank Statement', 'GST Certificate', 'PAN Card'];
|
||||
// for (const doc of requiredDocs) {
|
||||
// await mockUploadDocument(applicationUUID, adminToken, doc);
|
||||
// }
|
||||
// await delay(1000);
|
||||
|
||||
// 7.5 LOI APPROVAL
|
||||
log(7.5, 'LOI Generation & Approval...');
|
||||
const loiRes = await apiRequest('/loi/request', 'POST', { applicationId: applicationUUID }, adminToken);
|
||||
const loiRequestId = loiRes.data.id;
|
||||
// // 7.5 LOI APPROVAL
|
||||
// log(7.5, 'LOI Generation & Approval...');
|
||||
// const loiRes = await apiRequest('/loi/request', 'POST', { applicationId: applicationUUID }, adminToken);
|
||||
// const loiRequestId = loiRes.data.id;
|
||||
|
||||
// Head Approval
|
||||
await apiRequest(`/loi/request/${loiRequestId}/approve`, 'POST', {
|
||||
action: 'Approved',
|
||||
remarks: 'Head Authorization for LOI'
|
||||
}, headToken);
|
||||
// // Head Approval
|
||||
// await apiRequest(`/loi/request/${loiRequestId}/approve`, 'POST', {
|
||||
// action: 'Approved',
|
||||
// remarks: 'Head Authorization for LOI'
|
||||
// }, headToken);
|
||||
|
||||
// NBH Approval
|
||||
await apiRequest(`/loi/request/${loiRequestId}/approve`, 'POST', {
|
||||
action: 'Approved',
|
||||
remarks: 'NBH Authorization for LOI'
|
||||
}, nbhToken);
|
||||
// // NBH Approval
|
||||
// await apiRequest(`/loi/request/${loiRequestId}/approve`, 'POST', {
|
||||
// action: 'Approved',
|
||||
// remarks: 'NBH Authorization for LOI'
|
||||
// }, nbhToken);
|
||||
|
||||
log(7.5, 'LOI Milestone Complete.');
|
||||
await delay();
|
||||
// log(7.5, 'LOI Milestone Complete.');
|
||||
// await delay();
|
||||
|
||||
// 8. PAYMENT GATE (SECURITY DEPOSIT FIRST AS PER CURRENT FLOW)
|
||||
log(8, 'Finance Verifying SECURITY_DEPOSIT to unlock LOI Issued...');
|
||||
const financeToken = await login(EMAILS.FINANCE);
|
||||
await apiRequest('/loa/security-deposit', 'POST', {
|
||||
applicationId: applicationUUID,
|
||||
amount: 500000,
|
||||
paymentReference: 'PAY-888999',
|
||||
depositType: 'SECURITY_DEPOSIT',
|
||||
status: 'Verified'
|
||||
}, financeToken);
|
||||
log(8, 'Security Deposit Verified.')
|
||||
// 9. GENERATE DEALER CODES (align with backend gate: LOI Issued required)
|
||||
let statusBeforeCodeGen = await getApplicationStatus(applicationUUID, adminToken);
|
||||
log(9, `Current status before code generation: ${statusBeforeCodeGen}`);
|
||||
log(9, 'Ensuring mandatory PAN/GST/Bank fields before code generation...');
|
||||
await ensureMandatoryCodeGenFields(applicationUUID, adminToken);
|
||||
await delay(300);
|
||||
// // 8. PAYMENT GATE (SECURITY DEPOSIT FIRST AS PER CURRENT FLOW)
|
||||
// log(8, 'Finance Verifying SECURITY_DEPOSIT to unlock LOI Issued...');
|
||||
// const financeToken = await login(EMAILS.FINANCE);
|
||||
// await apiRequest('/loa/security-deposit', 'POST', {
|
||||
// applicationId: applicationUUID,
|
||||
// amount: 500000,
|
||||
// paymentReference: 'PAY-888999',
|
||||
// depositType: 'SECURITY_DEPOSIT',
|
||||
// status: 'Verified'
|
||||
// }, financeToken);
|
||||
// log(8, 'Security Deposit Verified.')
|
||||
// // 9. GENERATE DEALER CODES (align with backend gate: LOI Issued required)
|
||||
// let statusBeforeCodeGen = await getApplicationStatus(applicationUUID, adminToken);
|
||||
// log(9, `Current status before code generation: ${statusBeforeCodeGen}`);
|
||||
// log(9, 'Ensuring mandatory PAN/GST/Bank fields before code generation...');
|
||||
// await ensureMandatoryCodeGenFields(applicationUUID, adminToken);
|
||||
// await delay(300);
|
||||
|
||||
if (statusBeforeCodeGen === 'Security Details') {
|
||||
log(9, 'Status is Security Details; re-verifying Security Deposit to move to LOI Issued...');
|
||||
await apiRequest('/loa/security-deposit', 'POST', {
|
||||
applicationId: applicationUUID,
|
||||
amount: 500000,
|
||||
paymentReference: `PAY-RETRY-${Date.now()}`,
|
||||
depositType: 'SECURITY_DEPOSIT',
|
||||
status: 'Verified'
|
||||
}, financeToken);
|
||||
await delay();
|
||||
statusBeforeCodeGen = await getApplicationStatus(applicationUUID, adminToken);
|
||||
log(9, `Status after re-verify: ${statusBeforeCodeGen}`);
|
||||
}
|
||||
// if (statusBeforeCodeGen === 'Security Details') {
|
||||
// log(9, 'Status is Security Details; re-verifying Security Deposit to move to LOI Issued...');
|
||||
// await apiRequest('/loa/security-deposit', 'POST', {
|
||||
// applicationId: applicationUUID,
|
||||
// amount: 500000,
|
||||
// paymentReference: `PAY-RETRY-${Date.now()}`,
|
||||
// depositType: 'SECURITY_DEPOSIT',
|
||||
// status: 'Verified'
|
||||
// }, financeToken);
|
||||
// await delay();
|
||||
// statusBeforeCodeGen = await getApplicationStatus(applicationUUID, adminToken);
|
||||
// log(9, `Status after re-verify: ${statusBeforeCodeGen}`);
|
||||
// }
|
||||
|
||||
// Current backend flow keeps app at "Security Details" until explicit admin transition.
|
||||
if (statusBeforeCodeGen === 'Security Details') {
|
||||
log(9, 'Applying admin transition from Security Details -> LOI Issued...');
|
||||
await apiRequest(`/onboarding/applications/${applicationUUID}/status`, 'PUT', {
|
||||
status: 'LOI Issued',
|
||||
stage: 'LOI',
|
||||
reason: 'E2E script alignment: unlock dealer code generation after Security Details checks.'
|
||||
}, adminToken);
|
||||
await delay();
|
||||
statusBeforeCodeGen = await getApplicationStatus(applicationUUID, adminToken);
|
||||
log(9, `Status after admin transition: ${statusBeforeCodeGen}`);
|
||||
}
|
||||
// // Current backend flow keeps app at "Security Details" until explicit admin transition.
|
||||
// if (statusBeforeCodeGen === 'Security Details') {
|
||||
// log(9, 'Applying admin transition from Security Details -> LOI Issued...');
|
||||
// await apiRequest(`/onboarding/applications/${applicationUUID}/status`, 'PUT', {
|
||||
// status: 'LOI Issued',
|
||||
// stage: 'LOI',
|
||||
// reason: 'E2E script alignment: unlock dealer code generation after Security Details checks.'
|
||||
// }, adminToken);
|
||||
// await delay();
|
||||
// statusBeforeCodeGen = await getApplicationStatus(applicationUUID, adminToken);
|
||||
// log(9, `Status after admin transition: ${statusBeforeCodeGen}`);
|
||||
// }
|
||||
|
||||
if (statusBeforeCodeGen !== 'LOI Issued' && statusBeforeCodeGen !== 'Dealer Code Generation') {
|
||||
throw new Error(`Cannot generate codes: expected LOI Issued/Dealer Code Generation, got ${statusBeforeCodeGen}`);
|
||||
}
|
||||
// if (statusBeforeCodeGen !== 'LOI Issued' && statusBeforeCodeGen !== 'Dealer Code Generation') {
|
||||
// throw new Error(`Cannot generate codes: expected LOI Issued/Dealer Code Generation, got ${statusBeforeCodeGen}`);
|
||||
// }
|
||||
|
||||
log(9, 'Admin Generating SAP Dealer Codes...');
|
||||
await apiRequest(`/onboarding/applications/${applicationUUID}/generate-codes`, 'POST', {}, adminToken);
|
||||
log(9, 'Dealer Codes Generated.');
|
||||
await delay();
|
||||
// log(9, 'Admin Generating SAP Dealer Codes...');
|
||||
// await apiRequest(`/onboarding/applications/${applicationUUID}/generate-codes`, 'POST', {}, adminToken);
|
||||
// log(9, 'Dealer Codes Generated.');
|
||||
// await delay();
|
||||
|
||||
// 10. FIRST FILL (POST CODE-GENERATION)
|
||||
log(10, 'Finance Verifying FIRST FILL (₹15L)...');
|
||||
await apiRequest('/loa/security-deposit', 'POST', {
|
||||
applicationId: applicationUUID,
|
||||
amount: 1500000,
|
||||
paymentReference: 'PAY-FIN-999',
|
||||
depositType: 'FIRST_FILL',
|
||||
status: 'Verified'
|
||||
}, financeToken);
|
||||
log(10, 'Final Security Deposit Verified.');
|
||||
await delay();
|
||||
// // 10. FIRST FILL (POST CODE-GENERATION)
|
||||
// log(10, 'Finance Verifying FIRST FILL (₹15L)...');
|
||||
// await apiRequest('/loa/security-deposit', 'POST', {
|
||||
// applicationId: applicationUUID,
|
||||
// amount: 1500000,
|
||||
// paymentReference: 'PAY-FIN-999',
|
||||
// depositType: 'FIRST_FILL',
|
||||
// status: 'Verified'
|
||||
// }, financeToken);
|
||||
// log(10, 'Final Security Deposit Verified.');
|
||||
// await delay();
|
||||
|
||||
// 11. ADMIN UPDATING STATUTORY & BANK DETAILS
|
||||
log(11, 'Admin Updating Statutory & Bank Details for LOA Approval Gate...');
|
||||
await apiRequest(`/onboarding/applications/${applicationUUID}`, 'PUT', {
|
||||
accountHolderName: 'Ramesh Automobiles Private Limited',
|
||||
panNumber: 'ABCDE1234F',
|
||||
gstNumber: '07ABCDE1234F1Z5',
|
||||
bankName: 'HDFC Bank',
|
||||
accountNumber: '50100223344556',
|
||||
ifscCode: 'HDFC0001234'
|
||||
}, adminToken);
|
||||
log(11, 'Statutory & Bank details updated.');
|
||||
await delay();
|
||||
// // 11. ADMIN UPDATING STATUTORY & BANK DETAILS
|
||||
// log(11, 'Admin Updating Statutory & Bank Details for LOA Approval Gate...');
|
||||
// await apiRequest(`/onboarding/applications/${applicationUUID}`, 'PUT', {
|
||||
// accountHolderName: 'Ramesh Automobiles Private Limited',
|
||||
// panNumber: 'ABCDE1234F',
|
||||
// gstNumber: '07ABCDE1234F1Z5',
|
||||
// bankName: 'HDFC Bank',
|
||||
// accountNumber: '50100223344556',
|
||||
// ifscCode: 'HDFC0001234'
|
||||
// }, adminToken);
|
||||
// log(11, 'Statutory & Bank details updated.');
|
||||
// await delay();
|
||||
|
||||
// 12. FINAL LOA APPROVAL
|
||||
log(12, 'NBH & Head Approving Final LOA...');
|
||||
const loaRes = await apiRequest('/loa/request', 'POST', { applicationId: applicationUUID }, headToken);
|
||||
const finalLoaRequestId = loaRes.data.id;
|
||||
// // 12. FINAL LOA APPROVAL
|
||||
// log(12, 'NBH & Head Approving Final LOA...');
|
||||
// const loaRes = await apiRequest('/loa/request', 'POST', { applicationId: applicationUUID }, headToken);
|
||||
// const finalLoaRequestId = loaRes.data.id;
|
||||
|
||||
await apiRequest(`/loa/request/${finalLoaRequestId}/approve`, 'POST', {
|
||||
action: 'Approved',
|
||||
remarks: 'Head Authorization (Level 1)'
|
||||
}, headToken);
|
||||
// await apiRequest(`/loa/request/${finalLoaRequestId}/approve`, 'POST', {
|
||||
// action: 'Approved',
|
||||
// remarks: 'Head Authorization (Level 1)'
|
||||
// }, headToken);
|
||||
|
||||
await apiRequest(`/loa/request/${finalLoaRequestId}/approve`, 'POST', {
|
||||
action: 'Approved',
|
||||
remarks: 'NBH Approval (Level 2)'
|
||||
}, nbhToken);
|
||||
log(12, 'LOA Fully Approved.');
|
||||
await delay();
|
||||
// await apiRequest(`/loa/request/${finalLoaRequestId}/approve`, 'POST', {
|
||||
// action: 'Approved',
|
||||
// remarks: 'NBH Approval (Level 2)'
|
||||
// }, nbhToken);
|
||||
// log(12, 'LOA Fully Approved.');
|
||||
// await delay();
|
||||
|
||||
// 13. EOR (EVIDENCE OF READINESS) CHECKLIST VERIFICATION
|
||||
log(13, 'Admin Initializing EOR Checklist (100% Readiness Requirement)...');
|
||||
const eorInit = await apiRequest('/eor', 'POST', { applicationId: applicationUUID }, adminToken);
|
||||
const checklistId = eorInit.data.id;
|
||||
log(13, `EOR Checklist Created (ID: ${checklistId})`);
|
||||
// // 13. EOR (EVIDENCE OF READINESS) CHECKLIST VERIFICATION
|
||||
// log(13, 'Admin Initializing EOR Checklist (100% Readiness Requirement)...');
|
||||
// const eorInit = await apiRequest('/eor', 'POST', { applicationId: applicationUUID }, adminToken);
|
||||
// const checklistId = eorInit.data.id;
|
||||
// log(13, `EOR Checklist Created (ID: ${checklistId})`);
|
||||
|
||||
log(13.1, 'Auditor Verifying all 12 mandatory EOR items as COMPLIANT...');
|
||||
const eorItems = [
|
||||
{ itemType: 'Sales', description: 'Sales Standards' },
|
||||
{ itemType: 'Service', description: 'Service & Spares' },
|
||||
{ itemType: 'IT', description: 'DMS infra' },
|
||||
{ itemType: 'Training', description: 'Manpower Training' },
|
||||
{ itemType: 'Statutory', description: 'Trade certificate with test ride bikes registration' },
|
||||
{ itemType: 'Statutory', description: 'GST certificate including Accessories & Apparels billing' },
|
||||
{ itemType: 'Finance', description: 'Inventory Funding' },
|
||||
{ itemType: 'IT', description: 'Virtual code availability' },
|
||||
{ itemType: 'Finance', description: 'Vendor payments' },
|
||||
{ itemType: 'Marketing', description: 'Details for website submission' },
|
||||
{ itemType: 'Insurance', description: 'Infra Insurance both Showroom and Service center' },
|
||||
{ itemType: 'IT', description: 'Auto ordering' }
|
||||
];
|
||||
// log(13.1, 'Auditor Verifying all 12 mandatory EOR items as COMPLIANT...');
|
||||
// const eorItems = [
|
||||
// { itemType: 'Sales', description: 'Sales Standards' },
|
||||
// { itemType: 'Service', description: 'Service & Spares' },
|
||||
// { itemType: 'IT', description: 'DMS infra' },
|
||||
// { itemType: 'Training', description: 'Manpower Training' },
|
||||
// { itemType: 'Statutory', description: 'Trade certificate with test ride bikes registration' },
|
||||
// { itemType: 'Statutory', description: 'GST certificate including Accessories & Apparels billing' },
|
||||
// { itemType: 'Finance', description: 'Inventory Funding' },
|
||||
// { itemType: 'IT', description: 'Virtual code availability' },
|
||||
// { itemType: 'Finance', description: 'Vendor payments' },
|
||||
// { itemType: 'Marketing', description: 'Details for website submission' },
|
||||
// { itemType: 'Insurance', description: 'Infra Insurance both Showroom and Service center' },
|
||||
// { itemType: 'IT', description: 'Auto ordering' }
|
||||
// ];
|
||||
|
||||
for (const item of eorItems) {
|
||||
process.stdout.write(`.`); // Visual progress
|
||||
await apiRequest(`/eor/item/${checklistId}`, 'POST', {
|
||||
...item,
|
||||
isCompliant: true,
|
||||
remarks: 'Verified by Auditor - Compliant'
|
||||
}, adminToken);
|
||||
}
|
||||
console.log('\n[STEP 13.1] All EOR items marked as compliant.');
|
||||
// for (const item of eorItems) {
|
||||
// process.stdout.write(`.`); // Visual progress
|
||||
// await apiRequest(`/eor/item/${checklistId}`, 'POST', {
|
||||
// ...item,
|
||||
// isCompliant: true,
|
||||
// remarks: 'Verified by Auditor - Compliant'
|
||||
// }, adminToken);
|
||||
// }
|
||||
// console.log('\n[STEP 13.1] All EOR items marked as compliant.');
|
||||
|
||||
log(13.2, 'Auditor Submitting Final EOR Audit...');
|
||||
await apiRequest(`/eor/audit/${checklistId}`, 'POST', {
|
||||
status: 'Completed',
|
||||
overallComments: 'Dealer is 100% ready for inauguration. All infra and statutory items verified.'
|
||||
}, adminToken);
|
||||
// log(13.2, 'Auditor Submitting Final EOR Audit...');
|
||||
// await apiRequest(`/eor/audit/${checklistId}`, 'POST', {
|
||||
// status: 'Completed',
|
||||
// overallComments: 'Dealer is 100% ready for inauguration. All infra and statutory items verified.'
|
||||
// }, adminToken);
|
||||
|
||||
// Status check
|
||||
const finalAppStatus = await apiRequest(`/onboarding/applications/${applicationUUID}`, 'GET', null, adminToken);
|
||||
log(13.2, `Application Status after EOR: ${finalAppStatus.data.overallStatus}`);
|
||||
await delay();
|
||||
// // Status check
|
||||
// const finalAppStatus = await apiRequest(`/onboarding/applications/${applicationUUID}`, 'GET', null, adminToken);
|
||||
// log(13.2, `Application Status after EOR: ${finalAppStatus.data.overallStatus}`);
|
||||
// await delay();
|
||||
|
||||
// 14. FINAL ONBOARDING
|
||||
log(14, 'Admin Finalizing Dealer Onboarding...');
|
||||
await apiRequest('/dealers', 'POST', { applicationId: applicationUUID }, adminToken);
|
||||
await delay();
|
||||
// // 14. FINAL ONBOARDING
|
||||
// log(14, 'Admin Finalizing Dealer Onboarding...');
|
||||
// await apiRequest('/dealers', 'POST', { applicationId: applicationUUID }, adminToken);
|
||||
// await delay();
|
||||
|
||||
// 15. VERIFICATION
|
||||
log(15, 'Verifying Dealer Record Creation...');
|
||||
const dealerRes = await apiRequest(`/dealers/application/${applicationUUID}`, 'GET', null, adminToken);
|
||||
if (!dealerRes.success || !dealerRes.data) {
|
||||
throw new Error('Verification Failed: Dealer record not found after onboarding.');
|
||||
}
|
||||
log(15, `Dealer Found: ${dealerRes.data.legalName} (${dealerRes.data.id})`);
|
||||
// // 15. VERIFICATION
|
||||
// log(15, 'Verifying Dealer Record Creation...');
|
||||
// const dealerRes = await apiRequest(`/dealers/application/${applicationUUID}`, 'GET', null, adminToken);
|
||||
// if (!dealerRes.success || !dealerRes.data) {
|
||||
// throw new Error('Verification Failed: Dealer record not found after onboarding.');
|
||||
// }
|
||||
// log(15, `Dealer Found: ${dealerRes.data.legalName} (${dealerRes.data.id})`);
|
||||
|
||||
log(15.1, 'Verifying User Account Role Update...');
|
||||
const userRes = await apiRequest(`/admin/users`, 'GET', null, adminToken);
|
||||
const dealerUser = userRes.data.find(u => u.email === PROSPECT_EMAIL);
|
||||
if (!dealerUser || dealerUser.roleCode !== 'Dealer') {
|
||||
throw new Error(`Verification Failed: User role not updated to 'Dealer'. Current role: ${dealerUser?.roleCode}`);
|
||||
}
|
||||
log(15.1, `User role confirmed: ${dealerUser.roleCode}`);
|
||||
// log(15.1, 'Verifying User Account Role Update...');
|
||||
// const userRes = await apiRequest(`/admin/users`, 'GET', null, adminToken);
|
||||
// const dealerUser = userRes.data.find(u => u.email === PROSPECT_EMAIL);
|
||||
// if (!dealerUser || dealerUser.roleCode !== 'Dealer') {
|
||||
// throw new Error(`Verification Failed: User role not updated to 'Dealer'. Current role: ${dealerUser?.roleCode}`);
|
||||
// }
|
||||
// log(15.1, `User role confirmed: ${dealerUser.roleCode}`);
|
||||
|
||||
log(15.2, '--- WORKFLOW COMPLETED SUCCESSFULLY! ---');
|
||||
log(15.2, `The application ${applicationId} is now at 'ONBOARDED' status and Dealer profile is active.`);
|
||||
// log(15.2, '--- WORKFLOW COMPLETED SUCCESSFULLY! ---');
|
||||
// log(15.2, `The application ${applicationId} is now at 'ONBOARDED' status and Dealer profile is active.`);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
Reference in New Issue
Block a user