Skip to content
Merged
Changes from 1 commit
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
32 changes: 28 additions & 4 deletions src/modules/users/users/services/users.services.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,7 @@ export const updateUserService = async (
requestedUserId,
payload
) => {
const customer = await getAuthorizedCustomerService(
authenticatedUserId,
requestedUserId
);
const customer = await getAuthorizedUserForUpdateService(authenticatedUserId, requestedUserId);

const dataToUpdate = {};

Expand Down Expand Up @@ -362,6 +359,7 @@ export const updateUserPasswordService = async (

return updatedUser;
};

export const getUserProfileService = async (authenticatedUserId, requestedUserId) => {

const userProfile = await getAuthorizedUserService(
Expand All @@ -386,3 +384,29 @@ export const getUserProfileService = async (authenticatedUserId, requestedUserId

return user;
};
const getAuthorizedUserForUpdateService = async (
authenticatedUserId,
requestedUserId
) => {
if (!authenticatedUserId) {
throw { status: 401, message: "Usuario autenticado requerido" };
}

const authenticatedId = parsePositiveInteger(authenticatedUserId, "ID de usuario autenticado");
const targetUserId = parsePositiveInteger(requestedUserId, "ID de usuario");

if (authenticatedId !== targetUserId) {
throw { status: 403, message: "No tiene permisos para editar este perfil" };
}

const user = await prisma.users.findUnique({
where: { id_user: targetUserId },
select: { id_user: true, role: true, status: true },
});

if (!user || !user.status) {
throw { status: 404, message: "Usuario no encontrado o inactivo" };
}

return user; // sin restricción de rol
};