-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSortQuery.ts
More file actions
33 lines (27 loc) · 749 Bytes
/
Copy pathSortQuery.ts
File metadata and controls
33 lines (27 loc) · 749 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/**
* **SortQuery** - Simple single-field sorting
*
* This is the most basic form where the consumer specifies a field and direction.
* The API accepts the full property path (dot-chained) and decides whether to allow it.
*
* Usage:
* `GET /users?sortBy=status&sortOrder=asc`
*/
export enum SortDirection {
ASC = "asc",
DESC = "desc",
}
export interface SimpleSortOptions {
sortBy?: string // e.g., "status", "user.createdAt"
sortOrder?: SortDirection
}
export function buildSimpleSort(sort?: SimpleSortOptions): URLSearchParams {
const params = new URLSearchParams()
if (sort?.sortBy) {
params.set("sortBy", sort.sortBy)
}
if (sort?.sortOrder) {
params.set("sortOrder", sort.sortOrder)
}
return params
}