code refractor
This commit is contained in:
15
src/repositories/Map.ts
Normal file
15
src/repositories/Map.ts
Normal file
@ -0,0 +1,15 @@
|
||||
import { Map } from '@prisma/client';
|
||||
import prisma from '../helpers/prisma'; // Import the global Prisma instance
|
||||
|
||||
class MapRepository {
|
||||
async getFirst(): Promise<Map | null> {
|
||||
try {
|
||||
return await prisma.map.findFirst();
|
||||
} catch (error) {
|
||||
// Handle error
|
||||
throw new Error(`Failed to get first map: ${error.message}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default new MapRepository;
|
20
src/repositories/User.ts
Normal file
20
src/repositories/User.ts
Normal file
@ -0,0 +1,20 @@
|
||||
import prisma from '../helpers/prisma'; // Import the global Prisma instance
|
||||
import { User } from '@prisma/client';
|
||||
import bcrypt from 'bcryptjs';
|
||||
|
||||
class UserRepository {
|
||||
async getByUsername(username: string): Promise<User | null> {
|
||||
try {
|
||||
return await prisma.user.findUnique({
|
||||
where: {
|
||||
username,
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
// Handle error
|
||||
throw new Error(`Failed to get user by username: ${error.message}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default new UserRepository;
|
Reference in New Issue
Block a user