Add role create cli command

This commit is contained in:
rijkvanzanten
2020-09-18 11:49:36 -04:00
parent 04a5a8ce17
commit bed7f67203
4 changed files with 46 additions and 30 deletions

View 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();
}

View File

@@ -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();
}

View 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();
}