Initial commit: BI Agentes platform
Independent dashboard for CambioReal agents with local SQLite auth and read-only RDS connection. Features login, per-agent transaction filtering, KPIs, charts (Chart.js), and detailed transaction table. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
72
scripts/seed-agente.js
Normal file
72
scripts/seed-agente.js
Normal file
@@ -0,0 +1,72 @@
|
||||
/**
|
||||
* CLI para cadastrar agentes no SQLite
|
||||
*
|
||||
* Uso:
|
||||
* node scripts/seed-agente.js --email valorfx@cambioreal.com --senha 123456 --agente 76 --nome "ValorFx"
|
||||
*
|
||||
* Listar agentes:
|
||||
* node scripts/seed-agente.js --list
|
||||
*/
|
||||
require('dotenv').config({ path: require('path').join(__dirname, '..', '.env') });
|
||||
|
||||
const db = require('../src/db-local');
|
||||
const { createAgente } = require('../src/auth');
|
||||
|
||||
const args = process.argv.slice(2);
|
||||
|
||||
function getArg(name) {
|
||||
const idx = args.indexOf('--' + name);
|
||||
return idx !== -1 && args[idx + 1] ? args[idx + 1] : null;
|
||||
}
|
||||
|
||||
async function main() {
|
||||
// List mode
|
||||
if (args.includes('--list')) {
|
||||
const rows = db.prepare('SELECT id, email, agente_id, nome, ativo, created_at FROM agentes').all();
|
||||
if (!rows.length) {
|
||||
console.log('Nenhum agente cadastrado.');
|
||||
} else {
|
||||
console.log('\n ID | Agente ID | Nome | Email | Ativo | Criado em');
|
||||
console.log(' ' + '-'.repeat(95));
|
||||
rows.forEach(r => {
|
||||
console.log(` ${String(r.id).padEnd(3)}| ${String(r.agente_id).padEnd(10)}| ${r.nome.padEnd(19)}| ${r.email.padEnd(29)}| ${r.ativo ? 'Sim' : 'Nao'} | ${r.created_at}`);
|
||||
});
|
||||
}
|
||||
console.log();
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
// Create mode
|
||||
const email = getArg('email');
|
||||
const senha = getArg('senha');
|
||||
const agenteId = getArg('agente');
|
||||
const nome = getArg('nome');
|
||||
|
||||
if (!email || !senha || !agenteId || !nome) {
|
||||
console.log(`
|
||||
Uso: node scripts/seed-agente.js --email <email> --senha <senha> --agente <id> --nome "<nome>"
|
||||
|
||||
Exemplos:
|
||||
node scripts/seed-agente.js --email valorfx@cambioreal.com --senha 123456 --agente 76 --nome "ValorFx"
|
||||
node scripts/seed-agente.js --list
|
||||
`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
try {
|
||||
await createAgente(email, senha, parseInt(agenteId), nome);
|
||||
console.log(`\n Agente cadastrado com sucesso!`);
|
||||
console.log(` Nome: ${nome}`);
|
||||
console.log(` Email: ${email}`);
|
||||
console.log(` Agente ID: ${agenteId}\n`);
|
||||
} catch (err) {
|
||||
if (err.message.includes('UNIQUE')) {
|
||||
console.error(`\n Erro: email "${email}" ja esta cadastrado.\n`);
|
||||
} else {
|
||||
console.error('Erro:', err.message);
|
||||
}
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
||||
Reference in New Issue
Block a user