forked from Shared/esg
Added car by motor
This commit is contained in:
+249
-21
@@ -10,6 +10,11 @@
|
||||
batchRunning: false,
|
||||
batchStopRequested: false,
|
||||
batchResults: [],
|
||||
batchEndpoints: [],
|
||||
batchRecords: [],
|
||||
batchRowEntries: new Map(),
|
||||
batchCompleted: 0,
|
||||
batchTotal: 0,
|
||||
};
|
||||
const $ = (id) => document.getElementById(id);
|
||||
|
||||
@@ -74,6 +79,13 @@
|
||||
{ key: 'chassisNo', label: 'Chassis / VIN', example: 'IRFC89R2VSY976455', required: true, description: 'Vehicle chassis number or VIN' },
|
||||
],
|
||||
},
|
||||
carByMotor: {
|
||||
description: 'CarByMotorRequestDto — owner national code and motor/engine number.',
|
||||
fields: [
|
||||
{ key: 'nationalCode', label: 'National code', example: '4311402422', required: true, description: 'Owner national code (10 digits)', pattern: '\\d{10}' },
|
||||
{ key: 'motorNo', label: 'Motor number', example: '147H0403219', required: true, description: 'Vehicle motor/engine number' },
|
||||
],
|
||||
},
|
||||
thirdPartyCar: {
|
||||
description: 'Uses CarByPlateRequestDto for the third-party car route.',
|
||||
fields: [
|
||||
@@ -438,6 +450,7 @@
|
||||
const raw = value && typeof value === 'object' ? value : {};
|
||||
const source = (raw.request && typeof raw.request === 'object' ? raw.request : raw.payload && typeof raw.payload === 'object' ? raw.payload : raw);
|
||||
const plateObject = source.plate && typeof source.plate === 'object' ? source.plate : {};
|
||||
const vehicleObject = source.vehicle && typeof source.vehicle === 'object' ? source.vehicle : {};
|
||||
const directPlate = firstValue(source, ['plate', 'Plate', 'licensePlate', 'license_plate']);
|
||||
const plateText = directPlate && typeof directPlate === 'object' ? firstValue(plateObject, ['value', 'number']) : (directPlate ?? firstValue(plateObject, ['value', 'number']));
|
||||
let plk1 = firstValue(source, ['plk1', 'Plk1', 'plk01', 'platePart1', 'plate1', 'plaque_2', 'پلاک1']);
|
||||
@@ -451,19 +464,31 @@
|
||||
plk1 = plk1 ?? plateMatch[1]; plk2 = plk2 ?? plateMatch[2]; plk3 = plk3 ?? plateMatch[3]; plksrl = plksrl ?? plateMatch[4];
|
||||
}
|
||||
}
|
||||
const payload = {
|
||||
nationalCode: String(firstValue(source, ['nationalCode', 'NationalCode', 'national_code', 'nationalId', 'NationalId', 'NIN', 'nin', 'کدملی', 'کد ملی']) ?? '').trim(),
|
||||
const nationalCode = String(firstValue(source, ['nationalCode', 'NationalCode', 'national_code', 'nationalId', 'NationalId', 'NIN', 'nin', 'کدملی', 'کد ملی']) ?? '').trim();
|
||||
const chassisNo = String(firstValue(source, ['chassisNo', 'ChassisNo', 'chassis_no', 'chassis', 'vin', 'VIN', 'vinNumber', 'vin_number', 'شماره شاسی', 'شاسی']) ?? firstValue(vehicleObject, ['chassisNo', 'ChassisNo', 'chassis', 'vin', 'VIN']) ?? '').trim();
|
||||
const motorNo = String(firstValue(source, ['motorNo', 'MotorNo', 'motor_no', 'motorNumber', 'motor_number', 'engineNo', 'EngineNo', 'engineNumber', 'engine_number', 'شماره موتور', 'موتور']) ?? firstValue(vehicleObject, ['motorNo', 'MotorNo', 'motorNumber', 'engineNo', 'EngineNo', 'engineNumber']) ?? '').trim();
|
||||
const platePayload = {
|
||||
nationalCode,
|
||||
plk1: String(plk1 ?? firstValue(plateObject, ['plk1', 'Plk1', 'part1']) ?? '').trim(),
|
||||
plk2: String(plk2 ?? firstValue(plateObject, ['plk2', 'Plk2', 'letter']) ?? '').trim(),
|
||||
plk3: String(plk3 ?? firstValue(plateObject, ['plk3', 'Plk3', 'part3']) ?? '').trim(),
|
||||
plksrl: String(plksrl ?? firstValue(plateObject, ['plksrl', 'PlkSrl', 'serial']) ?? '').trim(),
|
||||
};
|
||||
const missing = Object.entries(payload).filter(([, item]) => !item).map(([key]) => key);
|
||||
const chassisPayload = { nationalCode, chassisNo };
|
||||
const motorPayload = { nationalCode, motorNo };
|
||||
const missingFor = (payload) => Object.entries(payload).filter(([, item]) => !item).map(([key]) => key);
|
||||
const plateMissing = missingFor(platePayload);
|
||||
const chassisMissing = missingFor(chassisPayload);
|
||||
const motorMissing = missingFor(motorPayload);
|
||||
return {
|
||||
index: index + 1,
|
||||
raw,
|
||||
payload,
|
||||
parseError: missing.length > 0 ? `Missing field(s): ${missing.join(', ')}` : undefined,
|
||||
payloads: { carByPlate: platePayload, carByChassis: chassisPayload, carByMotor: motorPayload },
|
||||
parseErrors: {
|
||||
carByPlate: plateMissing.length > 0 ? `Missing plate field(s): ${plateMissing.join(', ')}` : undefined,
|
||||
carByChassis: chassisMissing.length > 0 ? `Missing chassis field(s): ${chassisMissing.join(', ')}` : undefined,
|
||||
carByMotor: motorMissing.length > 0 ? `Missing motor field(s): ${motorMissing.join(', ')}` : undefined,
|
||||
},
|
||||
};
|
||||
}
|
||||
function parseBatchInput(text) {
|
||||
@@ -479,23 +504,152 @@
|
||||
if (!records.length) throw new Error('Batch input contains no records.');
|
||||
return records.map(normalizeBatchRecord);
|
||||
}
|
||||
const NO_MATCH_CODES = ['NO_MATCH', 'INQUIRY_NO_MATCH', 'CAR_POLICY_NOT_FOUND', 'RECORD_NOT_FOUND', 'REAL_ESTATE_NOT_FOUND', 'SHAHKAR_NO_MATCH', 'SHEBA_MISMATCH'];
|
||||
|
||||
function selectedBatchEndpoints() {
|
||||
return Array.from(document.querySelectorAll('input[name="batchEndpoint"]:checked')).map((input) => input.value);
|
||||
const mode = $('batchInquiryMode').value;
|
||||
if (mode === 'both') return ['carByPlate', 'carByChassis'];
|
||||
if (mode === 'all') return ['carByPlate', 'carByChassis', 'carByMotor'];
|
||||
return [mode];
|
||||
}
|
||||
function batchEndpointLabel(endpoint) {
|
||||
if (endpoint === 'carByPlate') return 'Plate';
|
||||
if (endpoint === 'carByChassis') return 'Chassis / VIN';
|
||||
if (endpoint === 'carByMotor') return 'Motor';
|
||||
return endpoint || '—';
|
||||
}
|
||||
function isNoMatchStatus(status) {
|
||||
return NO_MATCH_CODES.includes(status);
|
||||
}
|
||||
function latestBatchResult(recordIndex, endpoint) {
|
||||
for (let index = state.batchResults.length - 1; index >= 0; index -= 1) {
|
||||
const result = state.batchResults[index];
|
||||
if (result.index === recordIndex && result.endpoint === endpoint) return result;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
function getPlateVinCoverage(recordIndex) {
|
||||
const plate = latestBatchResult(recordIndex, 'carByPlate');
|
||||
const chassis = latestBatchResult(recordIndex, 'carByChassis');
|
||||
const motor = latestBatchResult(recordIndex, 'carByMotor');
|
||||
let status = 'pending';
|
||||
if (plate?.status === 'SUCCESS' || chassis?.status === 'SUCCESS') status = 'answered';
|
||||
else if (plate && chassis && isNoMatchStatus(plate.status) && isNoMatchStatus(chassis.status)) status = 'unanswered';
|
||||
else if (plate && chassis) status = 'inconclusive';
|
||||
return { status, plate, chassis, motor, motorRecovered: status === 'unanswered' && motor?.status === 'SUCCESS' };
|
||||
}
|
||||
function activeBatchEndpoints() {
|
||||
return state.batchEndpoints.length ? state.batchEndpoints : selectedBatchEndpoints();
|
||||
}
|
||||
function hasPlateVinCoverageMode() {
|
||||
const selected = activeBatchEndpoints();
|
||||
return selected.includes('carByPlate') && selected.includes('carByChassis');
|
||||
}
|
||||
function coverageBadge(text, className) {
|
||||
const badge = document.createElement('span');
|
||||
badge.className = `coverage-badge ${className || ''}`.trim();
|
||||
badge.textContent = text;
|
||||
return badge;
|
||||
}
|
||||
function applyCoverageFilter() {
|
||||
const unansweredOnly = $('batchUnansweredOnly').checked;
|
||||
state.batchRowEntries.forEach((entries, recordIndex) => {
|
||||
const coverage = getPlateVinCoverage(recordIndex);
|
||||
const hidden = unansweredOnly && coverage.status !== 'unanswered';
|
||||
entries.forEach(({ row, detailRow }) => {
|
||||
row.classList.toggle('coverage-filtered', hidden);
|
||||
detailRow.classList.toggle('coverage-filtered', hidden);
|
||||
});
|
||||
});
|
||||
}
|
||||
function renderRecordCoverage(recordIndex) {
|
||||
const entries = state.batchRowEntries.get(recordIndex) || [];
|
||||
if (!entries.length || !hasPlateVinCoverageMode()) return;
|
||||
const coverage = getPlateVinCoverage(recordIndex);
|
||||
const record = state.batchRecords.find((item) => item.index === recordIndex);
|
||||
const styleClass = coverage.motorRecovered ? 'record-motor-recovered' : `record-${coverage.status}`;
|
||||
|
||||
entries.forEach(({ row, detailRow, actionCell, result }) => {
|
||||
row.classList.remove('record-pending', 'record-answered', 'record-unanswered', 'record-inconclusive', 'record-motor-recovered');
|
||||
detailRow.classList.remove('record-pending', 'record-answered', 'record-unanswered', 'record-inconclusive', 'record-motor-recovered');
|
||||
row.classList.add(styleClass);
|
||||
detailRow.classList.add(styleClass);
|
||||
row.dataset.coverage = coverage.status;
|
||||
actionCell.replaceChildren();
|
||||
|
||||
if (result.endpoint === 'carByMotor') {
|
||||
actionCell.append(coverage.motorRecovered
|
||||
? coverageBadge('Recovered by motor', 'coverage-recovered')
|
||||
: coverageBadge(result.status === 'SUCCESS' ? 'Motor found' : isNoMatchStatus(result.status) ? 'Motor no-match' : 'Motor inconclusive', result.status === 'SUCCESS' ? 'coverage-good' : 'coverage-bad'));
|
||||
}
|
||||
});
|
||||
|
||||
const target = entries.find((entry) => entry.result.endpoint === 'carByChassis')
|
||||
|| entries.find((entry) => entry.result.endpoint === 'carByPlate');
|
||||
if (!target) return;
|
||||
|
||||
if (coverage.status === 'answered') {
|
||||
const source = coverage.plate?.status === 'SUCCESS' && coverage.chassis?.status === 'SUCCESS'
|
||||
? 'Plate + VIN'
|
||||
: coverage.plate?.status === 'SUCCESS' ? 'Plate' : 'VIN';
|
||||
target.actionCell.append(coverageBadge(`Answered by ${source}`, 'coverage-good'));
|
||||
} else if (coverage.status === 'unanswered') {
|
||||
target.actionCell.append(coverageBadge('No plate/VIN answer', 'coverage-bad'));
|
||||
if (coverage.motor) {
|
||||
target.actionCell.append(coverage.motorRecovered
|
||||
? coverageBadge('Motor found', 'coverage-recovered')
|
||||
: coverageBadge(isNoMatchStatus(coverage.motor.status) ? 'Motor no-match' : 'Motor inconclusive', 'coverage-bad'));
|
||||
} else if (activeBatchEndpoints().includes('carByMotor')) {
|
||||
target.actionCell.append(coverageBadge('Motor pending', 'coverage-pending'));
|
||||
} else if (record?.parseErrors.carByMotor) {
|
||||
target.actionCell.append(coverageBadge('Motor number unavailable', 'coverage-pending'));
|
||||
} else {
|
||||
const button = document.createElement('button');
|
||||
button.type = 'button';
|
||||
button.className = 'motor-follow-up';
|
||||
button.textContent = 'Test motor';
|
||||
button.addEventListener('click', (event) => {
|
||||
event.stopPropagation();
|
||||
runMotorFollowUp(recordIndex, button);
|
||||
});
|
||||
target.actionCell.append(button);
|
||||
}
|
||||
} else if (coverage.status === 'inconclusive') {
|
||||
target.actionCell.append(coverageBadge('Plate/VIN inconclusive', 'coverage-pending'));
|
||||
} else {
|
||||
target.actionCell.append(coverageBadge('Waiting for both', 'coverage-pending'));
|
||||
}
|
||||
|
||||
applyCoverageFilter();
|
||||
}
|
||||
function addBatchResult(result) {
|
||||
state.batchResults.push(result);
|
||||
const row = document.createElement('tr');
|
||||
row.className = 'data-row'; row.tabIndex = 0; row.setAttribute('aria-expanded', 'false');
|
||||
const inputLabel = result.payload ? `${result.payload.nationalCode} / ${result.payload.plk1}${result.payload.plk2}${result.payload.plk3}${result.payload.plksrl}` : '—';
|
||||
const values = [result.index, inputLabel, result.endpoint || '—', result.status, result.trackingCode || '—', result.message || '—'];
|
||||
row.dataset.recordIndex = String(result.index);
|
||||
const vehicleIdentity = result.endpoint === 'carByChassis'
|
||||
? result.payload?.chassisNo
|
||||
: result.endpoint === 'carByMotor'
|
||||
? result.payload?.motorNo
|
||||
: result.payload
|
||||
? `${result.payload.plk1}${result.payload.plk2}${result.payload.plk3}${result.payload.plksrl}`
|
||||
: '';
|
||||
const carTitle = firstValue(result.inputRecord, ['car_title', 'carTitle', 'title', 'vehicleTitle']);
|
||||
const identityLabel = result.payload ? `${result.payload.nationalCode} / ${vehicleIdentity || '—'}` : '—';
|
||||
const inputLabel = carTitle ? `${carTitle} · ${identityLabel}` : identityLabel;
|
||||
const endpointLabel = batchEndpointLabel(result.endpoint);
|
||||
const values = [result.index, inputLabel, endpointLabel, result.status, result.trackingCode || '—', result.message || '—'];
|
||||
values.forEach((value, index) => {
|
||||
const cell = document.createElement('td');
|
||||
if (index === 0) { const toggle = document.createElement('span'); toggle.className = 'row-toggle'; toggle.textContent = '▶'; toggle.setAttribute('aria-hidden', 'true'); cell.append(toggle); }
|
||||
cell.append(document.createTextNode(value));
|
||||
if (index === 3) { const noMatch = ['NO_MATCH', 'INQUIRY_NO_MATCH', 'CAR_POLICY_NOT_FOUND', 'RECORD_NOT_FOUND', 'REAL_ESTATE_NOT_FOUND', 'SHAHKAR_NO_MATCH', 'SHEBA_MISMATCH'].includes(result.status); cell.className = result.status === 'SUCCESS' ? 'status-success' : (noMatch ? 'status-neutral' : 'status-failure'); }
|
||||
if (index === 3) cell.className = result.status === 'SUCCESS' ? 'status-success' : (isNoMatchStatus(result.status) ? 'status-neutral' : 'status-failure');
|
||||
row.appendChild(cell);
|
||||
});
|
||||
const detailRow = createDetailRow(6, result);
|
||||
const actionCell = document.createElement('td');
|
||||
actionCell.className = 'coverage-action';
|
||||
row.appendChild(actionCell);
|
||||
const detailRow = createDetailRow(7, result);
|
||||
bindDetailToggle(row, detailRow, () => {
|
||||
if (!result.trackingCode) return;
|
||||
request(`/inquiry-logs?trackingCode=${encodeURIComponent(result.trackingCode)}&limit=1&page=1`)
|
||||
@@ -507,11 +661,78 @@
|
||||
})
|
||||
.catch(() => undefined);
|
||||
});
|
||||
if (!state.batchRowEntries.has(result.index)) state.batchRowEntries.set(result.index, []);
|
||||
state.batchRowEntries.get(result.index).push({ row, detailRow, actionCell, result });
|
||||
$('batchResultsBody').append(row, detailRow);
|
||||
renderRecordCoverage(result.index);
|
||||
}
|
||||
function updateBatchSummary(completed, total) {
|
||||
$('batchProgress').value = total ? completed / total : 0;
|
||||
const success = state.batchResults.filter((item) => item.status === 'SUCCESS').length; const noMatch = state.batchResults.filter((item) => ['NO_MATCH', 'INQUIRY_NO_MATCH', 'CAR_POLICY_NOT_FOUND', 'RECORD_NOT_FOUND', 'REAL_ESTATE_NOT_FOUND', 'SHAHKAR_NO_MATCH', 'SHEBA_MISMATCH'].includes(item.status)).length; const operational = completed - success - noMatch; $('batchSummary').textContent = `${completed} / ${total} completed · ${success} success · ${noMatch} no-match · ${operational} operational failure${operational === 1 ? '' : 's'}`;
|
||||
state.batchCompleted = completed;
|
||||
state.batchTotal = total;
|
||||
$('batchProgress').value = total ? Math.min(1, completed / total) : 0;
|
||||
const counts = (items) => {
|
||||
const success = items.filter((item) => item.status === 'SUCCESS').length;
|
||||
const noMatch = items.filter((item) => isNoMatchStatus(item.status)).length;
|
||||
const invalid = items.filter((item) => item.status === 'INVALID_INPUT').length;
|
||||
return { success, noMatch, invalid, operational: items.length - success - noMatch - invalid };
|
||||
};
|
||||
const selected = activeBatchEndpoints();
|
||||
const selectedResults = state.batchResults.filter((item) => selected.includes(item.endpoint));
|
||||
const overall = counts(selectedResults);
|
||||
const methodBreakdown = selected.length > 1
|
||||
? selected.map((endpoint) => {
|
||||
const label = batchEndpointLabel(endpoint);
|
||||
const method = counts(selectedResults.filter((item) => item.endpoint === endpoint));
|
||||
return `${label}: ${method.success} success, ${method.noMatch} no-match, ${method.operational} failed${method.invalid ? `, ${method.invalid} invalid` : ''}`;
|
||||
}).join(' · ')
|
||||
: '';
|
||||
|
||||
if (hasPlateVinCoverageMode()) {
|
||||
const coverage = state.batchRecords.map((record) => getPlateVinCoverage(record.index));
|
||||
const answered = coverage.filter((item) => item.status === 'answered').length;
|
||||
const unanswered = coverage.filter((item) => item.status === 'unanswered').length;
|
||||
const inconclusive = coverage.filter((item) => item.status === 'inconclusive').length;
|
||||
const pending = coverage.filter((item) => item.status === 'pending').length;
|
||||
const motorRecovered = coverage.filter((item) => item.motorRecovered).length;
|
||||
const records = state.batchRecords.length;
|
||||
const percent = (value) => records ? `${((value / records) * 100).toFixed(1)}%` : '0.0%';
|
||||
$('batchCoverage').classList.remove('hidden');
|
||||
$('batchCoverageFilter').classList.remove('hidden');
|
||||
$('coverageAnswered').textContent = `${answered} / ${records}`;
|
||||
$('coverageAnsweredRate').textContent = percent(answered);
|
||||
$('coverageUnanswered').textContent = `${unanswered} / ${records}`;
|
||||
$('coverageUnansweredRate').textContent = percent(unanswered);
|
||||
$('coverageInconclusive').textContent = String(inconclusive);
|
||||
$('coverageMotorRecovered').textContent = String(motorRecovered);
|
||||
$('batchSummary').textContent = `${completed} / ${total} requests completed · Plate + VIN answered ${answered}/${records} (${percent(answered)}) · no answer from either ${unanswered}/${records} (${percent(unanswered)})${inconclusive ? ` · ${inconclusive} inconclusive` : ''}${pending ? ` · ${pending} pending` : ''} · ${methodBreakdown}`;
|
||||
} else {
|
||||
$('batchCoverage').classList.add('hidden');
|
||||
$('batchCoverageFilter').classList.add('hidden');
|
||||
$('batchUnansweredOnly').checked = false;
|
||||
$('batchSummary').textContent = `${completed} / ${total} completed · ${overall.success} success · ${overall.noMatch} no-match · ${overall.operational} operational failure${overall.operational === 1 ? '' : 's'}${overall.invalid ? ` · ${overall.invalid} invalid input${overall.invalid === 1 ? '' : 's'}` : ''}`;
|
||||
}
|
||||
}
|
||||
async function runMotorFollowUp(recordIndex, button) {
|
||||
const record = state.batchRecords.find((item) => item.index === recordIndex);
|
||||
if (!record || latestBatchResult(recordIndex, 'carByMotor')) return;
|
||||
button.disabled = true;
|
||||
button.textContent = 'Testing…';
|
||||
const payload = record.payloads.carByMotor;
|
||||
let result;
|
||||
try {
|
||||
const body = await request('/inquiry/carByMotor', {
|
||||
method: 'POST',
|
||||
headers: { 'Idempotency-Key': `batch-followup-${Date.now()}-${record.index}-carByMotor` },
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
result = { index: record.index, payload, endpoint: 'carByMotor', status: body.success ? 'SUCCESS' : (body.error?.code || 'NO_MATCH'), trackingCode: body.trackingCode, message: body.success ? (body.message || 'Completed') : (body.error?.messageFa || body.error?.message || 'Inquiry returned no result'), response: body };
|
||||
} catch (error) {
|
||||
result = { index: record.index, payload, endpoint: 'carByMotor', status: 'REQUEST_ERROR', message: error.message, response: error.body };
|
||||
}
|
||||
result.inputRecord = record.raw;
|
||||
addBatchResult(result);
|
||||
updateBatchSummary(state.batchCompleted, state.batchTotal);
|
||||
await Promise.allSettled([loadMetrics(), loadLogs()]);
|
||||
}
|
||||
function wait(milliseconds) {
|
||||
return milliseconds > 0 ? new Promise((resolve) => setTimeout(resolve, milliseconds)) : Promise.resolve();
|
||||
@@ -519,7 +740,6 @@
|
||||
async function runBatchTest() {
|
||||
if (state.batchRunning) return;
|
||||
const endpoints = selectedBatchEndpoints();
|
||||
if (!endpoints.length) { showError('Select at least one plate endpoint.', 'appError'); return; }
|
||||
let records;
|
||||
try { records = parseBatchInput($('batchPayload').value.trim()); } catch (error) { showError(error.message, 'appError'); return; }
|
||||
const delay = Math.min(10000, Math.max(0, Number($('batchDelay').value) || 0));
|
||||
@@ -527,32 +747,39 @@
|
||||
if (total > 50 && !window.confirm(`Run ${total} requests (${records.length} record(s) × ${endpoints.length} endpoint(s))?`)) return;
|
||||
let completed = 0;
|
||||
state.batchRunning = true; state.batchStopRequested = false; state.batchResults = [];
|
||||
$('batchResultsBody').replaceChildren(); $('batchOutput').textContent = 'Running batch… click any completed row to inspect its response.'; $('batchProgress').classList.remove('hidden'); $('runBatchButton').disabled = true; $('stopBatchButton').classList.remove('hidden');
|
||||
state.batchEndpoints = endpoints; state.batchRecords = records; state.batchRowEntries = new Map(); state.batchCompleted = 0; state.batchTotal = total;
|
||||
$('batchUnansweredOnly').checked = false;
|
||||
$('batchResultsBody').replaceChildren(); $('batchOutput').textContent = 'Running batch… plate + VIN coverage updates as each pair completes.'; $('batchProgress').classList.remove('hidden'); $('runBatchButton').disabled = true; $('batchInquiryMode').disabled = true; $('stopBatchButton').classList.remove('hidden');
|
||||
updateBatchSummary(0, total);
|
||||
try {
|
||||
for (const record of records) {
|
||||
for (const endpoint of endpoints) {
|
||||
if (state.batchStopRequested) break;
|
||||
let result;
|
||||
if (record.parseError) {
|
||||
result = { index: record.index, payload: record.payload, endpoint, status: 'INVALID_INPUT', message: record.parseError };
|
||||
const payload = record.payloads[endpoint];
|
||||
const parseError = record.parseErrors[endpoint];
|
||||
if (parseError) {
|
||||
result = { index: record.index, payload, endpoint, status: 'INVALID_INPUT', message: parseError };
|
||||
} else {
|
||||
try {
|
||||
const body = await request('/inquiry/' + endpoint, { method: 'POST', headers: { 'Idempotency-Key': `batch-${Date.now()}-${record.index}-${endpoint}` }, body: JSON.stringify(record.payload) });
|
||||
result = { index: record.index, payload: record.payload, endpoint, status: body.success ? 'SUCCESS' : (body.error?.code || 'NO_MATCH'), trackingCode: body.trackingCode, message: body.success ? (body.message || 'Completed') : (body.error?.messageFa || body.error?.message || 'Inquiry returned no result'), response: body };
|
||||
const body = await request('/inquiry/' + endpoint, { method: 'POST', headers: { 'Idempotency-Key': `batch-${Date.now()}-${record.index}-${endpoint}` }, body: JSON.stringify(payload) });
|
||||
result = { index: record.index, payload, endpoint, status: body.success ? 'SUCCESS' : (body.error?.code || 'NO_MATCH'), trackingCode: body.trackingCode, message: body.success ? (body.message || 'Completed') : (body.error?.messageFa || body.error?.message || 'Inquiry returned no result'), response: body };
|
||||
} catch (error) {
|
||||
result = { index: record.index, payload: record.payload, endpoint, status: 'REQUEST_ERROR', message: error.message, response: error.body };
|
||||
result = { index: record.index, payload, endpoint, status: 'REQUEST_ERROR', message: error.message, response: error.body };
|
||||
}
|
||||
}
|
||||
result.inputRecord = record.raw;
|
||||
addBatchResult(result); completed += 1; updateBatchSummary(completed, total); await wait(delay);
|
||||
}
|
||||
if (state.batchStopRequested) break;
|
||||
}
|
||||
$('batchOutput').textContent = 'Batch finished. Click any row to inspect its full request and response.';
|
||||
$('batchOutput').textContent = hasPlateVinCoverageMode()
|
||||
? 'Batch finished. Green records were answered by plate or VIN; red records had no answer from either. Use Test motor on a red record for a targeted follow-up.'
|
||||
: 'Batch finished. Click any row to inspect its full request and response.';
|
||||
if (state.batchStopRequested) $('batchSummary').textContent += ' · stopped by user';
|
||||
await Promise.allSettled([loadMetrics(), loadLogs()]);
|
||||
} finally {
|
||||
state.batchRunning = false; state.batchStopRequested = false; $('runBatchButton').disabled = false; $('stopBatchButton').disabled = false; $('stopBatchButton').classList.add('hidden');
|
||||
state.batchRunning = false; state.batchStopRequested = false; $('runBatchButton').disabled = false; $('batchInquiryMode').disabled = false; $('stopBatchButton').disabled = false; $('stopBatchButton').classList.add('hidden');
|
||||
}
|
||||
}
|
||||
async function clearInquiryLogs() {
|
||||
@@ -629,6 +856,7 @@
|
||||
try { $('batchPayload').value = await file.text(); $('batchOutput').textContent = `Loaded ${file.name}. Click Run batch test to begin.`; } catch (_) { showError('Unable to read the selected batch file.', 'appError'); }
|
||||
});
|
||||
$('runBatchButton').addEventListener('click', runBatchTest);
|
||||
$('batchUnansweredOnly').addEventListener('change', applyCoverageFilter);
|
||||
$('stopBatchButton').addEventListener('click', () => { state.batchStopRequested = true; $('stopBatchButton').disabled = true; });
|
||||
setupCollapsiblePanels();
|
||||
$('idempotencyKey').value = newKey();
|
||||
|
||||
+21
-10
@@ -70,6 +70,7 @@
|
||||
<option value="legalPerson">Legal person</option>
|
||||
<option value="carByPlate">Car by plate</option>
|
||||
<option value="carByChassis">Car by chassis</option>
|
||||
<option value="carByMotor">Car by motor number</option>
|
||||
<option value="thirdPartyCar">Third-party car</option>
|
||||
<option value="policyByChassis">Policy by chassis</option>
|
||||
<option value="policyByPlate">Policy by plate</option>
|
||||
@@ -96,28 +97,38 @@
|
||||
</section>
|
||||
|
||||
<section class="panel">
|
||||
<div class="panel-heading"><div><p class="eyebrow">Batch input</p><h2>Test plate inquiries from JSON</h2></div></div>
|
||||
<p class="muted">Choose a JSON or TXT file, or paste a JSON array. For Parsian third-party plate inquiries, use <strong>Car by plate</strong>; the other routes remain available only for diagnostics.</p>
|
||||
<div class="panel-heading"><div><p class="eyebrow">Batch input</p><h2>Test vehicle inquiries from JSON</h2></div></div>
|
||||
<p class="muted">Choose plate, chassis/VIN, motor number, or a combined mode. Each lookup produces an independently expandable result with separate logs, traces, and cURLs.</p>
|
||||
<div class="batch-controls">
|
||||
<label>JSON/TXT file<input id="batchFile" type="file" accept=".json,.txt,application/json,text/plain" /></label>
|
||||
<label>Inquiry mode
|
||||
<select id="batchInquiryMode">
|
||||
<option value="carByPlate">By plate</option>
|
||||
<option value="carByChassis">By chassis / VIN</option>
|
||||
<option value="carByMotor">By motor number</option>
|
||||
<option value="both" selected>Plate and chassis</option>
|
||||
<option value="all">Plate, chassis, and motor</option>
|
||||
</select>
|
||||
</label>
|
||||
<label>Delay between requests (ms)<input id="batchDelay" type="number" min="0" max="10000" step="100" value="0" /></label>
|
||||
</div>
|
||||
<label class="wide">Input preview / paste JSON
|
||||
<textarea id="batchPayload" rows="8" spellcheck="false" placeholder='[{"nationalCode":"4311402422","plk1":"12","plk2":"ب","plk3":"345","plksrl":"67"}]'></textarea>
|
||||
<textarea id="batchPayload" rows="8" spellcheck="false" placeholder='[{"nationalCode":"4311402422","plk1":"12","plk2":"ب","plk3":"345","plksrl":"67","vin":"IRFC89R2VSY976455","motorNo":"147H0403219"}]'></textarea>
|
||||
</label>
|
||||
<div class="endpoint-list">
|
||||
<span class="muted">Endpoints</span>
|
||||
<label class="checkbox"><input type="checkbox" name="batchEndpoint" value="carByPlate" checked /> Car by plate</label>
|
||||
<label class="checkbox"><input type="checkbox" name="batchEndpoint" value="thirdPartyCar" /> Third-party car (diagnostic)</label>
|
||||
<label class="checkbox"><input type="checkbox" name="batchEndpoint" value="policyByPlate" /> Policy by plate (diagnostic)</label>
|
||||
</div>
|
||||
<div class="batch-actions">
|
||||
<button id="runBatchButton" class="primary" type="button">Run batch test</button>
|
||||
<button id="stopBatchButton" class="ghost hidden" type="button">Stop after current request</button>
|
||||
<span id="batchSummary" class="muted"></span>
|
||||
</div>
|
||||
<div id="batchCoverage" class="coverage-grid hidden" aria-live="polite">
|
||||
<article class="coverage-card coverage-card-good"><span>Answered by plate or VIN</span><strong id="coverageAnswered">0 / 0</strong><small id="coverageAnsweredRate">0.0%</small></article>
|
||||
<article class="coverage-card coverage-card-bad"><span>No answer from either</span><strong id="coverageUnanswered">0 / 0</strong><small id="coverageUnansweredRate">0.0%</small></article>
|
||||
<article class="coverage-card coverage-card-pending"><span>Inconclusive</span><strong id="coverageInconclusive">0</strong><small>failure or invalid input</small></article>
|
||||
<article class="coverage-card coverage-card-recovered"><span>Recovered by motor</span><strong id="coverageMotorRecovered">0</strong><small>plate + VIN still count as no-answer</small></article>
|
||||
</div>
|
||||
<label id="batchCoverageFilter" class="checkbox coverage-filter hidden"><input id="batchUnansweredOnly" type="checkbox" /> Show only records with no plate or VIN answer</label>
|
||||
<progress id="batchProgress" class="batch-progress hidden" max="1" value="0"></progress>
|
||||
<div class="table-wrap"><table><thead><tr><th>#</th><th>Input</th><th>Endpoint</th><th>Status</th><th>Tracking code</th><th>Message</th></tr></thead><tbody id="batchResultsBody"></tbody></table></div>
|
||||
<div class="table-wrap"><table><thead><tr><th>#</th><th>Input</th><th>Endpoint</th><th>Status</th><th>Tracking code</th><th>Message</th><th>Coverage / follow-up</th></tr></thead><tbody id="batchResultsBody"></tbody></table></div>
|
||||
<p id="batchOutput" class="table-hint" role="status">Click a request row to expand its full response.</p>
|
||||
</section>
|
||||
|
||||
|
||||
+30
-2
@@ -64,12 +64,25 @@ button:hover { filter: brightness(1.12); }
|
||||
.inquiry-form .wide, .inquiry-form button { grid-column: 1 / -1; }
|
||||
.request-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
|
||||
.form-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
|
||||
.batch-controls { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin: 18px 0; }
|
||||
.batch-controls { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; margin: 18px 0; }
|
||||
.endpoint-list { margin: 16px 0; }
|
||||
.checkbox { display: inline-flex; grid-template-columns: auto 1fr; align-items: center; gap: 7px; color: var(--text); font-weight: 600; }
|
||||
.checkbox input { width: auto; accent-color: var(--accent-strong); }
|
||||
.batch-actions { margin: 16px 0; }
|
||||
.batch-progress { width: 100%; height: 8px; margin: 4px 0 12px; accent-color: var(--accent-strong); }
|
||||
.coverage-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin: 14px 0; }
|
||||
.coverage-card { padding: 13px 14px; border: 1px solid var(--line); border-radius: 12px; background: rgba(6, 12, 26, .38); }
|
||||
.coverage-card span, .coverage-card small { display: block; color: var(--muted); font-size: 11px; }
|
||||
.coverage-card strong { display: inline-block; margin: 4px 8px 2px 0; font-size: 23px; }
|
||||
.coverage-card-good { border-color: rgba(101, 216, 178, .4); }
|
||||
.coverage-card-good strong { color: var(--accent); }
|
||||
.coverage-card-bad { border-color: rgba(255, 143, 143, .5); }
|
||||
.coverage-card-bad strong { color: var(--danger); }
|
||||
.coverage-card-pending { border-color: rgba(246, 200, 95, .42); }
|
||||
.coverage-card-pending strong { color: #f6c85f; }
|
||||
.coverage-card-recovered { border-color: rgba(129, 140, 248, .48); }
|
||||
.coverage-card-recovered strong { color: #a5b4fc; }
|
||||
.coverage-filter { margin: 10px 0; width: fit-content; }
|
||||
.field-hint { color: var(--muted); font-size: 11px; font-weight: 500; }
|
||||
#rawMode { display: grid; gap: 12px; }
|
||||
#rawMode button { justify-self: start; }
|
||||
@@ -111,6 +124,21 @@ tbody tr.data-row:focus { outline: 2px solid var(--accent); outline-offset: -2px
|
||||
.status-success { color: var(--accent); }
|
||||
.status-neutral { color: #f6c85f; }
|
||||
.status-failure { color: var(--danger); }
|
||||
tbody tr.record-answered > td { background: rgba(32, 180, 134, .055); }
|
||||
tbody tr.record-unanswered > td { background: rgba(255, 95, 95, .11); }
|
||||
tbody tr.record-unanswered > td:first-child { box-shadow: inset 3px 0 0 var(--danger); }
|
||||
tbody tr.record-inconclusive > td { background: rgba(246, 200, 95, .075); }
|
||||
tbody tr.record-inconclusive > td:first-child { box-shadow: inset 3px 0 0 #f6c85f; }
|
||||
tbody tr.record-motor-recovered > td { background: rgba(129, 140, 248, .11); }
|
||||
tbody tr.record-motor-recovered > td:first-child { box-shadow: inset 3px 0 0 #818cf8; }
|
||||
.coverage-filtered { display: none !important; }
|
||||
.coverage-action { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; min-width: 178px; }
|
||||
.coverage-badge { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 999px; padding: 4px 8px; color: var(--muted); font-size: 11px; font-weight: 800; }
|
||||
.coverage-good { border-color: rgba(101, 216, 178, .4); color: var(--accent); }
|
||||
.coverage-bad { border-color: rgba(255, 143, 143, .5); color: var(--danger); }
|
||||
.coverage-pending { border-color: rgba(246, 200, 95, .42); color: #f6c85f; }
|
||||
.coverage-recovered { border-color: rgba(129, 140, 248, .48); color: #a5b4fc; }
|
||||
.motor-follow-up { padding: 6px 10px; border: 1px solid rgba(129, 140, 248, .55); background: rgba(129, 140, 248, .13); color: #c7d2fe; font-size: 11px; font-weight: 800; }
|
||||
.error { min-height: 20px; color: var(--danger); }
|
||||
.banner { margin: 0 0 16px; }
|
||||
@media (max-width: 780px) { .shell { width: min(100% - 20px, 680px); padding-top: 20px; } .grid.two, .inquiry-form, .form-fields, .batch-controls, .metric-grid { grid-template-columns: 1fr; } .inquiry-form .wide, .inquiry-form button { grid-column: auto; } .request-toolbar { align-items: flex-start; flex-direction: column; } .topbar { align-items: flex-start; flex-direction: column; } .topbar-actions, .panel-actions { width: 100%; justify-content: space-between; } .panel { padding: 16px; } }
|
||||
@media (max-width: 780px) { .shell { width: min(100% - 20px, 680px); padding-top: 20px; } .grid.two, .inquiry-form, .form-fields, .batch-controls, .metric-grid, .coverage-grid { grid-template-columns: 1fr; } .inquiry-form .wide, .inquiry-form button { grid-column: auto; } .request-toolbar { align-items: flex-start; flex-direction: column; } .topbar { align-items: flex-start; flex-direction: column; } .topbar-actions, .panel-actions { width: 100%; justify-content: space-between; } .panel { padding: 16px; } }
|
||||
|
||||
Reference in New Issue
Block a user