50 lines
1.1 KiB
TypeScript
50 lines
1.1 KiB
TypeScript
import { Zone } from '@prisma/client'
|
|
import prisma from '../utilities/Prisma' // Import the global Prisma instance
|
|
|
|
class ZoneRepository {
|
|
async getFirst(): Promise<Zone | null> {
|
|
try {
|
|
return await prisma.zone.findFirst()
|
|
} catch (error: any) {
|
|
// Handle error
|
|
throw new Error(`Failed to get first zone: ${error.message}`)
|
|
}
|
|
}
|
|
|
|
async getAll(): Promise<Zone[]> {
|
|
try {
|
|
return await prisma.zone.findMany()
|
|
} catch (error: any) {
|
|
// Handle error
|
|
throw new Error(`Failed to get all zone: ${error.message}`)
|
|
}
|
|
}
|
|
|
|
async getById(id: number): Promise<Zone | null> {
|
|
try {
|
|
return await prisma.zone.findUnique({
|
|
where: {
|
|
id: id
|
|
},
|
|
include: {
|
|
zoneEventTiles: {
|
|
include: {
|
|
zone: true
|
|
}
|
|
},
|
|
zoneObjects: {
|
|
include: {
|
|
object: true
|
|
}
|
|
}
|
|
}
|
|
})
|
|
} catch (error: any) {
|
|
// Handle error
|
|
throw new Error(`Failed to get zone by id: ${error.message}`)
|
|
}
|
|
}
|
|
}
|
|
|
|
export default new ZoneRepository()
|