@spotsdev/sdk 1.0.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/client.d.ts +1 -1
- package/dist/api/client.js +7 -3
- package/dist/api/entities.d.ts +318 -0
- package/dist/api/entities.js +9 -0
- package/dist/api/mutations/clubs.d.ts +6 -6
- package/dist/api/mutations/clubs.js +12 -10
- package/dist/api/mutations/conversations.d.ts +7 -7
- package/dist/api/mutations/conversations.js +17 -13
- package/dist/api/mutations/index.js +1 -1
- package/dist/api/mutations/notifications.d.ts +4 -4
- package/dist/api/mutations/notifications.js +7 -7
- package/dist/api/mutations/orders.d.ts +7 -7
- package/dist/api/mutations/orders.js +11 -13
- package/dist/api/mutations/posts.d.ts +13 -13
- package/dist/api/mutations/posts.js +41 -29
- package/dist/api/mutations/products.d.ts +5 -5
- package/dist/api/mutations/products.js +9 -13
- package/dist/api/mutations/spots.d.ts +42 -8
- package/dist/api/mutations/spots.js +51 -13
- package/dist/api/mutations/users.d.ts +12 -10
- package/dist/api/mutations/users.js +20 -18
- package/dist/api/queries/auth.d.ts +5 -5
- package/dist/api/queries/auth.js +7 -7
- package/dist/api/queries/clubs.d.ts +7 -7
- package/dist/api/queries/clubs.js +11 -11
- package/dist/api/queries/conversations.d.ts +5 -5
- package/dist/api/queries/conversations.js +7 -7
- package/dist/api/queries/index.js +1 -1
- package/dist/api/queries/misc.d.ts +8 -32
- package/dist/api/queries/misc.js +28 -66
- package/dist/api/queries/notifications.d.ts +4 -4
- package/dist/api/queries/notifications.js +5 -5
- package/dist/api/queries/orders.d.ts +4 -4
- package/dist/api/queries/orders.js +7 -7
- package/dist/api/queries/posts.d.ts +44 -7
- package/dist/api/queries/posts.js +118 -15
- package/dist/api/queries/products.d.ts +6 -10
- package/dist/api/queries/products.js +7 -9
- package/dist/api/queries/spots.d.ts +31 -16
- package/dist/api/queries/spots.js +113 -31
- package/dist/api/queries/templates.d.ts +6 -9
- package/dist/api/queries/templates.js +8 -13
- package/dist/api/queries/users.d.ts +25 -11
- package/dist/api/queries/users.js +75 -27
- package/dist/api/types.d.ts +36 -33
- package/dist/api/types.js +6 -7
- package/dist/index.d.ts +1 -2
- package/dist/index.js +1 -8
- package/package.json +6 -21
- package/src/api/client.ts +45 -30
- package/src/api/entities.ts +424 -0
- package/src/api/mutations/clubs.ts +73 -40
- package/src/api/mutations/conversations.ts +91 -47
- package/src/api/mutations/index.ts +8 -8
- package/src/api/mutations/notifications.ts +48 -25
- package/src/api/mutations/orders.ts +101 -70
- package/src/api/mutations/posts.ts +229 -118
- package/src/api/mutations/products.ts +120 -81
- package/src/api/mutations/spots.ts +167 -55
- package/src/api/mutations/users.ts +109 -76
- package/src/api/queries/auth.ts +49 -24
- package/src/api/queries/clubs.ts +53 -38
- package/src/api/queries/conversations.ts +48 -30
- package/src/api/queries/index.ts +21 -21
- package/src/api/queries/misc.ts +53 -82
- package/src/api/queries/notifications.ts +32 -21
- package/src/api/queries/orders.ts +59 -42
- package/src/api/queries/posts.ts +203 -48
- package/src/api/queries/products.ts +51 -44
- package/src/api/queries/spots.ts +216 -85
- package/src/api/queries/templates.ts +39 -32
- package/src/api/queries/users.ts +157 -64
- package/src/api/types.ts +72 -118
- package/src/index.ts +5 -11
|
@@ -4,10 +4,16 @@
|
|
|
4
4
|
* TanStack Query hooks for user mutation operations.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
import {
|
|
8
|
+
useMutation,
|
|
9
|
+
type UseMutationOptions,
|
|
10
|
+
type UseMutationResult,
|
|
11
|
+
useQueryClient,
|
|
12
|
+
} from '@tanstack/react-query'
|
|
13
|
+
|
|
14
|
+
import {getApiClient} from '../client'
|
|
15
|
+
import {userKeys} from '../queries/users'
|
|
16
|
+
import {type ApiResponse, type UpdateProfileRequest, type User} from '../types'
|
|
11
17
|
|
|
12
18
|
// ============================================================================
|
|
13
19
|
// MUTATION HOOKS
|
|
@@ -16,182 +22,209 @@ import type { User, UpdateProfileRequest, ApiResponse } from '../types';
|
|
|
16
22
|
/**
|
|
17
23
|
* Update current user's profile
|
|
18
24
|
*
|
|
19
|
-
* @endpoint PUT /
|
|
25
|
+
* @endpoint PUT /users/me
|
|
20
26
|
*/
|
|
21
27
|
export function useUpdateProfile(
|
|
22
|
-
options?: Omit<
|
|
28
|
+
options?: Omit<
|
|
29
|
+
UseMutationOptions<User, Error, UpdateProfileRequest>,
|
|
30
|
+
'mutationFn'
|
|
31
|
+
>,
|
|
23
32
|
): UseMutationResult<User, Error, UpdateProfileRequest> {
|
|
24
|
-
const queryClient = useQueryClient()
|
|
33
|
+
const queryClient = useQueryClient()
|
|
25
34
|
|
|
26
35
|
return useMutation({
|
|
27
36
|
mutationFn: async (data: UpdateProfileRequest): Promise<User> => {
|
|
28
|
-
const client = getApiClient()
|
|
29
|
-
const response = await client.put<ApiResponse<User>>('/
|
|
30
|
-
return response.data.data
|
|
37
|
+
const client = getApiClient()
|
|
38
|
+
const response = await client.put<ApiResponse<User>>('/users/me', data)
|
|
39
|
+
return response.data.data
|
|
31
40
|
},
|
|
32
|
-
onSuccess:
|
|
33
|
-
queryClient.setQueryData(userKeys.me(), data)
|
|
41
|
+
onSuccess: data => {
|
|
42
|
+
queryClient.setQueryData(userKeys.me(), data)
|
|
34
43
|
},
|
|
35
44
|
...options,
|
|
36
|
-
})
|
|
45
|
+
})
|
|
37
46
|
}
|
|
38
47
|
|
|
39
48
|
/**
|
|
40
49
|
* Upload avatar
|
|
41
50
|
*
|
|
42
|
-
*
|
|
51
|
+
* Uploads avatar file and updates user profile in one request.
|
|
52
|
+
*
|
|
53
|
+
* @endpoint POST /users/me/avatar
|
|
43
54
|
*/
|
|
44
55
|
export function useUploadAvatar(
|
|
45
|
-
options?: Omit<
|
|
46
|
-
|
|
47
|
-
|
|
56
|
+
options?: Omit<
|
|
57
|
+
UseMutationOptions<{avatarUrl: string}, Error, FormData>,
|
|
58
|
+
'mutationFn'
|
|
59
|
+
>,
|
|
60
|
+
): UseMutationResult<{avatarUrl: string}, Error, FormData> {
|
|
61
|
+
const queryClient = useQueryClient()
|
|
48
62
|
|
|
49
63
|
return useMutation({
|
|
50
|
-
mutationFn: async (formData: FormData): Promise<{
|
|
51
|
-
const client = getApiClient()
|
|
52
|
-
const response = await client.post<ApiResponse<{
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
64
|
+
mutationFn: async (formData: FormData): Promise<{avatarUrl: string}> => {
|
|
65
|
+
const client = getApiClient()
|
|
66
|
+
const response = await client.post<ApiResponse<{avatarUrl: string}>>(
|
|
67
|
+
'/users/me/avatar',
|
|
68
|
+
formData,
|
|
69
|
+
{
|
|
70
|
+
headers: {'Content-Type': 'multipart/form-data'},
|
|
71
|
+
},
|
|
72
|
+
)
|
|
73
|
+
return response.data.data
|
|
56
74
|
},
|
|
57
75
|
onSuccess: () => {
|
|
58
|
-
queryClient.invalidateQueries({
|
|
76
|
+
queryClient.invalidateQueries({queryKey: userKeys.me()})
|
|
59
77
|
},
|
|
60
78
|
...options,
|
|
61
|
-
})
|
|
79
|
+
})
|
|
62
80
|
}
|
|
63
81
|
|
|
64
82
|
/**
|
|
65
83
|
* Delete current user's account
|
|
66
84
|
*
|
|
67
|
-
* @endpoint DELETE /
|
|
85
|
+
* @endpoint DELETE /users/me
|
|
68
86
|
*/
|
|
69
87
|
export function useDeleteAccount(
|
|
70
|
-
options?: Omit<UseMutationOptions<void, Error, void>, 'mutationFn'
|
|
88
|
+
options?: Omit<UseMutationOptions<void, Error, void>, 'mutationFn'>,
|
|
71
89
|
): UseMutationResult<void, Error, void> {
|
|
72
|
-
const queryClient = useQueryClient()
|
|
90
|
+
const queryClient = useQueryClient()
|
|
73
91
|
|
|
74
92
|
return useMutation({
|
|
75
93
|
mutationFn: async (): Promise<void> => {
|
|
76
|
-
const client = getApiClient()
|
|
77
|
-
await client.delete('/
|
|
94
|
+
const client = getApiClient()
|
|
95
|
+
await client.delete('/users/me')
|
|
78
96
|
},
|
|
79
97
|
onSuccess: () => {
|
|
80
|
-
queryClient.clear()
|
|
98
|
+
queryClient.clear()
|
|
81
99
|
},
|
|
82
100
|
...options,
|
|
83
|
-
})
|
|
101
|
+
})
|
|
84
102
|
}
|
|
85
103
|
|
|
86
104
|
/**
|
|
87
105
|
* Update user vibes
|
|
88
106
|
*
|
|
89
|
-
* @endpoint PUT /
|
|
107
|
+
* @endpoint PUT /users/me/vibes
|
|
90
108
|
*/
|
|
91
109
|
export function useUpdateVibes(
|
|
92
|
-
options?: Omit<
|
|
93
|
-
|
|
94
|
-
|
|
110
|
+
options?: Omit<
|
|
111
|
+
UseMutationOptions<User, Error, {vibes: string[]}>,
|
|
112
|
+
'mutationFn'
|
|
113
|
+
>,
|
|
114
|
+
): UseMutationResult<User, Error, {vibes: string[]}> {
|
|
115
|
+
const queryClient = useQueryClient()
|
|
95
116
|
|
|
96
117
|
return useMutation({
|
|
97
|
-
mutationFn: async (data: {
|
|
98
|
-
const client = getApiClient()
|
|
99
|
-
const response = await client.put<ApiResponse<User>>(
|
|
100
|
-
|
|
118
|
+
mutationFn: async (data: {vibes: string[]}): Promise<User> => {
|
|
119
|
+
const client = getApiClient()
|
|
120
|
+
const response = await client.put<ApiResponse<User>>(
|
|
121
|
+
'/users/me/vibes',
|
|
122
|
+
data,
|
|
123
|
+
)
|
|
124
|
+
return response.data.data
|
|
101
125
|
},
|
|
102
126
|
onSuccess: () => {
|
|
103
|
-
queryClient.invalidateQueries({
|
|
127
|
+
queryClient.invalidateQueries({queryKey: userKeys.me()})
|
|
104
128
|
},
|
|
105
129
|
...options,
|
|
106
|
-
})
|
|
130
|
+
})
|
|
107
131
|
}
|
|
108
132
|
|
|
109
133
|
/**
|
|
110
134
|
* Update user interests
|
|
111
135
|
*
|
|
112
|
-
* @endpoint PUT /
|
|
136
|
+
* @endpoint PUT /user/me/interests
|
|
113
137
|
*/
|
|
114
138
|
export function useUpdateInterests(
|
|
115
|
-
options?: Omit<
|
|
116
|
-
|
|
117
|
-
|
|
139
|
+
options?: Omit<
|
|
140
|
+
UseMutationOptions<User, Error, {interests: string[]}>,
|
|
141
|
+
'mutationFn'
|
|
142
|
+
>,
|
|
143
|
+
): UseMutationResult<User, Error, {interests: string[]}> {
|
|
144
|
+
const queryClient = useQueryClient()
|
|
118
145
|
|
|
119
146
|
return useMutation({
|
|
120
|
-
mutationFn: async (data: {
|
|
121
|
-
const client = getApiClient()
|
|
122
|
-
const response = await client.put<ApiResponse<User>>(
|
|
123
|
-
|
|
147
|
+
mutationFn: async (data: {interests: string[]}): Promise<User> => {
|
|
148
|
+
const client = getApiClient()
|
|
149
|
+
const response = await client.put<ApiResponse<User>>(
|
|
150
|
+
'/user/me/interests',
|
|
151
|
+
data,
|
|
152
|
+
)
|
|
153
|
+
return response.data.data
|
|
124
154
|
},
|
|
125
155
|
onSuccess: () => {
|
|
126
|
-
queryClient.invalidateQueries({
|
|
156
|
+
queryClient.invalidateQueries({queryKey: userKeys.me()})
|
|
127
157
|
},
|
|
128
158
|
...options,
|
|
129
|
-
})
|
|
159
|
+
})
|
|
130
160
|
}
|
|
131
161
|
|
|
132
162
|
/**
|
|
133
163
|
* Complete onboarding step
|
|
134
164
|
*
|
|
135
|
-
* @endpoint POST /
|
|
165
|
+
* @endpoint POST /user/me/onboarding-step
|
|
136
166
|
*/
|
|
137
167
|
export function useCompleteOnboardingStep(
|
|
138
|
-
options?: Omit<UseMutationOptions<User, Error, {
|
|
139
|
-
): UseMutationResult<User, Error, {
|
|
140
|
-
const queryClient = useQueryClient()
|
|
168
|
+
options?: Omit<UseMutationOptions<User, Error, {step: number}>, 'mutationFn'>,
|
|
169
|
+
): UseMutationResult<User, Error, {step: number}> {
|
|
170
|
+
const queryClient = useQueryClient()
|
|
141
171
|
|
|
142
172
|
return useMutation({
|
|
143
|
-
mutationFn: async (data: {
|
|
144
|
-
const client = getApiClient()
|
|
145
|
-
const response = await client.post<ApiResponse<User>>(
|
|
146
|
-
|
|
173
|
+
mutationFn: async (data: {step: number}): Promise<User> => {
|
|
174
|
+
const client = getApiClient()
|
|
175
|
+
const response = await client.post<ApiResponse<User>>(
|
|
176
|
+
'/user/me/onboarding-step',
|
|
177
|
+
data,
|
|
178
|
+
)
|
|
179
|
+
return response.data.data
|
|
147
180
|
},
|
|
148
181
|
onSuccess: () => {
|
|
149
|
-
queryClient.invalidateQueries({
|
|
182
|
+
queryClient.invalidateQueries({queryKey: userKeys.me()})
|
|
150
183
|
},
|
|
151
184
|
...options,
|
|
152
|
-
})
|
|
185
|
+
})
|
|
153
186
|
}
|
|
154
187
|
|
|
155
188
|
/**
|
|
156
189
|
* Block a user
|
|
157
190
|
*
|
|
158
|
-
* @endpoint POST /
|
|
191
|
+
* @endpoint POST /users/{id}/block
|
|
159
192
|
*/
|
|
160
193
|
export function useBlockUser(
|
|
161
|
-
options?: Omit<UseMutationOptions<void, Error, string>, 'mutationFn'
|
|
194
|
+
options?: Omit<UseMutationOptions<void, Error, string>, 'mutationFn'>,
|
|
162
195
|
): UseMutationResult<void, Error, string> {
|
|
163
|
-
const queryClient = useQueryClient()
|
|
196
|
+
const queryClient = useQueryClient()
|
|
164
197
|
|
|
165
198
|
return useMutation({
|
|
166
199
|
mutationFn: async (userId: string): Promise<void> => {
|
|
167
|
-
const client = getApiClient()
|
|
168
|
-
await client.post(`/
|
|
200
|
+
const client = getApiClient()
|
|
201
|
+
await client.post(`/users/${userId}/block`)
|
|
169
202
|
},
|
|
170
203
|
onSuccess: () => {
|
|
171
|
-
queryClient.invalidateQueries({
|
|
204
|
+
queryClient.invalidateQueries({queryKey: userKeys.blocked()})
|
|
172
205
|
},
|
|
173
206
|
...options,
|
|
174
|
-
})
|
|
207
|
+
})
|
|
175
208
|
}
|
|
176
209
|
|
|
177
210
|
/**
|
|
178
211
|
* Unblock a user
|
|
179
212
|
*
|
|
180
|
-
* @endpoint DELETE /
|
|
213
|
+
* @endpoint DELETE /users/{id}/block
|
|
181
214
|
*/
|
|
182
215
|
export function useUnblockUser(
|
|
183
|
-
options?: Omit<UseMutationOptions<void, Error, string>, 'mutationFn'
|
|
216
|
+
options?: Omit<UseMutationOptions<void, Error, string>, 'mutationFn'>,
|
|
184
217
|
): UseMutationResult<void, Error, string> {
|
|
185
|
-
const queryClient = useQueryClient()
|
|
218
|
+
const queryClient = useQueryClient()
|
|
186
219
|
|
|
187
220
|
return useMutation({
|
|
188
221
|
mutationFn: async (userId: string): Promise<void> => {
|
|
189
|
-
const client = getApiClient()
|
|
190
|
-
await client.delete(`/
|
|
222
|
+
const client = getApiClient()
|
|
223
|
+
await client.delete(`/users/${userId}/block`)
|
|
191
224
|
},
|
|
192
225
|
onSuccess: () => {
|
|
193
|
-
queryClient.invalidateQueries({
|
|
226
|
+
queryClient.invalidateQueries({queryKey: userKeys.blocked()})
|
|
194
227
|
},
|
|
195
228
|
...options,
|
|
196
|
-
})
|
|
229
|
+
})
|
|
197
230
|
}
|
package/src/api/queries/auth.ts
CHANGED
|
@@ -4,9 +4,19 @@
|
|
|
4
4
|
* TanStack Query hooks for authentication operations.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
import {
|
|
8
|
+
useMutation,
|
|
9
|
+
type UseMutationOptions,
|
|
10
|
+
type UseMutationResult,
|
|
11
|
+
} from '@tanstack/react-query'
|
|
12
|
+
|
|
13
|
+
import {getApiClient} from '../client'
|
|
14
|
+
import {
|
|
15
|
+
type ApiResponse,
|
|
16
|
+
type AuthResponse,
|
|
17
|
+
type SendOtpRequest,
|
|
18
|
+
type VerifyOtpRequest,
|
|
19
|
+
} from '../types'
|
|
10
20
|
|
|
11
21
|
// ============================================================================
|
|
12
22
|
// MUTATION HOOKS
|
|
@@ -15,53 +25,68 @@ import type { SendOtpRequest, VerifyOtpRequest, AuthResponse, ApiResponse } from
|
|
|
15
25
|
/**
|
|
16
26
|
* Send OTP to phone number
|
|
17
27
|
*
|
|
18
|
-
* @endpoint POST /
|
|
28
|
+
* @endpoint POST /auth/send-otp
|
|
19
29
|
*/
|
|
20
30
|
export function useSendOtp(
|
|
21
|
-
options?: Omit<
|
|
22
|
-
|
|
31
|
+
options?: Omit<
|
|
32
|
+
UseMutationOptions<ApiResponse<{sent: boolean}>, Error, SendOtpRequest>,
|
|
33
|
+
'mutationFn'
|
|
34
|
+
>,
|
|
35
|
+
): UseMutationResult<ApiResponse<{sent: boolean}>, Error, SendOtpRequest> {
|
|
23
36
|
return useMutation({
|
|
24
37
|
mutationFn: async (data: SendOtpRequest) => {
|
|
25
|
-
const client = getApiClient()
|
|
26
|
-
const response = await client.post<ApiResponse<{
|
|
27
|
-
|
|
38
|
+
const client = getApiClient()
|
|
39
|
+
const response = await client.post<ApiResponse<{sent: boolean}>>(
|
|
40
|
+
'/auth/send-otp',
|
|
41
|
+
data,
|
|
42
|
+
)
|
|
43
|
+
return response.data
|
|
28
44
|
},
|
|
29
45
|
...options,
|
|
30
|
-
})
|
|
46
|
+
})
|
|
31
47
|
}
|
|
32
48
|
|
|
33
49
|
/**
|
|
34
50
|
* Verify OTP and authenticate
|
|
35
51
|
*
|
|
36
|
-
* @endpoint POST /
|
|
52
|
+
* @endpoint POST /auth/verify-otp
|
|
37
53
|
*/
|
|
38
54
|
export function useVerifyOtp(
|
|
39
|
-
options?: Omit<
|
|
55
|
+
options?: Omit<
|
|
56
|
+
UseMutationOptions<AuthResponse, Error, VerifyOtpRequest>,
|
|
57
|
+
'mutationFn'
|
|
58
|
+
>,
|
|
40
59
|
): UseMutationResult<AuthResponse, Error, VerifyOtpRequest> {
|
|
41
60
|
return useMutation({
|
|
42
61
|
mutationFn: async (data: VerifyOtpRequest) => {
|
|
43
|
-
const client = getApiClient()
|
|
44
|
-
const response = await client.post<AuthResponse>('/
|
|
45
|
-
return response.data
|
|
62
|
+
const client = getApiClient()
|
|
63
|
+
const response = await client.post<AuthResponse>('/auth/verify-otp', data)
|
|
64
|
+
return response.data
|
|
46
65
|
},
|
|
47
66
|
...options,
|
|
48
|
-
})
|
|
67
|
+
})
|
|
49
68
|
}
|
|
50
69
|
|
|
51
70
|
/**
|
|
52
71
|
* Refresh access token
|
|
53
72
|
*
|
|
54
|
-
* @endpoint POST /
|
|
73
|
+
* @endpoint POST /auth/refresh
|
|
55
74
|
*/
|
|
56
75
|
export function useRefreshToken(
|
|
57
|
-
options?: Omit<
|
|
58
|
-
|
|
76
|
+
options?: Omit<
|
|
77
|
+
UseMutationOptions<{accessToken: string}, Error, {refreshToken: string}>,
|
|
78
|
+
'mutationFn'
|
|
79
|
+
>,
|
|
80
|
+
): UseMutationResult<{accessToken: string}, Error, {refreshToken: string}> {
|
|
59
81
|
return useMutation({
|
|
60
|
-
mutationFn: async (data: {
|
|
61
|
-
const client = getApiClient()
|
|
62
|
-
const response = await client.post<{
|
|
63
|
-
|
|
82
|
+
mutationFn: async (data: {refreshToken: string}) => {
|
|
83
|
+
const client = getApiClient()
|
|
84
|
+
const response = await client.post<{accessToken: string}>(
|
|
85
|
+
'/auth/refresh',
|
|
86
|
+
data,
|
|
87
|
+
)
|
|
88
|
+
return response.data
|
|
64
89
|
},
|
|
65
90
|
...options,
|
|
66
|
-
})
|
|
91
|
+
})
|
|
67
92
|
}
|
package/src/api/queries/clubs.ts
CHANGED
|
@@ -4,9 +4,14 @@
|
|
|
4
4
|
* TanStack Query hooks for club operations.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
import {
|
|
8
|
+
useQuery,
|
|
9
|
+
type UseQueryOptions,
|
|
10
|
+
type UseQueryResult,
|
|
11
|
+
} from '@tanstack/react-query'
|
|
12
|
+
|
|
13
|
+
import {getApiClient} from '../client'
|
|
14
|
+
import {type ApiResponse, type Club} from '../types'
|
|
10
15
|
|
|
11
16
|
// ============================================================================
|
|
12
17
|
// QUERY KEYS
|
|
@@ -19,8 +24,9 @@ export const clubKeys = {
|
|
|
19
24
|
detail: (id: string) => [...clubKeys.details(), id] as const,
|
|
20
25
|
bySlug: (slug: string) => [...clubKeys.all, 'slug', slug] as const,
|
|
21
26
|
byUser: (userId: string) => [...clubKeys.all, 'user', userId] as const,
|
|
22
|
-
membership: (clubId: string, userId: string) =>
|
|
23
|
-
|
|
27
|
+
membership: (clubId: string, userId: string) =>
|
|
28
|
+
[...clubKeys.detail(clubId), 'membership', userId] as const,
|
|
29
|
+
}
|
|
24
30
|
|
|
25
31
|
// ============================================================================
|
|
26
32
|
// QUERY HOOKS
|
|
@@ -29,107 +35,116 @@ export const clubKeys = {
|
|
|
29
35
|
/**
|
|
30
36
|
* Get clubs for a spot
|
|
31
37
|
*
|
|
32
|
-
* @endpoint GET /
|
|
38
|
+
* @endpoint GET /clubs/spot/{spotId}
|
|
33
39
|
*/
|
|
34
40
|
export function useClubsBySpot(
|
|
35
41
|
spotId: string,
|
|
36
|
-
options?: Omit<UseQueryOptions<Club[]>, 'queryKey' | 'queryFn'
|
|
42
|
+
options?: Omit<UseQueryOptions<Club[]>, 'queryKey' | 'queryFn'>,
|
|
37
43
|
): UseQueryResult<Club[]> {
|
|
38
44
|
return useQuery({
|
|
39
45
|
queryKey: clubKeys.bySpot(spotId),
|
|
40
46
|
queryFn: async (): Promise<Club[]> => {
|
|
41
|
-
const client = getApiClient()
|
|
42
|
-
const response = await client.get<ApiResponse<Club[]>>(
|
|
43
|
-
|
|
47
|
+
const client = getApiClient()
|
|
48
|
+
const response = await client.get<ApiResponse<Club[]>>(
|
|
49
|
+
`/clubs/spot/${spotId}`,
|
|
50
|
+
)
|
|
51
|
+
return response.data.data
|
|
44
52
|
},
|
|
45
53
|
enabled: !!spotId,
|
|
46
54
|
...options,
|
|
47
|
-
})
|
|
55
|
+
})
|
|
48
56
|
}
|
|
49
57
|
|
|
50
58
|
/**
|
|
51
59
|
* Get a club by ID
|
|
52
60
|
*
|
|
53
|
-
* @endpoint GET /
|
|
61
|
+
* @endpoint GET /clubs/{id}
|
|
54
62
|
*/
|
|
55
63
|
export function useClub(
|
|
56
64
|
clubId: string,
|
|
57
|
-
options?: Omit<UseQueryOptions<Club>, 'queryKey' | 'queryFn'
|
|
65
|
+
options?: Omit<UseQueryOptions<Club>, 'queryKey' | 'queryFn'>,
|
|
58
66
|
): UseQueryResult<Club> {
|
|
59
67
|
return useQuery({
|
|
60
68
|
queryKey: clubKeys.detail(clubId),
|
|
61
69
|
queryFn: async (): Promise<Club> => {
|
|
62
|
-
const client = getApiClient()
|
|
63
|
-
const response = await client.get<ApiResponse<Club>>(`/
|
|
64
|
-
return response.data.data
|
|
70
|
+
const client = getApiClient()
|
|
71
|
+
const response = await client.get<ApiResponse<Club>>(`/clubs/${clubId}`)
|
|
72
|
+
return response.data.data
|
|
65
73
|
},
|
|
66
74
|
enabled: !!clubId,
|
|
67
75
|
...options,
|
|
68
|
-
})
|
|
76
|
+
})
|
|
69
77
|
}
|
|
70
78
|
|
|
71
79
|
/**
|
|
72
80
|
* Get a club by slug
|
|
73
81
|
*
|
|
74
|
-
* @endpoint GET /
|
|
82
|
+
* @endpoint GET /clubs/slug/{slug}
|
|
75
83
|
*/
|
|
76
84
|
export function useClubBySlug(
|
|
77
85
|
slug: string,
|
|
78
|
-
options?: Omit<UseQueryOptions<Club>, 'queryKey' | 'queryFn'
|
|
86
|
+
options?: Omit<UseQueryOptions<Club>, 'queryKey' | 'queryFn'>,
|
|
79
87
|
): UseQueryResult<Club> {
|
|
80
88
|
return useQuery({
|
|
81
89
|
queryKey: clubKeys.bySlug(slug),
|
|
82
90
|
queryFn: async (): Promise<Club> => {
|
|
83
|
-
const client = getApiClient()
|
|
84
|
-
const response = await client.get<ApiResponse<Club>>(
|
|
85
|
-
|
|
91
|
+
const client = getApiClient()
|
|
92
|
+
const response = await client.get<ApiResponse<Club>>(
|
|
93
|
+
`/clubs/slug/${slug}`,
|
|
94
|
+
)
|
|
95
|
+
return response.data.data
|
|
86
96
|
},
|
|
87
97
|
enabled: !!slug,
|
|
88
98
|
...options,
|
|
89
|
-
})
|
|
99
|
+
})
|
|
90
100
|
}
|
|
91
101
|
|
|
92
102
|
/**
|
|
93
103
|
* Get clubs for a user
|
|
94
104
|
*
|
|
95
|
-
* @endpoint GET /
|
|
105
|
+
* @endpoint GET /clubs/user/{userId}
|
|
96
106
|
*/
|
|
97
107
|
export function useClubsByUser(
|
|
98
108
|
userId: string,
|
|
99
|
-
options?: Omit<UseQueryOptions<Club[]>, 'queryKey' | 'queryFn'
|
|
109
|
+
options?: Omit<UseQueryOptions<Club[]>, 'queryKey' | 'queryFn'>,
|
|
100
110
|
): UseQueryResult<Club[]> {
|
|
101
111
|
return useQuery({
|
|
102
112
|
queryKey: clubKeys.byUser(userId),
|
|
103
113
|
queryFn: async (): Promise<Club[]> => {
|
|
104
|
-
const client = getApiClient()
|
|
105
|
-
const response = await client.get<ApiResponse<Club[]>>(
|
|
106
|
-
|
|
114
|
+
const client = getApiClient()
|
|
115
|
+
const response = await client.get<ApiResponse<Club[]>>(
|
|
116
|
+
`/clubs/user/${userId}`,
|
|
117
|
+
)
|
|
118
|
+
return response.data.data
|
|
107
119
|
},
|
|
108
120
|
enabled: !!userId,
|
|
109
121
|
...options,
|
|
110
|
-
})
|
|
122
|
+
})
|
|
111
123
|
}
|
|
112
124
|
|
|
113
125
|
/**
|
|
114
126
|
* Get membership status for a user in a club
|
|
115
127
|
*
|
|
116
|
-
* @endpoint GET /
|
|
128
|
+
* @endpoint GET /clubs/{id}/membership/{userId}
|
|
117
129
|
*/
|
|
118
130
|
export function useClubMembership(
|
|
119
131
|
clubId: string,
|
|
120
132
|
userId: string,
|
|
121
|
-
options?: Omit<
|
|
122
|
-
|
|
133
|
+
options?: Omit<
|
|
134
|
+
UseQueryOptions<{isMember: boolean; role?: string}>,
|
|
135
|
+
'queryKey' | 'queryFn'
|
|
136
|
+
>,
|
|
137
|
+
): UseQueryResult<{isMember: boolean; role?: string}> {
|
|
123
138
|
return useQuery({
|
|
124
139
|
queryKey: clubKeys.membership(clubId, userId),
|
|
125
140
|
queryFn: async () => {
|
|
126
|
-
const client = getApiClient()
|
|
127
|
-
const response = await client.get<
|
|
128
|
-
|
|
129
|
-
)
|
|
130
|
-
return response.data.data
|
|
141
|
+
const client = getApiClient()
|
|
142
|
+
const response = await client.get<
|
|
143
|
+
ApiResponse<{isMember: boolean; role?: string}>
|
|
144
|
+
>(`/clubs/${clubId}/membership/${userId}`)
|
|
145
|
+
return response.data.data
|
|
131
146
|
},
|
|
132
147
|
enabled: !!clubId && !!userId,
|
|
133
148
|
...options,
|
|
134
|
-
})
|
|
149
|
+
})
|
|
135
150
|
}
|