Repository navigation
OM-524: Solicitud de banners promocionales por comercios - #197
Conversation
Schema Prisma: Se agregaron 3 campos al modelo Banners existente: fk_store (FK opcional a Stores), approval_status (enum ApprovalStatus, default PENDING) y rejection_reason. image_url pasó a opcional. Se registró la relación inversa en Stores. Nuevo módulo commerce/banner-requests: Los comercios (SELLER) pueden crear solicitudes de banner, ver su historial filtrado por estado y cancelar solicitudes pendientes. POST /api/stores/:storeId/banner-requests GET /api/stores/:storeId/banner-requests DELETE /api/stores/:storeId/banner-requests/:requestId Extensión del módulo admin: El administrador puede revisar las solicitudes de comercios y aprobarlas o rechazarlas (con motivo obligatorio). GET /api/admin/banners/requests PATCH /api/admin/banners/requests/:id
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (3)
📝 WalkthroughWalkthroughAgrega soporte de "banner requests": esquema (relación Banners ↔ Stores), documentación OpenAPI, rutas y controladores para vendedores (crear/listar/cancelar) y admin (listar/procesar aprobar/rechazar), con servicios que validan, persisten y gestionan estados de aprobación. CambiosSistema de solicitudes de banners con aprobación
Sequence Diagram(s): sequenceDiagram
participant Seller
participant BannerRequestController
participant BannerRequestService
participant PrismaDB
Seller->>BannerRequestController: POST /api/stores/:storeId/banner-requests
BannerRequestController->>BannerRequestService: createBannerRequestService(payload)
BannerRequestService->>PrismaDB: prisma.banners.create({fk_store, approval_status: "PENDING", is_active:false})
PrismaDB-->>BannerRequestService: banner creado
BannerRequestService-->>BannerRequestController: respuesta mapeada 201
BannerRequestController-->>Seller: 201 Created
sequenceDiagram
participant Admin
participant AdminBannersController
participant AdminBannersService
participant PrismaDB
Admin->>AdminBannersController: PATCH /api/admin/banners/requests/:id
AdminBannersController->>AdminBannersService: processBannerRequestService(id, decision)
AdminBannersService->>PrismaDB: updateMany where id & approval_status = PENDING
alt decision = APPROVE
PrismaDB-->>AdminBannersService: updated (approval_status=ACTIVE, is_active=true)
else decision = REJECT
PrismaDB-->>AdminBannersService: updated (approval_status=REJECTED, rejection_reason=...)
end
AdminBannersService-->>AdminBannersController: banner mapeado 200
AdminBannersController-->>Admin: 200 OK
Esfuerzo estimado de revisión🎯 4 (Complex) | ⏱️ ~45 minutes PRs potencialmente relacionados
Revisores sugeridos
Poema
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Tip For best results, initiate chat on the files or code changes.
Aquí algunas cosas que puedo hacer:
¿Qué necesitas? 😊 (¯ |
|
@CodeRabbit review |
✅ Action performedReview finished.
|
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/modules/admin/banners/admin-banners.routes.js`:
- Around line 170-176: OpenAPI paths and security in the swagger block are
inconsistent with the actual router: replace instances of the path string
'/api/admin/banner-requests' with '/api/admin/banners/requests' (and any other
mismatched path occurrences) and change the security scheme entries from
'bearerAuth' to 'cookieAuth' so they match the admin module's router; update all
occurrences referenced (the blocks around the existing path and security
entries) so the documented path and auth exactly mirror the real routes.
In `@src/modules/admin/banners/admin-banners.service.js`:
- Around line 302-305: The code uses a non-atomic check-then-update
(prisma.banners.findFirst) that allows race conditions when two admins act
concurrently; replace the findFirst + separate update with a single conditional
update (e.g., prisma.banners.updateMany or prisma.banners.update with a WHERE
that includes id_banner: id, fk_store: { not: null }, status: true and
approval_status: 'PENDING') and then check the returned count/rowsAffected to
determine if the update actually applied (if count === 0, return/conflict
because another process already handled it). Update the logic in the
admin-banners service around the existing prisma.banners.findFirst / subsequent
update calls so the change is done atomically and handle the no-op result as a
race-condition conflict.
In `@src/modules/commerce/banner-requests/banner-request.service.js`:
- Around line 140-154: The cancel flow has a TOCTOU: you read the banner row
into request then update by id only, so it can be changed between operations;
make the cancel atomic by performing a conditional update that includes the
pending state and active status check (e.g. replace the separate
read+prisma.banners.update with a single conditional update like
prisma.banners.updateMany or a transactional update where the where includes
id_banner, fk_store, approval_status: "PENDING", status: true) and then verify
the affected count/result — if zero, throw the same
ValidationError/NotFoundError as appropriate; reference the existing request
variable, prisma.banners.update call, and the "PENDING" approval_status check
when making this change.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 02245937-3fab-4496-8dd7-2c1a2650bfec
📒 Files selected for processing (10)
prisma/schema.prismasrc/app.jssrc/docs/schemas/commerce/banner-request.schema.jssrc/docs/schemas/index.jssrc/modules/admin/banners/admin-banners.controller.jssrc/modules/admin/banners/admin-banners.routes.jssrc/modules/admin/banners/admin-banners.service.jssrc/modules/commerce/banner-requests/banner-request.controller.jssrc/modules/commerce/banner-requests/banner-request.routes.jssrc/modules/commerce/banner-requests/banner-request.service.js
|



Schema Prisma: Se agregaron 3 campos al modelo Banners existente: fk_store (FK opcional a Stores), approval_status (enum ApprovalStatus, default PENDING) y rejection_reason. image_url pasó a opcional. Se registró la relación inversa en Stores.
Nuevo módulo commerce/banner-requests: Los comercios (SELLER) pueden crear solicitudes de banner, ver su historial filtrado por estado y cancelar solicitudes pendientes.
POST /api/stores/:storeId/banner-requests
GET /api/stores/:storeId/banner-requests
DELETE /api/stores/:storeId/banner-requests/:requestId Extensión del módulo admin: El administrador puede revisar las solicitudes de comercios y aprobarlas o rechazarlas (con motivo obligatorio).
GET /api/admin/banners/requests
PATCH /api/admin/banners/requests/:id
Summary by CodeRabbit
New Features
Documentation