forked from StellarSplit/StellarSplit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapiRouteRegistry.ts
More file actions
69 lines (60 loc) · 1.88 KB
/
Copy pathapiRouteRegistry.ts
File metadata and controls
69 lines (60 loc) · 1.88 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/**
* Explicit API route registry.
*
* Every endpoint is declared as an explicit named constant rather than
* being guessed or inferred from fallback path variants. This makes the
* request behavior transparent and allows frontend code to discover all
* available endpoints.
*
* Usage:
* const path = ApiRoutes.splits.byId(splitId)
* await request<ApiSplitRecord>({ method: 'get', endpoint: path })
*/
export const ApiRoutes = {
splits: {
byId: (id: string) => `/splits/${id}`,
create: () => '/splits',
list: () => '/splits',
},
payments: {
bySplit: (splitId: string) => `/payments/split/${splitId}`,
stats: (splitId: string) => `/payments/stats/${splitId}`,
submit: () => '/payments/submit',
},
receipts: {
bySplit: (splitId: string) => `/receipts/split/${splitId}`,
upload: (splitId: string) => `/receipts/upload/${splitId}`,
signedUrl: (receiptId: string) => `/receipts/${receiptId}/signed-url`,
ocrData: (receiptId: string) => `/receipts/${receiptId}/ocr-data`,
},
items: {
create: () => '/items',
byId: (itemId: string) => `/items/${itemId}`,
},
profile: {
byWallet: (walletAddress: string) => `/profile/${walletAddress}`,
},
dashboard: {
summary: () => '/dashboard/summary',
activity: () => '/dashboard/activity',
},
activities: {
byUser: (userId: string) => `/activities/${userId}`,
create: () => '/activities',
},
analytics: {
overview: () => '/analytics/overview',
payments: () => '/analytics/payments',
splits: () => '/analytics/splits',
},
} as const;
/**
* Get the path for a given route function or endpoint string.
* This allows routes to be referenced either as functions or strings
* in a type-safe way.
*/
export function getRoutePath(
routeOrPath: string | (() => string),
): string {
return typeof routeOrPath === 'function' ? routeOrPath() : routeOrPath;
}