forked from noxious/server
Complete refractor - we do sexy code only
This commit is contained in:
15
src/app/repositories/map.ts
Normal file
15
src/app/repositories/map.ts
Normal file
@ -0,0 +1,15 @@
|
||||
import { Map } from '@prisma/client';
|
||||
import prisma from '../utilities/prisma'; // Import the global Prisma instance
|
||||
|
||||
class MapRepository {
|
||||
async getFirst(): Promise<Map | null> {
|
||||
try {
|
||||
return await prisma.map.findFirst();
|
||||
} catch (error: any) {
|
||||
// Handle error
|
||||
throw new Error(`Failed to get first map: ${error.message}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default MapRepository;
|
33
src/app/repositories/user.ts
Normal file
33
src/app/repositories/user.ts
Normal file
@ -0,0 +1,33 @@
|
||||
import prisma from '../utilities/prisma'; // Import the global Prisma instance
|
||||
import { User } from '@prisma/client';
|
||||
|
||||
class UserRepository {
|
||||
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}`);
|
||||
}
|
||||
}
|
||||
|
||||
async create(username: string, password: string): Promise<User> {
|
||||
try {
|
||||
return await prisma.user.create({
|
||||
data: {
|
||||
username,
|
||||
password,
|
||||
},
|
||||
});
|
||||
} catch (error: any) {
|
||||
// Handle error
|
||||
throw new Error(`Failed to create user: ${error.message}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default new UserRepository;
|
Reference in New Issue
Block a user