mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-19 12:19:16 +00:00
started migration of user domain to ts
This commit is contained in:
53
backend/src/services/CreateUserService.ts
Normal file
53
backend/src/services/CreateUserService.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
import * as Yup from "yup";
|
||||
|
||||
import AppError from "../errors/AppError";
|
||||
import User from "../models/User";
|
||||
|
||||
interface Request {
|
||||
email: string;
|
||||
password: string;
|
||||
name: string;
|
||||
profile?: string;
|
||||
}
|
||||
|
||||
const CreateUserService = async ({
|
||||
email,
|
||||
password,
|
||||
name,
|
||||
profile = "admin"
|
||||
}: Request): Promise<User> => {
|
||||
// const schema = Yup.object().shape({
|
||||
// name: Yup.string().required().min(2),
|
||||
// email: Yup.string()
|
||||
// .email()
|
||||
// .required()
|
||||
// .test(
|
||||
// "Check-email",
|
||||
// "An user with this email already exists.",
|
||||
// async value => {
|
||||
// const emailExists = await User.findOne({
|
||||
// where: { email: value }
|
||||
// });
|
||||
// return !Boolean(emailExists);
|
||||
// }
|
||||
// ),
|
||||
// password: Yup.string().required().min(5)
|
||||
// });
|
||||
|
||||
// try {
|
||||
// await schema.validate({ email, password, name });
|
||||
// } catch (err) {
|
||||
// throw new AppError(err.message);
|
||||
// }
|
||||
|
||||
const user = User.create({
|
||||
email,
|
||||
passwordHash: password,
|
||||
name,
|
||||
profile
|
||||
});
|
||||
|
||||
return user;
|
||||
};
|
||||
|
||||
export default CreateUserService;
|
||||
Reference in New Issue
Block a user