fiora/packages/bin/scripts/getUserId.ts
碎碎酱 1dbe1195fd
Add fiora command and update scripts (#417)
* Add fiora command

* Update scripts and docs

* Support i18n
2021-07-20 21:07:14 +08:00

30 lines
763 B
TypeScript

import chalk from 'chalk';
import User from '@fiora/database/mongoose/models/user';
import initMongoDB from '@fiora/database/mongoose/initMongoDB';
export async function getUserId(username: string) {
if (!username) {
console.log(chalk.red('Wrong command, [username] is missing.'));
return;
}
await initMongoDB();
const user = await User.findOne({ username });
if (!user) {
console.log(chalk.red(`User [${username}] does not exist`));
} else {
console.log(
`The userId of [${username}] is:`,
chalk.green(user._id.toString()),
);
}
}
async function run() {
const username = process.argv[3];
await getUserId(username);
process.exit(0);
}
export default run;