Several fixes
This commit is contained in:
parent
7475b83179
commit
060af95dc6
@ -25,7 +25,7 @@ export default function (socket: TSocket, io: Server) {
|
||||
return socket.emit('notification', {message: 'You can only have 4 characters'});
|
||||
}
|
||||
|
||||
const character: Character = await CharacterRepository.create(user_id, data.name) as Character;
|
||||
const character: Character = await CharacterRepository.create(user_id, data.name, 'player') as Character;
|
||||
characters = [...characters, character];
|
||||
|
||||
socket.emit('character:create:success');
|
||||
|
@ -10,7 +10,7 @@ export default function (socket: TSocket, io: Server) {
|
||||
try {
|
||||
data = ZCharacterDelete.parse(data);
|
||||
|
||||
await CharacterRepository.delete(data.character_id);
|
||||
await CharacterRepository.deleteByUserIdAndId(socket.user?.id as number, data.id as number);
|
||||
|
||||
const user_id = socket.user?.id as number;
|
||||
const characters: Character[] = await CharacterRepository.getByUserId(user_id) as Character[];
|
||||
|
@ -43,17 +43,17 @@ class CharacterRepository {
|
||||
}
|
||||
}
|
||||
|
||||
async create(userId: number, name: string): Promise<Character | null> {
|
||||
async create(userId: number, name: string, role: 'player'): Promise<Character | null> {
|
||||
try {
|
||||
return await prisma.character.create({
|
||||
data: {
|
||||
userId,
|
||||
name,
|
||||
role: 'gm',
|
||||
position_x: 0,
|
||||
position_y: 0,
|
||||
rotation: 0,
|
||||
zoneId: 1,
|
||||
role,
|
||||
position_x: 0, // @TODO Set default registration values in the database
|
||||
position_y: 0, // @TODO Set default registration values in the database
|
||||
rotation: 0, // @TODO Set default registration values in the database
|
||||
zoneId: 1, // @TODO Set default registration values in the database
|
||||
},
|
||||
});
|
||||
} catch (error: any) {
|
||||
@ -89,6 +89,20 @@ class CharacterRepository {
|
||||
}
|
||||
}
|
||||
|
||||
async deleteByUserIdAndId(userId: number, characterId: number): Promise<Character | null> {
|
||||
try {
|
||||
return await prisma.character.delete({
|
||||
where: {
|
||||
userId,
|
||||
id: characterId,
|
||||
},
|
||||
});
|
||||
} catch (error: any) {
|
||||
// Handle error
|
||||
throw new Error(`Failed to delete character by user ID and character ID: ${error.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
async getByName(name: string): Promise<Character | null> {
|
||||
try {
|
||||
return await prisma.character.findFirst({
|
||||
|
@ -1,6 +1,5 @@
|
||||
import bcrypt from "bcryptjs";
|
||||
import UserRepository from "../repositories/UserRepository";
|
||||
import CharacterRepository from "../repositories/CharacterRepository";
|
||||
import bcrypt from 'bcryptjs'
|
||||
import UserRepository from '../repositories/UserRepository'
|
||||
|
||||
class UserService
|
||||
{
|
||||
@ -25,12 +24,7 @@ class UserService
|
||||
}
|
||||
|
||||
const hashedPassword = await bcrypt.hash(password, 10);
|
||||
const newUser = await UserRepository.create(username, hashedPassword);
|
||||
|
||||
// @TODO: Remove this logic from here and move it to the character creation part wherever that'll be
|
||||
const newCharacter = await CharacterRepository.create(newUser.id, newUser.username);
|
||||
|
||||
return newUser
|
||||
return await UserRepository.create(username, hashedPassword)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user