Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions backend/src/controllers/avatarController.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,25 +245,34 @@ const getAvatarByPet = async (req, res) => {

// Convert petId to integer (comes from route params as string)
const petIdNum = parseInt(petId, 10);
console.log(`[AvatarController] Converting petId: "${petId}" -> ${petIdNum} (isNaN: ${isNaN(petIdNum)})`);

if (isNaN(petIdNum)) {
return res.status(400).json({
success: false,
message: 'Invalid pet ID format'
});
}

console.log(`[AvatarController] Fetching avatar for pet ${petIdNum}, user ${userId}`);

// Verify user has access to pet
const hasAccess = await Pet.userHasAccess(petIdNum, userId);
console.log(`[AvatarController] User access check: ${hasAccess}`);

if (!hasAccess) {
return res.status(403).json({
success: false,
message: 'Not authorized to view this pet'
});
}

console.log(`[AvatarController] Calling Avatar.getByPetId(${petIdNum})`);
const avatar = await Avatar.getByPetId(petIdNum);
console.log(`[AvatarController] Avatar query result:`, avatar);

if (!avatar) {
console.error(`[AvatarController] NO AVATAR FOUND for pet ${petIdNum}. Check if pet_id column matches.`);
return res.status(404).json({
success: false,
message: 'No avatar found for this pet'
Expand Down
Loading