feat: Implement rest API endpoint for admins to create user

This commit is contained in:
Faruk AYDIN
2024-09-17 11:41:18 +03:00
parent fd971449ca
commit 89aa7ffc73
5 changed files with 203 additions and 1 deletions

View File

@@ -0,0 +1,22 @@
import { renderObject } from '../../../../../helpers/renderer.js';
import User from '../../../../../models/user.js';
import Role from '../../../../../models/role.js';
export default async (request, response) => {
const user = await User.query().insertAndFetch(await userParams(request));
await user.sendInvitationEmail();
renderObject(response, user, { status: 201 });
};
const userParams = async (request) => {
const { fullName, email } = request.body;
const roleId = request.body.roleId || (await Role.findAdmin()).id;
return {
fullName,
status: 'invited',
email: email?.toLowerCase(),
roleId,
};
};