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} */ static async create(createUser: CreateUserCommand): Promise { 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"); }); } }