Complete refractor - we do sexy code only

This commit is contained in:
2024-05-09 04:00:05 +02:00
parent ca88c085e6
commit 8356a83431
28 changed files with 449 additions and 492 deletions

30
src/app/services/user.ts Normal file
View File

@ -0,0 +1,30 @@
import bcrypt from "bcryptjs";
import UserRepository from "../repositories/user";
class UserService {
async login(username: string, password: string): Promise<boolean | any> {
const user = await UserRepository.getByUsername(username);
if (!user) {
return false;
}
const passwordMatch = await bcrypt.compare(password, user.password);
if (!passwordMatch) {
return false;
}
return user;
}
async register(username: string, password: string): Promise<boolean | any> {
const user = await UserRepository.getByUsername(username);
if (user) {
return false;
}
const hashedPassword = await bcrypt.hash(password, 10);
return await UserRepository.create(username, hashedPassword);
}
}
export default UserService;