diff --git a/src/lib/server/orders-service.ts b/src/lib/server/orders-service.ts index 14a9143..32e0cde 100644 --- a/src/lib/server/orders-service.ts +++ b/src/lib/server/orders-service.ts @@ -682,9 +682,16 @@ export async function getOrdersArchiveData( const av = (a as unknown as Record)[sortKey]; const bv = (b as unknown as Record)[sortKey]; if (av === bv) return 0; - if (av === undefined) return 1; - if (bv === undefined) return -1; - return (av > bv ? 1 : -1) * sortDir; + // PB returns `null` for unset fields (e.g. `updated`, `email_body`) + // and `undefined` for absent fields. Treat both as "missing" + // and sink them to the end of an ascending sort, the start of + // a descending sort. Avoids the `av > bv` comparison where one + // side is null and TS strict mode rejects the >. + if (av == null) return 1; + if (bv == null) return -1; + if (av > bv) return 1 * sortDir; + if (av < bv) return -1 * sortDir; + return 0; }); const totalItems = filtered.length; diff --git a/src/lib/server/quotes-service.ts b/src/lib/server/quotes-service.ts index 01f9afe..6d3a74f 100644 --- a/src/lib/server/quotes-service.ts +++ b/src/lib/server/quotes-service.ts @@ -670,9 +670,16 @@ export async function getQuotesArchiveData( const av = (a as unknown as Record)[sortKey]; const bv = (b as unknown as Record)[sortKey]; if (av === bv) return 0; - if (av === undefined) return 1; - if (bv === undefined) return -1; - return (av > bv ? 1 : -1) * sortDir; + // PB returns `null` for unset fields (e.g. `updated`, `email_body`) + // and `undefined` for absent fields. Treat both as "missing" + // and sink them to the end of an ascending sort, the start of + // a descending sort. Avoids the `av > bv` comparison where one + // side is null and TS strict mode rejects the >. + if (av == null) return 1; + if (bv == null) return -1; + if (av > bv) return 1 * sortDir; + if (av < bv) return -1 * sortDir; + return 0; }); const totalItems = filtered.length;