|
1 |
| -const urls: Record< |
2 |
| - string, |
3 |
| - { |
4 |
| - list: string; |
5 |
| - detail: string; |
6 |
| - } |
7 |
| -> = { |
8 |
| - user: { |
9 |
| - list: 'users/', |
10 |
| - detail: 'users/<id>/' |
11 |
| - }, |
12 |
| - teacher: { |
13 |
| - list: 'users/teachers/', |
14 |
| - detail: 'users/teachers/<id>/' |
15 |
| - }, |
16 |
| - student: { |
17 |
| - list: 'users/students/', |
18 |
| - detail: 'users/students/<id>/' |
19 |
| - }, |
20 |
| - school: { |
21 |
| - list: 'schools/', |
22 |
| - detail: 'schools/<id>/' |
23 |
| - }, |
24 |
| - class: { |
25 |
| - list: 'classes/', |
26 |
| - detail: 'classes/<id>/' |
27 |
| - }, |
28 |
| - otpBypassToken: { |
29 |
| - list: 'otp-bypass-tokens/', |
30 |
| - detail: 'otp-bypass-tokens/<id>/' |
31 |
| - }, |
32 |
| - authFactor: { |
33 |
| - list: 'auth-factors/', |
34 |
| - detail: 'auth-factors/<id>/' |
35 |
| - } |
36 |
| -}; |
| 1 | +function url(list: string, detail: string) { |
| 2 | + if (list === detail) throw Error("List and detail are the same.") |
37 | 3 |
|
38 |
| -export default urls; |
| 4 | + return { list, detail } |
| 5 | +} |
| 6 | + |
| 7 | +const urls = { |
| 8 | + user: url("users/", "users/<id>/"), |
| 9 | + teacher: url("users/teachers/", "users/teachers/<id>/"), |
| 10 | + student: url("users/students/", "users/students/<id>/"), |
| 11 | + school: url("schools/", "schools/<id>/"), |
| 12 | + class: url("classes/", "classes/<id>/"), |
| 13 | + otpBypassToken: url("otp-bypass-tokens/", "otp-bypass-tokens/<id>/"), |
| 14 | + authFactor: url("auth-factors/", "auth-factors/<id>/"), |
| 15 | +} |
| 16 | + |
| 17 | +export default urls |
0 commit comments