Added signup route 👤

This commit is contained in:
Manik Maity
2024-11-07 21:08:08 +05:30
parent a3c5140bb4
commit 8741f40304
12 changed files with 1096 additions and 3 deletions

View File

@@ -0,0 +1,26 @@
import { SALT } from "../config/veriables.js";
import { createUser } from "../repositories/user.repo.js";
import bcrypt from "bcrypt";
export async function signupService(username, email, password) {
try {
if (username.trim() == "" || email.trim() == "" || password.trim() == "") {
throw {
statusCode: 400,
message: "All fields are required",
};
}
const hashedPassword = bcrypt.hashSync(password, SALT);
const user = await createUser(username, email, hashedPassword);
return user;
} catch (err) {
if (err.code == 11000) {
throw {
statusCode: 409,
message: "User already exists",
};
} else {
throw err;
}
}
}