#161: Set default value for createdAt field, store zone chats into database
This commit is contained in:
@ -0,0 +1,30 @@
|
||||
import prisma from '../utilities/prisma'
|
||||
import { gameLogger } from '../utilities/logger'
|
||||
import { Server } from 'socket.io'
|
||||
import { TSocket } from '../utilities/types'
|
||||
import ChatRepository from '../repositories/chatRepository'
|
||||
|
||||
class ChatService {
|
||||
async sendZoneMessage(io: Server, socket: TSocket, message: string, characterId: number, zoneId: number): Promise<boolean> {
|
||||
try {
|
||||
const newChat = await prisma.chat.create({
|
||||
data: {
|
||||
characterId,
|
||||
zoneId,
|
||||
message
|
||||
}
|
||||
})
|
||||
|
||||
const chat = await ChatRepository.getById(newChat.id)
|
||||
if (!chat) return false
|
||||
|
||||
io.to(zoneId.toString()).emit('chat:message', chat)
|
||||
return true
|
||||
} catch (error: any) {
|
||||
gameLogger.error(`Failed to save chat message: ${error instanceof Error ? error.message : String(error)}`)
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default ChatService
|
||||
|
Reference in New Issue
Block a user