use camelcase file names from now on...

This commit is contained in:
2024-08-21 20:55:58 +02:00
parent acc9eaae9e
commit 6b97e7d9cb
55 changed files with 396 additions and 116 deletions

View File

@ -0,0 +1,37 @@
import bcrypt from 'bcryptjs'
import UserRepository from '../repositories/userRepository'
import prisma from '../utilities/prisma'
import { User } from '@prisma/client'
class UserService {
async login(username: string, password: string): Promise<boolean | User> {
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 | User> {
const user = await UserRepository.getByUsername(username)
if (user) {
return false
}
const hashedPassword = await bcrypt.hash(password, 10)
return prisma.user.create({
data: {
username,
password: hashedPassword
}
})
}
}
export default UserService