ff-admin-server/src/command/userCommandHandler.ts
Julian Krauser e1ec65350d login and authentication
login via totp
authentication via access and refresh tokens
2024-08-22 11:40:31 +02:00

30 lines
840 B
TypeScript

import { dataSource } from "../data-source";
import { user } from "../entity/user";
import InternalException from "../exceptions/internalException";
import { CreateUserCommand } from "./userCommand";
export default abstract class UserCommandHandler {
/**
* @description create user
* @param CreateUserCommand
* @returns {Promise<string>}
*/
static async create(createUser: CreateUserCommand): Promise<string> {
return await dataSource
.createQueryBuilder()
.insert()
.into(user)
.values({
username: createUser.username,
mail: createUser.mail,
secret: createUser.secret,
})
.execute()
.then((result) => {
return result.identifiers[0].id;
})
.catch((err) => {
throw new InternalException("Failed saving user");
});
}
}