mirror of
https://github.com/yinxin630/fiora.git
synced 2026-06-04 21:03:18 +08:00
30 lines
763 B
TypeScript
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;
|