54 lines
1.6 KiB
TypeScript
54 lines
1.6 KiB
TypeScript
import { appLogger } from '#utilities/logger'
|
|
import { BaseRepository } from '#repositories/baseRepository'
|
|
import { Chat } from '#entities/chat'
|
|
|
|
class ChatRepository extends BaseRepository {
|
|
async getById(id: number): Promise<Chat[]> {
|
|
try {
|
|
const repository = this.em.getRepository(Chat)
|
|
return await repository.find({
|
|
id
|
|
})
|
|
} catch (error: any) {
|
|
appLogger.error(`Failed to get chat by ID: ${error instanceof Error ? error.message : String(error)}`)
|
|
return []
|
|
}
|
|
}
|
|
|
|
async getAll(): Promise<Chat[]> {
|
|
try {
|
|
const repository = this.em.getRepository(Chat)
|
|
return await repository.findAll()
|
|
} catch (error: any) {
|
|
appLogger.error(`Failed to get all chats: ${error instanceof Error ? error.message : String(error)}`)
|
|
return []
|
|
}
|
|
}
|
|
|
|
async getByCharacterId(characterId: number): Promise<Chat[]> {
|
|
try {
|
|
const repository = this.em.getRepository(Chat)
|
|
return await repository.find({
|
|
character: characterId
|
|
})
|
|
} catch (error: any) {
|
|
appLogger.error(`Failed to get chats by character ID: ${error instanceof Error ? error.message : String(error)}`)
|
|
return []
|
|
}
|
|
}
|
|
|
|
async getByZoneId(zoneId: number): Promise<Chat[]> {
|
|
try {
|
|
const repository = this.em.getRepository(Chat)
|
|
return await repository.find({
|
|
zone: zoneId
|
|
})
|
|
} catch (error: any) {
|
|
appLogger.error(`Failed to get chats by zone ID: ${error instanceof Error ? error.message : String(error)}`)
|
|
return []
|
|
}
|
|
}
|
|
}
|
|
|
|
export default new ChatRepository()
|