Repository navigation
Om 405 #80
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
Om 405 #80
Changes from all commits
c6e9787
b2fc9b6
3fb53a1
95e724d
fcc9a3d
0ceecd0
5cc3ecf
3d80511
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 |
|---|---|---|
|
|
@@ -755,7 +755,7 @@ export const updateStoreService = async ( | |
| } | ||
| }; | ||
|
|
||
| export const getStoreByIdService = async (id) => { | ||
| export const getStoreByIdService = async (id, { ignoreStoreStatus = false } = {}) => { | ||
| try { | ||
| // validaciones básicas | ||
| if (!id) { | ||
|
|
@@ -779,6 +779,7 @@ export const getStoreByIdService = async (id) => { | |
| instagram_url: true, | ||
| tiktok_url: true, | ||
| status: true, | ||
| store_status: true, | ||
| created_at: true, | ||
| user: { | ||
| select: { id_user: true, name: true, email: true } | ||
|
|
@@ -826,6 +827,11 @@ export const getStoreByIdService = async (id) => { | |
| throw { status: 404, message: "Comercio no encontrado" }; | ||
| } | ||
|
|
||
| // DESPUÉS — null se trata como ACTIVE (comportamiento por defecto del schema) | ||
| if (!ignoreStoreStatus && store.store_status && store.store_status !== "ACTIVE") { | ||
| throw { status: 404, message: "Comercio no disponible" }; | ||
| } | ||
|
|
||
| return mapStoreWithPricedProducts(store); | ||
|
|
||
| } catch (error) { | ||
|
|
@@ -1059,6 +1065,33 @@ export const filterStoreProductsService = async (id, filters, pagination) => { | |
| } | ||
| }; | ||
|
|
||
| export const updateStoreStatusService = async (authenticatedUserId, storeId, store_status) => { | ||
| const store = await getAuthorizedStoreOwnerService(authenticatedUserId, storeId); | ||
|
|
||
| const ALLOWED_STATUSES = ["ACTIVE", "INACTIVE"]; | ||
| if (!ALLOWED_STATUSES.includes(store_status)) { | ||
| throw { status: 400, message: "store_status debe ser ACTIVE o INACTIVE" }; | ||
| } | ||
|
|
||
| await prisma.$transaction([ | ||
| prisma.stores.update({ | ||
| where: { id_store: store.id_store }, | ||
| data: { store_status } | ||
| }), | ||
| // Al desactivar → ocultar productos. Al activar → hacerlos visibles nuevamente. | ||
| prisma.products.updateMany({ | ||
| where: { fk_store: store.id_store, status: true }, | ||
| data: { visible: store_status === "ACTIVE" } | ||
| }) | ||
|
Comment on lines
+1076
to
+1085
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. No pisen Al desactivar guardás 🤖 Prompt for AI Agents |
||
| ]); | ||
|
|
||
| const updated = await prisma.stores.findUnique({ | ||
| where: { id_store: store.id_store }, | ||
| select: { id_store: true, name: true, store_status: true, status: true } | ||
| }); | ||
|
|
||
| return updated; | ||
| }; | ||
|
|
||
| /** | ||
| * Esta funcion se utiliza para el borrado logico de un comercio y sus respectivos productos en base al usuario autenticado que debe ser el dueño. | ||
|
|
@@ -1091,7 +1124,10 @@ export const getStoresService = async (filters = {}) => { | |
| const categoryIdRaw = | ||
| filters.storeCategoryId ?? filters.categoryId ?? filters.fk_store_category; | ||
|
|
||
| const where = { status: true }; | ||
| const where = { | ||
| status: true, | ||
| store_status: "ACTIVE" | ||
| }; | ||
|
|
||
| if (search) { | ||
| where.OR = [ | ||
|
|
||
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.
🧩 Analysis chain
🏁 Script executed:
Repository: CrisNAC/BackendMarketplace
Length of output: 19504
Verificá el tipo antes de comparar el owner con
!==.store.user.id_usersale numérico de Prisma, peroreq.user.id_userviene como string desde el JWT (como se ve en la línea 25 del mismo archivo conNumber(req.user.id_user)). Sin casteo, el dueño legítimo cae en 403 por diferencia de tipo.Ajuste requerido
📝 Committable suggestion
🤖 Prompt for AI Agents