feat(F-161): completed feature

This commit is contained in:
chattie
2026-08-22 18:13:37 +02:00
parent 83a44980c6
commit 9152b3a65e
15 changed files with 164 additions and 63 deletions

View File

@@ -6751,13 +6751,15 @@
"description": "Order detail must show shipping address, payment method, customer details and correct customer email without false missing-email warning.", "description": "Order detail must show shipping address, payment method, customer details and correct customer email without false missing-email warning.",
"priority": "high", "priority": "high",
"risk": "med", "risk": "med",
"status": "pending", "status": "done",
"created_at": "2026-08-22", "created_at": "2026-08-22",
"gates": { "gates": {
"reviewer": false, "reviewer": true,
"security": false, "security": true,
"qa": false "qa": true,
} "close": true
},
"completed_at": "2026-08-22T16:13:37Z"
}, },
{ {
"id": "F-162", "id": "F-162",
@@ -6788,6 +6790,21 @@
"security": false, "security": false,
"qa": false "qa": false
} }
},
{
"id": "F-164",
"type": "fix",
"title": "Update outdated POS Next.js",
"description": "Upgrade POS Next.js from outdated 15.x to the supported version aligned with Admin and fix resulting config/build compatibility.",
"priority": "high",
"risk": "med",
"status": "pending",
"created_at": "2026-08-22",
"gates": {
"reviewer": false,
"security": false,
"qa": false
}
} }
] ]
} }

View File

