ff-admin-server/src/command/userCommandHandler.ts

33 lines
920 B
TypeScript
Raw Normal View History

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
2024-08-25 11:36:19 +00:00
* @returns {Promise<number>}
*/
2024-08-25 11:36:19 +00:00
static async create(createUser: CreateUserCommand): Promise<number> {
return await dataSource
.createQueryBuilder()
.insert()
.into(user)
.values({
username: createUser.username,
mail: createUser.mail,
2024-08-25 11:36:19 +00:00
firstname: createUser.firstname,
lastname: createUser.lastname,
secret: createUser.secret,
})
.execute()
.then((result) => {
return result.identifiers[0].id;
})
.catch((err) => {
throw new InternalException("Failed saving user");
});
}
}