use camelcase file names from now on...
This commit is contained in:
31
src/repositories/userRepository.ts
Normal file
31
src/repositories/userRepository.ts
Normal file
@ -0,0 +1,31 @@
|
||||
import prisma from '../utilities/prisma' // Import the global Prisma instance
|
||||
import { User } from '@prisma/client'
|
||||
|
||||
class UserRepository {
|
||||
async getById(id: number): Promise<User | null> {
|
||||
try {
|
||||
return await prisma.user.findUnique({
|
||||
where: {
|
||||
id
|
||||
}
|
||||
})
|
||||
} catch (error: any) {
|
||||
// Handle error
|
||||
throw new Error(`Failed to get user by ID: ${error.message}`)
|
||||
}
|
||||
}
|
||||
async getByUsername(username: string): Promise<User | null> {
|
||||
try {
|
||||
return await prisma.user.findUnique({
|
||||
where: {
|
||||
username
|
||||
}
|
||||
})
|
||||
} catch (error: any) {
|
||||
// Handle error
|
||||
throw new Error(`Failed to get user by username: ${error.message}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default new UserRepository()
|
Reference in New Issue
Block a user