fix(berths): natural-sort SQL ordering for mooring numbers
Drizzle SQL template was running `\d+$` through JS string-literal escape rules, eating the backslash and matching every character class \d alias instead of digits. Berths sorted lexically (A1, A10, A11, A2, …) instead of by trailing number. Switch to `[0-9]+$` POSIX form which survives the escape pass intact. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -67,7 +67,7 @@ export async function listBerths(portId: string, query: ListBerthsQuery) {
|
||||
// map. The mooring format is locked at `^[A-Z]+\d+$` so the regexp
|
||||
// splits are safe.
|
||||
const NATURAL_MOORING_SORT = [
|
||||
sql`regexp_replace(${berths.mooringNumber}, '\d+$', '') ASC`,
|
||||
sql`regexp_replace(${berths.mooringNumber}, '[0-9]+$', '') ASC`,
|
||||
sql`(regexp_replace(${berths.mooringNumber}, '^[A-Z]+', ''))::int ASC`,
|
||||
];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user