31 lines
840 B
TypeScript
31 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");
|
||
|
});
|
||
|
}
|
||
|
}
|