36 lines
767 B
JavaScript
36 lines
767 B
JavaScript
/**
|
|
* Get User By ID Query Handler
|
|
* Handles retrieval of a specific user by ID
|
|
*/
|
|
class GetUserByIdQueryHandler {
|
|
constructor(prisma) {
|
|
this.prisma = prisma;
|
|
}
|
|
|
|
/**
|
|
* Execute get user by ID query
|
|
* @param {GetUserByIdQuery} query
|
|
* @returns {Promise<Object>} User data without password
|
|
*/
|
|
async handle(query) {
|
|
const { userId } = query;
|
|
|
|
if (!userId || isNaN(userId)) {
|
|
throw new Error('Valid user ID is required');
|
|
}
|
|
|
|
const user = await this.prisma.user.findUnique({
|
|
where: { id: parseInt(userId) }
|
|
});
|
|
|
|
if (!user) {
|
|
throw new Error('User not found');
|
|
}
|
|
|
|
const { password, ...userWithoutPassword } = user;
|
|
return userWithoutPassword;
|
|
}
|
|
}
|
|
|
|
module.exports = GetUserByIdQueryHandler;
|