@@ -526,46 +526,55 @@ export default function OrderDetailPage() {
{/* Sidebar */} {/* Sidebar */}
<div className="space-y-6"> <div className="space-y-6">
{/* F-140: Customer + Addresses + Payment */} {/* F-140: Customer + Addresses + Payment */}
{(order.email || order.customerName) && (
<div className="bg-white border border-gray-200 rounded-xl p-6"> <div className="bg-white border border-gray-200 rounded-xl p-6">
<h2 className="font-bold text-gray-900 mb-4">Cliente</h2> <h2 className="font-bold text-gray-900 mb-4">Cliente</h2>
<div className="space-y-1 text-sm"> <dl className="space-y-2 text-sm">
{order.customerName && <p className="font-medium text-gray-900">{order.customerName}</p>} <div>
{order.email && <p className="text-gray-600">{order.email}</p>} <dt className="text-xs font-semibold uppercase tracking-wide text-gray-400">Nombre</dt>
{(order.phone || order.customerPhone) && ( <dd className="font-medium text-gray-900">{order.customerName || order.shippingAddress?.recipientName || 'No registrado'}</dd>
<p className="text-gray-600">{order.customerPhone || order.phone}</p>
)}
</div> </div>
<div>
<dt className="text-xs font-semibold uppercase tracking-wide text-gray-400">Email</dt>
<dd className={order.email ? 'text-gray-700' : 'text-amber-700'}>{order.email || 'No registrado'}</dd>
</div>
<div>
<dt className="text-xs font-semibold uppercase tracking-wide text-gray-400">Teléfono</dt>
<dd className="text-gray-700">{order.customerPhone || order.phone || 'No registrado'}</dd>
</div>
</dl>
</div> </div>
)}
{order.shippingAddress && (
<div className="bg-white border border-gray-200 rounded-xl p-6"> <div className="bg-white border border-gray-200 rounded-xl p-6">
<h2 className="font-bold text-gray-900 mb-4">Dirección de envío</h2> <h2 className="font-bold text-gray-900 mb-4">Dirección de envío</h2>
{order.shippingAddress ? (
<div className="space-y-1 text-sm text-gray-700"> <div className="space-y-1 text-sm text-gray-700">
<p className="font-medium">{order.shippingAddress.recipientName}</p> <p className="font-medium">{order.shippingAddress.recipientName}</p>
<p>{order.shippingAddress.street}</p> <p>{order.shippingAddress.street}</p>
<p>{order.shippingAddress.postalCode} {order.shippingAddress.city}</p> <p>{order.shippingAddress.postalCode} {order.shippingAddress.city}</p>
<p>{order.shippingAddress.country}</p> <p>{order.shippingAddress.country}</p>
</div> </div>
</div> ) : (
<p className="text-sm text-amber-700">No registrada para este pedido.</p>
)} )}
</div>
{order.billingAddress && (
<div className="bg-white border border-gray-200 rounded-xl p-6"> <div className="bg-white border border-gray-200 rounded-xl p-6">
<h2 className="font-bold text-gray-900 mb-4">Dirección de facturación</h2> <h2 className="font-bold text-gray-900 mb-4">Dirección de facturación</h2>
{order.billingAddress ? (
<div className="space-y-1 text-sm text-gray-700"> <div className="space-y-1 text-sm text-gray-700">
<p className="font-medium">{order.billingAddress.recipientName}</p> <p className="font-medium">{order.billingAddress.recipientName}</p>
<p>{order.billingAddress.street}</p> <p>{order.billingAddress.street}</p>
<p>{order.billingAddress.postalCode} {order.billingAddress.city}</p> <p>{order.billingAddress.postalCode} {order.billingAddress.city}</p>
<p>{order.billingAddress.country}</p> <p>{order.billingAddress.country}</p>
</div> </div>
</div> ) : (
<p className="text-sm text-gray-500">No registrada; consultar la dirección de envío.</p>
)} )}
</div>
{order.payment && (
<div className="bg-white border border-gray-200 rounded-xl p-6"> <div className="bg-white border border-gray-200 rounded-xl p-6">
<h2 className="font-bold text-gray-900 mb-4">Pago</h2> <h2 className="font-bold text-gray-900 mb-4">Pago</h2>
{order.payment ? (
<div className="space-y-1 text-sm"> <div className="space-y-1 text-sm">
<div className="flex justify-between"> <div className="flex justify-between">
<span className="text-gray-600">Método</span> <span className="text-gray-600">Método</span>
@@ -593,8 +602,10 @@ export default function OrderDetailPage() {
</span> </span>
</div> </div>
</div> </div>
</div> ) : (
<p className="text-sm text-gray-500">No hay una transacción de pago registrada para este pedido.</p>
)} )}
</div>
{/* F-140 already shown above — keep existing Envío section */} {/* F-140 already shown above — keep existing Envío section */}
{/* Envío */} {/* Envío */}
<div className="bg-white border border-gray-200 rounded-xl p-6"> <div className="bg-white border border-gray-200 rounded-xl p-6">

View File

@@ -105,7 +105,7 @@ export const ordersApi = {
`/api/orders${qs ? `?${qs}` : ''}`, `/api/orders${qs ? `?${qs}` : ''}`,
).then((data) => (Array.isArray(data) ? { items: data, total: data.length } : data)); ).then((data) => (Array.isArray(data) ? { items: data, total: data.length } : data));
}, },
get: (id: string) => api.get<import('@/types').Order>(`/api/orders/${id}`), get: (id: string) => api.get<import('@/types').Order>(`/api/orders/${id}/admin`),
transition: (id: string, state: string, trackingNumber?: string, courier?: string) => transition: (id: string, state: string, trackingNumber?: string, courier?: string) =>
api.post<import('@/types').Order & { notified?: boolean; notificationError?: string }>( api.post<import('@/types').Order & { notified?: boolean; notificationError?: string }>(
`/api/orders/${id}/transitions/admin`, `/api/orders/${id}/transitions/admin`,

View File

@@ -342,7 +342,9 @@ export async function buildApp(deps: BuildAppDeps = {}): Promise<FastifyInstance
await app.register(async (instance) => { await app.register(async (instance) => {
await registerCheckoutRoutes(instance, { await registerCheckoutRoutes(instance, {
pool: deps.pool as pg.Pool, pool: deps.pool as pg.Pool,
authenticate: combinedAuth, // Checkout creates customer-owned orders. Do not use combinedAuth here:
// a coexisting backoffice cookie must never override the storefront user.
authenticate,
tracer: telemetry.tracer, tracer: telemetry.tracer,
}); });
}); });

View File

@@ -25,6 +25,9 @@ const BASE_ORDER = {
total_cents: 1210, total_cents: 1210,
tracking_number: null, tracking_number: null,
courier: null, courier: null,
customer_name: null,
customer_phone: null,
phone: null,
created_at: new Date('2026-01-01T00:00:00Z'), created_at: new Date('2026-01-01T00:00:00Z'),
updated_at: new Date('2026-01-01T00:00:00Z'), updated_at: new Date('2026-01-01T00:00:00Z'),
}; };
@@ -40,9 +43,28 @@ describe('PgOrderRepository.findById — F-153 customer email association', () =
expect(result!.email).toBe('customer@example.com'); expect(result!.email).toBe('customer@example.com');
const orderQuery = String(query.mock.calls[0]![0]); const orderQuery = String(query.mock.calls[0]![0]);
expect(orderQuery).toContain('identity_users'); expect(orderQuery).toContain('identity_users');
expect(orderQuery).toContain('users_profiles');
expect(orderQuery).toContain('COALESCE(o.customer_name, p.display_name)');
expect(orderQuery).toContain('u.email'); expect(orderQuery).toContain('u.email');
}); });
it('maps customer name and phone resolved by the read query', async () => {
const { pool } = mockPool({
...BASE_ORDER,
email: 'customer@example.com',
customer_name: 'Cliente Ejemplo',
customer_phone: '+34600000000',
phone: '+34600000000',
});
const repo = new PgOrderRepository(pool);
const result = await repo.findById('order-1');
expect(result?.customerName).toBe('Cliente Ejemplo');
expect(result?.customerPhone).toBe('+34600000000');
expect(result?.phone).toBe('+34600000000');
});
it('returns null email when the order has no linked identity_user', async () => { it('returns null email when the order has no linked identity_user', async () => {
const { pool } = mockPool({ ...BASE_ORDER, email: null }); const { pool } = mockPool({ ...BASE_ORDER, email: null });
const repo = new PgOrderRepository(pool); const repo = new PgOrderRepository(pool);

View File

@@ -173,9 +173,13 @@ export class PgOrderRepository implements OrderRepository {
async findById(id: string): Promise<OrderView | undefined> { async findById(id: string): Promise<OrderView | undefined> {
const orderResult = await this.pool.query<OrderRow>( const orderResult = await this.pool.query<OrderRow>(
`SELECT o.*, u.email, u.phone `SELECT o.*, u.email,
COALESCE(o.customer_name, p.display_name) AS customer_name,
COALESCE(o.customer_phone, p.phone, u.phone) AS customer_phone,
COALESCE(u.phone, p.phone) AS phone
FROM orders_orders o FROM orders_orders o
LEFT JOIN identity_users u ON u.id = o.user_id LEFT JOIN identity_users u ON u.id = o.user_id
LEFT JOIN users_profiles p ON p.user_id = o.user_id
WHERE o.id = $1`, WHERE o.id = $1`,
[id], [id],
); );
@@ -207,9 +211,13 @@ export class PgOrderRepository implements OrderRepository {
async findByIdAndUserId(id: string, userId: string): Promise<OrderView | undefined> { async findByIdAndUserId(id: string, userId: string): Promise<OrderView | undefined> {
const orderResult = await this.pool.query<OrderRow>( const orderResult = await this.pool.query<OrderRow>(
`SELECT o.*, u.email, u.phone `SELECT o.*, u.email,
COALESCE(o.customer_name, p.display_name) AS customer_name,
COALESCE(o.customer_phone, p.phone, u.phone) AS customer_phone,
COALESCE(u.phone, p.phone) AS phone
FROM orders_orders o FROM orders_orders o
LEFT JOIN identity_users u ON u.id = o.user_id LEFT JOIN identity_users u ON u.id = o.user_id
LEFT JOIN users_profiles p ON p.user_id = o.user_id
WHERE o.id = $1 AND o.user_id = $2`, WHERE o.id = $1 AND o.user_id = $2`,
[id, userId], [id, userId],
); );
@@ -294,6 +302,8 @@ function toOrder(row: OrderRow): Order {
totalCents: row.total_cents, totalCents: row.total_cents,
trackingNumber: row.tracking_number, trackingNumber: row.tracking_number,
courier: row.courier, courier: row.courier,
customerName: row.customer_name ?? null,
customerPhone: row.customer_phone ?? null,
createdAt: row.created_at, createdAt: row.created_at,
updatedAt: row.updated_at, updatedAt: row.updated_at,
}; };

View File

@@ -0,0 +1,16 @@
# F-161 — Diseño
## Auth boundary
`registerCheckoutRoutes` recibe `createSessionAuthenticator` (identity) en lugar de `combinedAuth`. Las rutas admin/orders permanecen combined porque sirven ambos contextos; checkout es customer-only.
## Read model
`PgOrderRepository.findById` y `findByIdAndUserId` añaden `users_profiles` y resuelven:
- nombre: snapshot `orders_orders.customer_name` → perfil.
- teléfono: snapshot → perfil → identity.
- email: identity user.
## UI
Las cuatro tarjetas de información siempre se renderizan. Si el backend no tiene una transacción o dirección de facturación, se comunica «No registrado»/«Misma que envío» en vez de ocultar la sección.
## Datos existentes
El único pedido afectado, creado segundos después del perfil/dirección del cliente, se reasocia al identity user correspondiente. No se crea una migración heurística general.

View File

@@ -0,0 +1,3 @@
# F-161
El detalle admin muestra siempre Cliente, Dirección de envío, Dirección de facturación y Pago. Los datos no registrados se indican expresamente. Checkout queda ligado solo a la sesión customer.

View File

@@ -0,0 +1,14 @@
# F-161 — Implementer
## Cambios
- Checkout usa auth identity y ya no puede asignar pedidos al backoffice cuando coexisten cookies.
- Read model une `users_profiles` y resuelve nombre/teléfono con snapshots como prioridad.
- `toOrder` vuelve a exponer `customerName/customerPhone` (se estaban descartando).
- Admin usa `/orders/:id/admin`, no el endpoint customer limitado al propietario.
- Cliente, envío, facturación y pago siempre se muestran con fallbacks explícitos.
- Pedido local afectado reasociado al customer correcto.
## Evidencia
- 6/6 tests target PASS; tsc PASS; admin build PASS.
- Runtime: email `info@rikrdo.es`, nombre `Ricardo Echeverriabarrena`, teléfono y dirección Benahavis presentes.
- Facturación/pago ausentes aparecen como no registrados.

View File

@@ -0,0 +1 @@
{"feature_id":"F-161","agent":"leader","stage":"close","verdict":"APPROVED","summary":"Order detail and checkout ownership fixed.","checks":[{"item":"all gates","ok":true},{"item":"runtime data","ok":true},{"item":"build/tests","ok":true}],"issues":[]}

View File

@@ -0,0 +1 @@
{"feature_id":"F-161","agent":"qa","stage":"qa_gate","verdict":"APPROVED","summary":"Detalle runtime contiene cliente y envío; tarjetas de facturación/pago muestran fallback.","checks":[{"item":"email/name/phone","ok":true},{"item":"shipping address","ok":true},{"item":"missing data fallback","ok":true},{"item":"tests/build","ok":true}],"issues":[]}

View File

@@ -0,0 +1 @@
{"feature_id":"F-161","agent":"reviewer","stage":"review_gate","verdict":"APPROVED","summary":"Se corrige la causa de ownership y el detalle deja de ocultar secciones.","checks":[{"item":"auth boundary","ok":true},{"item":"read model","ok":true},{"item":"admin endpoint","ok":true},{"item":"build/tests","ok":true}],"issues":[]}

View File

@@ -0,0 +1 @@
{"feature_id":"F-161","agent":"security","stage":"security_gate","verdict":"APPROVED","summary":"Checkout queda aislado a identity auth; detalle admin sigue protegido por rol admin.","checks":[{"item":"customer ownership","ok":true},{"item":"admin RBAC","ok":true},{"item":"no PII exposure to customer route","ok":true}],"issues":[]}

View File

@@ -1,14 +1,16 @@
# Feature activa: F-160Fix Reporting sales grouped queries returning 500 # Feature activa: F-161Complete admin order detail information
## Causa raíz ## Diagnóstico
`runSalesQuery` concatena `${selectExpr}` directamente antes de `COUNT(...)` sin coma, generando SQL inválido en todos los grupos. Además, el grupo `terminal` selecciona `o.store_id` pero agrupa solo por `terminal_id`. El pedido existente se creó con `user_id` de `backoffice_users` porque Checkout usa `combinedAuth`, que prioriza `backoffice_session` si ambos cookies existen. Por eso el JOIN a `identity_users` no encuentra email, perfil ni dirección. La UI además oculta por completo Cliente, Direcciones y Pago cuando faltan datos.
## Solución ## Solución
- Añadir coma explícita tras las columnas dimensionales. - Checkout debe usar exclusivamente el autenticador de identidad/customer.
- Agrupar terminal por `store_id, terminal_id`. - El detalle obtiene nombre/teléfono desde `users_profiles` como fallback.
- Añadir tests de integración del servicio SQL real para day/channel/store/terminal. - Las tarjetas Cliente, Envío, Facturación y Pago siempre aparecen, mostrando estado explícito cuando un dato no fue registrado.
- Reparar la asociación del pedido local afectado con el cliente correcto.
## Aceptación ## Aceptación
- Los cuatro endpoints usados por Dashboard responden 200. - El pedido muestra email, nombre, teléfono y dirección de envío.
- No hay interpolación de valores del usuario; solo expresiones de enum controlado. - No aparece el falso aviso «El cliente no tiene email asociado».
- Build, tests y verify pasan. - Pago/facturación ausentes se muestran como «No registrado», no desaparecen.
- Futuros checkouts no usan sesiones backoffice.

View File

@@ -1,68 +1,68 @@
{ {
"feature_id": "F-160", "feature_id": "F-161",
"stage": "close", "stage": "close",
"agent": "leader", "agent": "leader",
"action": "Close Reporting sales fix", "action": "Close complete order detail fix",
"state": "running", "state": "running",
"next_agent": "leader", "next_agent": "leader",
"waiting_for": "Seleccionar una feature pending y actualizar este estado", "waiting_for": "Seleccionar una feature pending y actualizar este estado",
"updated_at": "2026-08-22T16:05:20Z", "updated_at": "2026-08-22T16:13:24Z",
"timeline": [ "timeline": [
{ {
"ts": "2026-08-22T16:02:17Z", "ts": "2026-08-22T16:05:41Z",
"agent": "leader", "agent": "leader",
"stage": "intake", "stage": "intake",
"state": "running", "state": "running",
"message": "Diagnose grouped Reporting sales SQL 500" "message": "Audit order detail customer, shipping and payment data"
}, },
{ {
"ts": "2026-08-22T16:02:44Z", "ts": "2026-08-22T16:07:57Z",
"agent": "architect", "agent": "architect",
"stage": "design", "stage": "design",
"state": "running", "state": "running",
"message": "Specify grouped sales SQL correction" "message": "Design customer-only checkout auth and complete detail fallbacks"
}, },
{ {
"ts": "2026-08-22T16:03:01Z", "ts": "2026-08-22T16:08:21Z",
"agent": "implementer", "agent": "implementer",
"stage": "build", "stage": "build",
"state": "running", "state": "running",
"message": "Fix grouped sales SQL and add regression coverage" "message": "Fix checkout ownership and order detail read model"
}, },
{ {
"ts": "2026-08-22T16:04:34Z", "ts": "2026-08-22T16:12:38Z",
"agent": "reviewer", "agent": "reviewer",
"stage": "review_gate", "stage": "review_gate",
"state": "running", "state": "running",
"message": "Review SQL regression fix" "message": "Review order ownership and detail completeness"
}, },
{ {
"ts": "2026-08-22T16:04:45Z", "ts": "2026-08-22T16:12:50Z",
"agent": "security", "agent": "security",
"stage": "security_gate", "stage": "security_gate",
"state": "running", "state": "running",
"message": "Verify SQL parameterization remains safe" "message": "Verify customer ownership isolation"
}, },
{ {
"ts": "2026-08-22T16:04:57Z", "ts": "2026-08-22T16:13:04Z",
"agent": "qa", "agent": "qa",
"stage": "qa_gate", "stage": "qa_gate",
"state": "running", "state": "running",
"message": "Validate grouped reporting endpoints" "message": "Validate order customer/address/payment sections"
}, },
{ {
"ts": "2026-08-22T16:05:11Z", "ts": "2026-08-22T16:13:13Z",
"agent": "documenter", "agent": "documenter",
"stage": "document", "stage": "document",
"state": "running", "state": "running",
"message": "Record Reporting SQL fix" "message": "Document complete order detail"
}, },
{ {
"ts": "2026-08-22T16:05:20Z", "ts": "2026-08-22T16:13:24Z",
"agent": "leader", "agent": "leader",
"stage": "close", "stage": "close",
"state": "running", "state": "running",
"message": "Close Reporting sales fix" "message": "Close complete order detail fix"
} }
] ]
} }