Repository navigation
Revert "Om 55: Merging with Cris Code rabbit" #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -86,10 +86,10 @@ export const createStoreService = async (data) => { | |
| throw { status: 404, message: "Usuario no encontrado" }; | ||
| } | ||
|
|
||
| // Verificar que sea SELLER | ||
| // if (usuario.role !== "SELLER") { | ||
| // throw { status: 403, message: "El usuario no es vendedor" }; | ||
| // } | ||
| // vrificar que sea SELLER | ||
| if (usuario.role !== "SELLER") { | ||
| throw { status: 403, message: "El usuario no es vendedor" }; | ||
| } | ||
|
Comment on lines
+89
to
+92
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Buscar si existe algún endpoint o servicio para actualizar el rol del usuario a SELLER
rg -n "SELLER" --type js -C 3Repository: CrisNAC/BackendMarketplace Length of output: 1256 🏁 Script executed: # Ver el contexto completo de la función que contiene la validación SELLER
head -n 110 src/modules/commerce/commerces/store.service.js | tail -n 50Repository: CrisNAC/BackendMarketplace Length of output: 1430 🏁 Script executed: # Buscar endpoints o servicios que asignen o actualicen el rol SELLER
rg -n "(role|SELLER)" --type js -i -C 2 | grep -E "(update|assign|change|set)" -iRepository: CrisNAC/BackendMarketplace Length of output: 52 🏁 Script executed: # Buscar endpoints de usuarios que podrían actualizar roles
rg -n "role" src/modules --type js -lRepository: CrisNAC/BackendMarketplace Length of output: 272 🏁 Script executed: # Buscar si hay algún servicio de autenticación o usuarios
fd -e js | xargs grep -l "user.*role" -i | head -20Repository: CrisNAC/BackendMarketplace Length of output: 124 🏁 Script executed: # Ver el servicio de usuarios completo
cat -n src/modules/users/users/services/users.services.jsRepository: CrisNAC/BackendMarketplace Length of output: 1549 🏁 Script executed: # Ver el controlador de sesión
cat -n src/modules/session/controllers/session.controllers.jsRepository: CrisNAC/BackendMarketplace Length of output: 4673 🏁 Script executed: # Buscar en toda la carpeta de usuarios si hay algún endpoint o función que actualice roles
rg -n "role" src/modules/users --type js -B 2 -A 2Repository: CrisNAC/BackendMarketplace Length of output: 872 🏁 Script executed: # Buscar archivos de rutas
find src -name "*route*" -o -name "*routes*" | head -20Repository: CrisNAC/BackendMarketplace Length of output: 448 🏁 Script executed: # Buscar controladores de usuarios
find src/modules/users -name "*controller*" -o -name "*controllers*"Repository: CrisNAC/BackendMarketplace Length of output: 162 🏁 Script executed: # Buscar cualquier función que actualice usuarios o roles
rg -n "update.*user|role.*update" --type js -iRepository: CrisNAC/BackendMarketplace Length of output: 52 🏁 Script executed: # Buscar en el schema de prisma si existe referencia al rol
find . -name "schema.prisma" -o -name "*.prisma"Repository: CrisNAC/BackendMarketplace Length of output: 92 🏁 Script executed: # Ver las rutas disponibles para usuarios
cat -n src/modules/users/users/routes/users.routes.jsRepository: CrisNAC/BackendMarketplace Length of output: 353 🏁 Script executed: # Ver los controladores de usuarios
cat -n src/modules/users/users/controllers/users.controllers.jsRepository: CrisNAC/BackendMarketplace Length of output: 1613 🏁 Script executed: # Ver la estructura de usuarios en el schema
grep -n "model.*[Uu]ser\|role\|SELLER\|CUSTOMER" prisma/schema.prisma -A 10 -B 2Repository: CrisNAC/BackendMarketplace Length of output: 842 No existe mecanismo para asignar el rol SELLER a los usuarios. La validación de rol SELLER en la función está correcta, pero presenta un problema crítico: los nuevos usuarios se crean con rol "CUSTOMER" por defecto (users.services.js línea 35), y el único endpoint disponible es Esto hace que los usuarios nunca puedan crear una tienda, a menos que se actualice manualmente la base de datos o se implemente un endpoint para asignar el rol SELLER (por ejemplo, desde un panel de administrador o mediante una solicitud de vendedor). Se debe agregar un mecanismo para que los usuarios puedan obtener el rol SELLER, o aclarar si esta restricción es intencional y será gestionada mediante otro proceso fuera de la API. 🤖 Prompt for AI Agents |
||
|
|
||
| // verificar que no tenga tienda | ||
| const tiendaExistente = await prisma.stores.findUnique({ | ||
|
|
@@ -130,20 +130,14 @@ export const createStoreService = async (data) => { | |
| await tx.addresses.create({ | ||
| data: { | ||
| fk_user, | ||
| fk_store: store.id, | ||
| fk_store: store.id_store, | ||
| address: address.trim(), | ||
| city: city.trim(), | ||
| region: region.trim(), | ||
| postal_code | ||
| } | ||
| }); | ||
|
|
||
| // Actualizamos rol del usuario a SELLER al crearse el comercio | ||
| await tx.users.update({ | ||
| where: { id_user: fk_user }, | ||
| data: { role: "SELLER" } | ||
| }); | ||
|
|
||
| return store; | ||
| }); | ||
|
|
||
|
|
@@ -161,22 +155,22 @@ export const createStoreService = async (data) => { | |
|
|
||
| /** | ||
| * Obtiene un comercio por su ID, incluyendo datos del vendedor, categoría, productos visibles y direcciones activas. Realiza validaciones básicas y maneja errores. | ||
| * @param {*} id | ||
| * @param {*} id_store | ||
| * @returns | ||
| */ | ||
| export const getStoreByIdService = async (id) => { | ||
| export const getStoreByIdService = async (id_store) => { | ||
| try { | ||
| // validaciones básicas | ||
| if (!id) { | ||
| if (!id_store) { | ||
| throw { status: 400, message: "ID de tienda es requerido" }; | ||
| } | ||
| if (isNaN(Number(id))) { | ||
| if (isNaN(Number(id_store))) { | ||
| throw { status: 400, message: "ID de tienda debe ser un número" }; | ||
| } | ||
|
|
||
| // Buscar comercio | ||
| const store = await prisma.stores.findUnique({ | ||
| where: { id_store: Number(id) }, | ||
| where: { id_store: Number(id_store) }, | ||
| // Datos del comercio | ||
| select: { | ||
| id_store: true, | ||
|
|
@@ -237,21 +231,21 @@ export const getStoreByIdService = async (id) => { | |
|
|
||
| /** | ||
| * Obtiene todos los productos de una tienda específica, filtrando por productos activos y visibles. Realiza validaciones básicas y maneja errores. | ||
| * @param {*} id | ||
| * @param {*} id_store | ||
| * @returns | ||
| */ | ||
| export const getAllProductsByStoreService = async (id) => { | ||
| export const getAllProductsByStoreService = async (id_store) => { | ||
| try { | ||
| // validaciones básicas | ||
| if (!id) { | ||
| if (!id_store) { | ||
| throw { status: 400, message: "ID de tienda es requerido" }; | ||
| } | ||
| if (isNaN(Number(id))) { | ||
| if (isNaN(Number(id_store))) { | ||
| throw { status: 400, message: "ID de tienda debe ser un número" }; | ||
| } | ||
| // Verificar que la tienda exista | ||
| const store = await prisma.stores.findUnique({ | ||
| where: { id_store: Number(id) }, | ||
| where: { id_store: Number(id_store) }, | ||
| select: { id_store: true } | ||
| }); | ||
| // Si no se encuentra la tienda, lanzar error 404 | ||
|
|
@@ -261,7 +255,7 @@ export const getAllProductsByStoreService = async (id) => { | |
| // Obtener productos activos y visibles de la tienda | ||
| const products = await prisma.products.findMany({ | ||
| where: { | ||
| fk_store: Number(id), | ||
| fk_store: Number(id_store), | ||
| status: true | ||
| }, | ||
| select: { | ||
|
|
@@ -299,22 +293,22 @@ export const getAllProductsByStoreService = async (id) => { | |
|
|
||
| /** | ||
| * Obtiene productos de una tienda específica aplicando filtros dinámicos como nombre, categoría, visibilidad y rango de precios. Realiza validaciones básicas y maneja errores. | ||
| * @param {*} id | ||
| * @param {*} id_store | ||
| * @param {*} filters | ||
| * @returns | ||
| */ | ||
| export const filterStorePriductsService = async (id, filters) => { | ||
| export const filterStorePriductsService = async (id_store, filters) => { | ||
| try { | ||
| // validaciones básicas | ||
| if (!id) { | ||
| if (!id_store) { | ||
| throw { status: 400, message: "ID de tienda es requerido" }; | ||
| } | ||
| if (isNaN(Number(id))) { | ||
| if (isNaN(Number(id_store))) { | ||
| throw { status: 400, message: "ID de tienda debe ser un número" }; | ||
| } | ||
| // Verificar que la tienda exista | ||
| const store = await prisma.stores.findUnique({ | ||
| where: { id_store: Number(id) }, | ||
| where: { id_store: Number(id_store) }, | ||
| select: { id_store: true } | ||
| }); | ||
| // Si no se encuentra la tienda, lanzar error 404 | ||
|
|
@@ -325,7 +319,7 @@ export const filterStorePriductsService = async (id, filters) => { | |
| const { name, category, visible, minPrice, maxPrice, sortBy, sortOrder } = filters; | ||
| // Condiciones base para productos activos de la tienda | ||
| const whereConditions = { | ||
| fk_store: Number(id), | ||
| fk_store: Number(id_store), | ||
| status: true | ||
| }; | ||
| if (name) { | ||
|
|
||
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Discrepancia en nombres de parámetros de filtro.
El controlador extrae
price_minyprice_maxdel query string, pero el serviciofilterStorePriductsServiceesperaminPriceymaxPricesegún los snippets relevantes (líneas 319 y 334-338 de store.service.js). Esto causará que los filtros de precio no funcionen.🐛 Corrección propuesta
export const filterStoreProducts = async (req, res) => { try { const { id_store } = req.params; - const { category, price_min, price_max } = req.query; - const products = await filterStorePriductsService(id_store, { category, price_min, price_max }); + const { category, price_min, price_max, name, visible, sortBy, sortOrder } = req.query; + const products = await filterStorePriductsService(id_store, { + category, + minPrice: price_min, + maxPrice: price_max, + name, + visible, + sortBy, + sortOrder + }); return res.status(200).json(products);📝 Committable suggestion
🤖 Prompt for AI Agents