mirror of
https://github.com/directus/directus.git
synced 2026-02-01 23:45:02 -05:00
Add role create cli command
This commit is contained in:
14
api/src/cli/commands/roles/create.ts
Normal file
14
api/src/cli/commands/roles/create.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
export default async function rolesCreate({ name, admin }: any) {
|
||||
const database = require('../../../database/index').default;
|
||||
const RolesService = require('../../../services/roles').default;
|
||||
|
||||
if (!name) {
|
||||
console.error('Name is required');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const service = new RolesService();
|
||||
const id = await service.create({ name, admin, status: 'active' });
|
||||
console.log(id);
|
||||
database.destroy();
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
import argon2 from 'argon2';
|
||||
import { v4 as uuidV4 } from 'uuid';
|
||||
|
||||
export default async function userCreate({ email, password }: any) {
|
||||
if (!email || !password) {
|
||||
console.error('Email and password are required');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const database = require('../../../database').default;
|
||||
|
||||
const existingUser = await database.select('id').from('directus_users').where({ email }).first();
|
||||
|
||||
if (existingUser) {
|
||||
console.error(`User with email "${email}" already exists`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const hashedPassword = await argon2.hash(password);
|
||||
await database.insert({ id: uuidV4(), email, password: hashedPassword }).into('directus_users');
|
||||
|
||||
database.destroy();
|
||||
}
|
||||
14
api/src/cli/commands/users/create.ts
Normal file
14
api/src/cli/commands/users/create.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
export default async function usersCreate({ email, password, role }: any) {
|
||||
const database = require('../../../database/index').default;
|
||||
const UsersService = require('../../../services/users').default;
|
||||
|
||||
if (!email || !password || !role) {
|
||||
console.error('Email, password, role are required');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const service = new UsersService();
|
||||
const id = await service.create({ email, password, role });
|
||||
console.log(id);
|
||||
database.destroy();
|
||||
}
|
||||
Reference in New Issue
Block a user