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

@@ -173,9 +173,13 @@ export class PgOrderRepository implements OrderRepository {
async findById(id: string): Promise<OrderView | undefined> {
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
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`,
[id],
);
@@ -207,9 +211,13 @@ export class PgOrderRepository implements OrderRepository {
async findByIdAndUserId(id: string, userId: string): Promise<OrderView | undefined> {
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
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`,
[id, userId],
);
@@ -294,6 +302,8 @@ function toOrder(row: OrderRow): Order {
totalCents: row.total_cents,
trackingNumber: row.tracking_number,
courier: row.courier,
customerName: row.customer_name ?? null,
customerPhone: row.customer_phone ?? null,
createdAt: row.created_at,
updatedAt: row.updated_at,
};