99 lines
2.6 KiB
JavaScript
99 lines
2.6 KiB
JavaScript
#!/usr/bin/env node
|
|
/* eslint-disable no-console */
|
|
require('dotenv').config();
|
|
|
|
const axaBridge = require('../src/services/axaBridgeService');
|
|
|
|
function parseArgs(argv) {
|
|
const out = {
|
|
matricule: process.env.AXA_SMOKE_MATRICULE || 'SYSTEM',
|
|
numContrat: process.env.AXA_SMOKE_NUM_CONTRAT || '',
|
|
runQt550: false,
|
|
totalCotisation: process.env.AXA_SMOKE_TOTAL_COTISATION || '',
|
|
dateDebut: process.env.AXA_SMOKE_DATE_DEBUT || '',
|
|
dateFin: process.env.AXA_SMOKE_DATE_FIN || ''
|
|
};
|
|
|
|
for (let i = 0; i < argv.length; i += 1) {
|
|
const arg = argv[i];
|
|
if (arg === '--matricule' && argv[i + 1]) {
|
|
out.matricule = String(argv[++i]).trim();
|
|
continue;
|
|
}
|
|
if (arg === '--num-contrat' && argv[i + 1]) {
|
|
out.numContrat = String(argv[++i]).trim();
|
|
continue;
|
|
}
|
|
if (arg === '--run-qt550') {
|
|
out.runQt550 = true;
|
|
continue;
|
|
}
|
|
if (arg === '--total-cotisation' && argv[i + 1]) {
|
|
out.totalCotisation = String(argv[++i]).trim();
|
|
continue;
|
|
}
|
|
if (arg === '--date-debut' && argv[i + 1]) {
|
|
out.dateDebut = String(argv[++i]).trim();
|
|
continue;
|
|
}
|
|
if (arg === '--date-fin' && argv[i + 1]) {
|
|
out.dateFin = String(argv[++i]).trim();
|
|
continue;
|
|
}
|
|
}
|
|
|
|
return out;
|
|
}
|
|
|
|
async function main() {
|
|
const opts = parseArgs(process.argv.slice(2));
|
|
|
|
const health = await axaBridge.getHealth({ matricule: opts.matricule });
|
|
console.log(JSON.stringify({
|
|
step: 'health',
|
|
ok: health.ok,
|
|
helperReady: health.helperReady,
|
|
errors: health.errors
|
|
}, null, 2));
|
|
|
|
if (!health.ok) {
|
|
throw new Error('AXA health check failed.');
|
|
}
|
|
|
|
if (opts.numContrat) {
|
|
const lookup = await axaBridge.lookupContract({
|
|
matricule: opts.matricule,
|
|
numContrat: opts.numContrat
|
|
});
|
|
console.log(JSON.stringify({
|
|
step: 'lookup',
|
|
numContrat: lookup.numContrat,
|
|
numClient: lookup.numClient,
|
|
nomClient: lookup.nomClient,
|
|
numAgent: lookup.numAgent
|
|
}, null, 2));
|
|
}
|
|
|
|
if (opts.runQt550) {
|
|
if (!opts.numContrat || !opts.totalCotisation || !opts.dateDebut || !opts.dateFin) {
|
|
throw new Error('Missing required options for --run-qt550 (--num-contrat, --total-cotisation, --date-debut, --date-fin).');
|
|
}
|
|
await axaBridge.runQt550({
|
|
matricule: opts.matricule,
|
|
numContrat: opts.numContrat,
|
|
totalCotisation: opts.totalCotisation,
|
|
dateDebut: opts.dateDebut,
|
|
dateFin: opts.dateFin
|
|
});
|
|
console.log(JSON.stringify({
|
|
step: 'qt550',
|
|
ok: true
|
|
}, null, 2));
|
|
}
|
|
}
|
|
|
|
main().catch((error) => {
|
|
console.error(error.stack || error.message || String(error));
|
|
process.exit(1);
|
|
});
|