Repository navigation
OM-489: Módulo delivery completo (entregas, asignaciones, reseñas) #128
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
Merged
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
5ab411f
OM-489: cree las validaciones zod para delivery
Benjakr04 c7e883b
OM-489: cree las validaciones zod para delivery
Benjakr04 abac5d3
OM-489: guardando estado de trabajo
Benjakr04 a99396e
OM-489: guardando estado de trabajo
Benjakr04 942c59e
OM-489: guardando estado de trabajo
Benjakr04 f263823
OM-489: he creado delivery.controller.js
Benjakr04 46a88a2
OM-489: guardando estado de trabajo
Benjakr04 b99d299
OM-489: ya esta el back de Delivery
Benjakr04 eb20e4a
OM-489: ya esta el back de Delivery
Benjakr04 362a22e
OM-489: guardando estado de trabajo
Benjakr04 4b254a1
OM-489: guardando estado de trabajo
Benjakr04 c0369ec
OM-489: ya esta el back de Delivery
Benjakr04 eb63589
OM-489: guardando estado de trabajo
Benjakr04 7c289bf
Merge branch 'dev' of https://github.com/CrisNAC/BackendMarketplace i…
Benjakr04 5ce5be8
OM-489: Implementar módulo completo de deliveries con assignments y r…
Benjakr04 e808a92
OM-489: arregle algunas cosas que me dijo CR
Benjakr04 d972fbe
OM-489: arregle algunas cosas que me dijo CR
Benjakr04 7cc3be6
OM-489: FIX 2
Benjakr04 3361613
OM-489: FIX 3
Benjakr04 a8eb97f
OM-489: FIX 4
Benjakr04 2e28af4
OM-489: FIX 5
Benjakr04 9f8d04b
OM-489: FIX 6
Benjakr04 b7f9ef4
OM-489: FIX 7
Benjakr04 a3669ee
OM-489: FIX 8
Benjakr04 1a7bf95
OM-489: FIX 9
Benjakr04 c2252d3
OM-489: FIX 10
Benjakr04 06a471a
OM-489: ya pasaron todos los tests
Benjakr04 bafd926
OM-489: ya pasaron todos los tests, e hice un pequeño cambio para pap…
Benjakr04 1c4cc76
OM-489: ya pasaron todos los tests, e hice un pequeño cambio para pap…
Benjakr04 ff3b63e
OM-489: ya pasaron todos los tests, e hice un pequeño cambio para pap…
Benjakr04 be0dcab
OM-489: correccion de rutas recomendada por Code Rabbit
Benjakr04 a94cdfd
OM-489: correccion de rutas recomendada por Code Rabbit
Benjakr04 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
2 changes: 2 additions & 0 deletions
2
prisma/migrations/20260428223931_add_delivered_to_assignment_status/migration.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| -- AlterEnum | ||
| ALTER TYPE "AssignmentStatus" ADD VALUE 'DELIVERED'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
166 changes: 166 additions & 0 deletions
166
src/modules/delivery/delivery-assignments/delivery-assignments.controller.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,166 @@ | ||
| //delivery.assignments.controller.js | ||
| import { ZodError } from 'zod'; | ||
| import { createAssignmentSchema } from './delivery-assignments.validation.js'; | ||
| import { | ||
| createAssignmentService, | ||
| getAssignmentByIdService, | ||
| getOrderAssignmentsService, | ||
| getDeliveryAssignmentsService, | ||
| getDeliveryPendingAssignmentsService, | ||
| getAcceptedAssignmentService, | ||
| completeAssignmentService | ||
| } from './delivery-assignments.service.js'; | ||
|
|
||
| // Crear asignación | ||
| export const createAssignment = async (req, res) => { | ||
| try { | ||
| const validData = createAssignmentSchema.parse(req.body); | ||
| const result = await createAssignmentService(validData); | ||
| res.status(201).json(result); | ||
| } catch (error) { | ||
| if (error instanceof ZodError) { | ||
| return res.status(400).json({ | ||
| error: { code: 400, message: "Datos inválidos", details: error.issues } | ||
| }); | ||
| } | ||
| return res.status(error.status || 500).json({ | ||
| error: { code: error.status || 500, message: error.message } | ||
| }); | ||
| } | ||
| }; | ||
|
|
||
| // Obtener asignación por ID | ||
| export const getAssignmentById = async (req, res) => { | ||
| try { | ||
| const { id } = req.params; | ||
|
|
||
| const assignmentId = Number.parseInt(id, 10); | ||
| if (Number.isNaN(assignmentId)) { | ||
| return res.status(400).json({ | ||
| error: { code: 400, message: "ID inválido" } | ||
| }); | ||
| } | ||
|
|
||
| const result = await getAssignmentByIdService(assignmentId); | ||
| res.json(result); | ||
| } catch (error) { | ||
| return res.status(error.status || 500).json({ | ||
| error: { code: error.status || 500, message: error.message } | ||
| }); | ||
| } | ||
| }; | ||
|
|
||
| // Obtener asignaciones de un pedido | ||
| export const getOrderAssignments = async (req, res) => { | ||
| try { | ||
| const { orderId } = req.params; | ||
|
|
||
| const orderIdNum = Number.parseInt(orderId, 10); | ||
| if (Number.isNaN(orderIdNum)) { | ||
| return res.status(400).json({ | ||
| error: { code: 400, message: "ID inválido" } | ||
| }); | ||
| } | ||
|
|
||
| const result = await getOrderAssignmentsService(orderIdNum); | ||
| res.json(result); | ||
| } catch (error) { | ||
| return res.status(error.status || 500).json({ | ||
| error: { code: error.status || 500, message: error.message } | ||
| }); | ||
| } | ||
| }; | ||
|
|
||
| // Obtener asignaciones de un delivery | ||
| export const getDeliveryAssignments = async (req, res) => { | ||
| try { | ||
| const { deliveryId } = req.params; | ||
| const { status } = req.query; | ||
|
|
||
| const deliveryIdNum = Number.parseInt(deliveryId, 10); | ||
| if (Number.isNaN(deliveryIdNum)) { | ||
| return res.status(400).json({ | ||
| error: { code: 400, message: "ID inválido" } | ||
| }); | ||
| } | ||
|
|
||
| // Validar status contra enum | ||
| const validStatuses = ["PENDING", "ACCEPTED", "REJECTED", "DELIVERED"]; | ||
| if (status && !validStatuses.includes(status)) { | ||
| return res.status(400).json({ | ||
| error: { code: 400, message: `Status inválido. Debe ser uno de: ${validStatuses.join(", ")}` } | ||
| }); | ||
| } | ||
|
|
||
| const result = await getDeliveryAssignmentsService(deliveryIdNum, status || null); | ||
| res.json(result); | ||
| } catch (error) { | ||
| return res.status(error.status || 500).json({ | ||
| error: { code: error.status || 500, message: error.message } | ||
| }); | ||
| } | ||
| }; | ||
|
|
||
| // Obtener asignaciones PENDING de un delivery | ||
| export const getDeliveryPendingAssignments = async (req, res) => { | ||
| try { | ||
| const { deliveryId } = req.params; | ||
|
|
||
| const deliveryIdNum = Number.parseInt(deliveryId, 10); | ||
| if (Number.isNaN(deliveryIdNum)) { | ||
| return res.status(400).json({ | ||
| error: { code: 400, message: "ID inválido" } | ||
| }); | ||
| } | ||
|
|
||
| const result = await getDeliveryPendingAssignmentsService(deliveryIdNum); | ||
| res.json(result); | ||
| } catch (error) { | ||
| return res.status(error.status || 500).json({ | ||
| error: { code: error.status || 500, message: error.message } | ||
| }); | ||
| } | ||
| }; | ||
|
|
||
| // Obtener la asignación aceptada de un pedido | ||
| export const getAcceptedAssignment = async (req, res) => { | ||
| try { | ||
| const { orderId } = req.params; | ||
|
|
||
| const orderIdNum = Number.parseInt(orderId, 10); | ||
| if (Number.isNaN(orderIdNum)) { | ||
| return res.status(400).json({ | ||
| error: { code: 400, message: "ID inválido" } | ||
| }); | ||
| } | ||
|
|
||
| const result = await getAcceptedAssignmentService(orderIdNum); | ||
| res.json(result); | ||
| } catch (error) { | ||
| return res.status(error.status || 500).json({ | ||
| error: { code: error.status || 500, message: error.message } | ||
| }); | ||
| } | ||
| }; | ||
|
|
||
| // Completar asignación (marcar como entregado) | ||
| export const completeAssignment = async (req, res) => { | ||
| try { | ||
| const { id } = req.params; | ||
|
|
||
| const assignmentId = Number.parseInt(id, 10); | ||
| if (Number.isNaN(assignmentId)) { | ||
| return res.status(400).json({ | ||
| error: { code: 400, message: "ID inválido" } | ||
| }); | ||
| } | ||
|
|
||
| // Pasar id_user autenticado al service | ||
| const result = await completeAssignmentService(assignmentId, req.user.id_user); | ||
| res.json(result); | ||
| } catch (error) { | ||
| return res.status(error.status || 500).json({ | ||
| error: { code: error.status || 500, message: error.message } | ||
| }); | ||
| } | ||
| }; | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.