18 lines
673 B
TypeScript
18 lines
673 B
TypeScript
import { Socket, Server } from 'socket.io'
|
|
import { TSocket } from '../../utilities/types'
|
|
import { Character } from '@prisma/client'
|
|
import CharacterRepository from '../../repositories/characterRepository'
|
|
|
|
export default function CharacterList(io: Server, socket: TSocket) {
|
|
socket.on('character:list', async (data: any) => {
|
|
try {
|
|
console.log('character:list requested')
|
|
const user_id = socket.user?.id as number
|
|
const characters: Character[] = (await CharacterRepository.getByUserId(user_id)) as Character[]
|
|
socket.emit('character:list', characters)
|
|
} catch (error: any) {
|
|
console.log('character:list error', error)
|
|
}
|
|
})
|
|
}
|