srs-api/scripts/user.ts
Aswin Biju c6251810ae
All checks were successful
deploy / test (push) Successful in 1m13s
deploy / deploy (push) Successful in 19s
feat: added WhatsApp summary options for users
2026-11-05 00:37:57 +05:30

56 lines
1.9 KiB
TypeScript

/**
* npm run user manage one menu: create, change a password, result messages on/off, list
* npm run user create a short wizard: choose Admin or User
* npm run user password set a new password for an admin or a user
* npm run user list show every account
*
*/
import { createWizard, listLines, manageWizard, passwordWizard, resultsWizard } from '../src/cli/userWizard';
import { loadConfig } from '../src/config';
import { openDb } from '../src/db';
import { runMigrations } from '../src/db/migrate';
import { makeIo } from './cliIo';
async function main(): Promise<number> {
const command = process.argv[2];
if (!['manage', 'create', 'password', 'results', 'list'].includes(command ?? '')) {
console.log('usage:');
console.log(' npm run user manage one menu for everything below');
console.log(' npm run user create create an admin or a user (a short wizard)');
console.log(' npm run user password set a new password for an admin or a user');
console.log(' npm run user results turn result messages on or off for an admin or a user');
console.log(' npm run user list show every account');
return command ? 1 : 0;
}
const config = loadConfig();
const db = openDb(config.dbPath);
runMigrations(db);
try {
if (command === 'list') {
for (const line of listLines(db)) console.log(line);
return 0;
}
const { io, close } = makeIo();
try {
if (command === 'manage') return await manageWizard(db, io, config.defaultCountryCode);
if (command === 'password') return await passwordWizard(db, io);
if (command === 'results') return await resultsWizard(db, io);
return await createWizard(db, io, config.defaultCountryCode);
} finally {
close();
}
} finally {
db.close();
}
}
main().then(
(code) => process.exit(code),
(err) => {
console.error(String(err));
process.exit(1);
},
);