Customers: sort nameless records last instead of first
The 44 customers with no recoverable name render as "(SIN NOMBRE)", and
ordering the list by name alone floated all of them to the top — "(" sorts
before every letter — so the first two screens of the customer browser were
nothing but placeholders. Small number, worst possible position.
Adds customers.nameMissing, set by the transform and used as the primary sort
key so those records land at the end of the list. Denormalized rather than
computed in the query because the list is paginated in SQL, so the ordering
has to be expressible as a column.
Applied to the dev DB as an ALTER + UPDATE in place (no truncate), so the
existing loaded data and its FKs were left alone.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -41,7 +41,9 @@ export class CustomersService {
|
||||
where,
|
||||
skip: (page - 1) * pageSize,
|
||||
take: pageSize,
|
||||
orderBy: { name: "asc" },
|
||||
// Nameless records last: ordering by name alone floats every
|
||||
// "(SIN NOMBRE)" to the top, since "(" sorts before every letter.
|
||||
orderBy: [{ nameMissing: "asc" }, { name: "asc" }],
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
|
||||
@@ -170,6 +170,7 @@ def customer_from_utilities(row, name_index) -> dict:
|
||||
id=str(uuid.uuid4()),
|
||||
name=name,
|
||||
nameSource=name_source,
|
||||
nameMissing=int(name == NO_NAME),
|
||||
addressLine1=s(row["direccion"]),
|
||||
addressLine2=s(row["colonia"]),
|
||||
city=s(row["ciudad"]),
|
||||
@@ -197,6 +198,7 @@ def customer_from_insurance(row, name_index) -> dict:
|
||||
id=str(uuid.uuid4()),
|
||||
name=name,
|
||||
nameSource=name_source,
|
||||
nameMissing=int(name == NO_NAME),
|
||||
addressLine1=s(row["direccion_1"]),
|
||||
addressLine2=s(row["direccion_2"]),
|
||||
city=s(row["ciudad"]),
|
||||
@@ -219,7 +221,7 @@ def customer_from_insurance(row, name_index) -> dict:
|
||||
|
||||
|
||||
_CUST_COLS = [
|
||||
"id", "name", "nameSource", "addressLine1", "addressLine2", "city", "state", "zipCode",
|
||||
"id", "name", "nameSource", "nameMissing", "addressLine1", "addressLine2", "city", "state", "zipCode",
|
||||
"country", "phone", "mobile", "fax", "email", "notes", "identificationType",
|
||||
"identificationNumber", "identificationExpiration", "customerSince",
|
||||
"status", "feeAmount", "updatedAt",
|
||||
@@ -276,6 +278,7 @@ def main() -> None:
|
||||
if master["name"] == NO_NAME and ins_rec["name"] != NO_NAME:
|
||||
master["name"] = ins_rec["name"]
|
||||
master["nameSource"] = ins_rec["nameSource"] or "DATGRAL (seguros)"
|
||||
master["nameMissing"] = 0
|
||||
from_ins_side += 1
|
||||
enrich.append((cust_id, ins_rec))
|
||||
else:
|
||||
|
||||
@@ -55,6 +55,10 @@ model Customer {
|
||||
// recovered from a secondary table (see migration/transform_customers.py),
|
||||
// so staff can tell a reconstructed name from an original one.
|
||||
nameSource String?
|
||||
// True when `name` is the "(SIN NOMBRE)" placeholder. Denormalized so lists
|
||||
// can sort nameless records last — ordering by `name` alone puts them first,
|
||||
// since "(" sorts before every letter.
|
||||
nameMissing Boolean @default(false)
|
||||
addressLine1 String?
|
||||
addressLine2 String?
|
||||
city String?
|
||||
|
||||
Reference in New Issue
Block a user