@arascreative/erp-client 0.0.0-stage → 1.1.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/generated/api.d.ts +2282 -0
- package/dist/generated/api.d.ts.map +1 -0
- package/dist/generated/api.js +961 -0
- package/dist/generated/zod.d.ts +1087 -0
- package/dist/generated/zod.d.ts.map +1 -0
- package/dist/generated/zod.js +404 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.test.d.ts +2 -0
- package/dist/index.test.d.ts.map +1 -0
- package/dist/index.test.js +13 -0
- package/package.json +57 -3
- package/README.md +0 -3
|
@@ -0,0 +1,961 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generated by orval v7.21.0 🍺
|
|
3
|
+
* Do not edit manually.
|
|
4
|
+
* TSNX API
|
|
5
|
+
* OpenAPI spec version: 1.0.0
|
|
6
|
+
*/
|
|
7
|
+
import { useMutation, useQuery } from '@tanstack/react-query';
|
|
8
|
+
;
|
|
9
|
+
export const getGetAntiforgeryTokenUrl = () => {
|
|
10
|
+
return `/identity/antiforgery`;
|
|
11
|
+
};
|
|
12
|
+
export const getAntiforgeryToken = async (options) => {
|
|
13
|
+
const res = await fetch(getGetAntiforgeryTokenUrl(), {
|
|
14
|
+
...options,
|
|
15
|
+
method: 'GET'
|
|
16
|
+
});
|
|
17
|
+
const body = [204, 205, 304].includes(res.status) ? null : await res.text();
|
|
18
|
+
const data = body ? JSON.parse(body) : {};
|
|
19
|
+
return { data, status: res.status, headers: res.headers };
|
|
20
|
+
};
|
|
21
|
+
export const getGetAntiforgeryTokenQueryKey = () => {
|
|
22
|
+
return [
|
|
23
|
+
`/identity/antiforgery`
|
|
24
|
+
];
|
|
25
|
+
};
|
|
26
|
+
export const getGetAntiforgeryTokenQueryOptions = (options) => {
|
|
27
|
+
const { query: queryOptions, fetch: fetchOptions } = options ?? {};
|
|
28
|
+
const queryKey = queryOptions?.queryKey ?? getGetAntiforgeryTokenQueryKey();
|
|
29
|
+
const queryFn = ({ signal }) => getAntiforgeryToken({ signal, ...fetchOptions });
|
|
30
|
+
return { queryKey, queryFn, ...queryOptions };
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* @summary Get an antiforgery token
|
|
34
|
+
*/
|
|
35
|
+
export function useGetAntiforgeryToken(options, queryClient) {
|
|
36
|
+
const queryOptions = getGetAntiforgeryTokenQueryOptions(options);
|
|
37
|
+
const query = useQuery(queryOptions, queryClient);
|
|
38
|
+
query.queryKey = queryOptions.queryKey;
|
|
39
|
+
return query;
|
|
40
|
+
}
|
|
41
|
+
export const getLoginUrl = () => {
|
|
42
|
+
return `/identity/login`;
|
|
43
|
+
};
|
|
44
|
+
export const login = async (loginBody, options) => {
|
|
45
|
+
const res = await fetch(getLoginUrl(), {
|
|
46
|
+
...options,
|
|
47
|
+
method: 'POST',
|
|
48
|
+
headers: { 'Content-Type': 'application/json', ...options?.headers },
|
|
49
|
+
body: JSON.stringify(loginBody)
|
|
50
|
+
});
|
|
51
|
+
const body = [204, 205, 304].includes(res.status) ? null : await res.text();
|
|
52
|
+
const data = body ? JSON.parse(body) : {};
|
|
53
|
+
return { data, status: res.status, headers: res.headers };
|
|
54
|
+
};
|
|
55
|
+
export const getLoginMutationOptions = (options) => {
|
|
56
|
+
const mutationKey = ['login'];
|
|
57
|
+
const { mutation: mutationOptions, fetch: fetchOptions } = options ?
|
|
58
|
+
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
|
|
59
|
+
options
|
|
60
|
+
: { ...options, mutation: { ...options.mutation, mutationKey } }
|
|
61
|
+
: { mutation: { mutationKey, }, fetch: undefined };
|
|
62
|
+
const mutationFn = (props) => {
|
|
63
|
+
const { data } = props ?? {};
|
|
64
|
+
return login(data, fetchOptions);
|
|
65
|
+
};
|
|
66
|
+
return { mutationFn, ...mutationOptions };
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* @summary Sign in with email and password
|
|
70
|
+
*/
|
|
71
|
+
export const useLogin = (options, queryClient) => {
|
|
72
|
+
const mutationOptions = getLoginMutationOptions(options);
|
|
73
|
+
return useMutation(mutationOptions, queryClient);
|
|
74
|
+
};
|
|
75
|
+
export const getGetCurrentUserUrl = () => {
|
|
76
|
+
return `/identity/me`;
|
|
77
|
+
};
|
|
78
|
+
export const getCurrentUser = async (options) => {
|
|
79
|
+
const res = await fetch(getGetCurrentUserUrl(), {
|
|
80
|
+
...options,
|
|
81
|
+
method: 'GET'
|
|
82
|
+
});
|
|
83
|
+
const body = [204, 205, 304].includes(res.status) ? null : await res.text();
|
|
84
|
+
const data = body ? JSON.parse(body) : {};
|
|
85
|
+
return { data, status: res.status, headers: res.headers };
|
|
86
|
+
};
|
|
87
|
+
export const getGetCurrentUserQueryKey = () => {
|
|
88
|
+
return [
|
|
89
|
+
`/identity/me`
|
|
90
|
+
];
|
|
91
|
+
};
|
|
92
|
+
export const getGetCurrentUserQueryOptions = (options) => {
|
|
93
|
+
const { query: queryOptions, fetch: fetchOptions } = options ?? {};
|
|
94
|
+
const queryKey = queryOptions?.queryKey ?? getGetCurrentUserQueryKey();
|
|
95
|
+
const queryFn = ({ signal }) => getCurrentUser({ signal, ...fetchOptions });
|
|
96
|
+
return { queryKey, queryFn, ...queryOptions };
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* @summary Get the current signed-in user
|
|
100
|
+
*/
|
|
101
|
+
export function useGetCurrentUser(options, queryClient) {
|
|
102
|
+
const queryOptions = getGetCurrentUserQueryOptions(options);
|
|
103
|
+
const query = useQuery(queryOptions, queryClient);
|
|
104
|
+
query.queryKey = queryOptions.queryKey;
|
|
105
|
+
return query;
|
|
106
|
+
}
|
|
107
|
+
export const getLogoutUrl = () => {
|
|
108
|
+
return `/identity/logout`;
|
|
109
|
+
};
|
|
110
|
+
export const logout = async (options) => {
|
|
111
|
+
const res = await fetch(getLogoutUrl(), {
|
|
112
|
+
...options,
|
|
113
|
+
method: 'POST'
|
|
114
|
+
});
|
|
115
|
+
const body = [204, 205, 304].includes(res.status) ? null : await res.text();
|
|
116
|
+
const data = body ? JSON.parse(body) : {};
|
|
117
|
+
return { data, status: res.status, headers: res.headers };
|
|
118
|
+
};
|
|
119
|
+
export const getLogoutMutationOptions = (options) => {
|
|
120
|
+
const mutationKey = ['logout'];
|
|
121
|
+
const { mutation: mutationOptions, fetch: fetchOptions } = options ?
|
|
122
|
+
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
|
|
123
|
+
options
|
|
124
|
+
: { ...options, mutation: { ...options.mutation, mutationKey } }
|
|
125
|
+
: { mutation: { mutationKey, }, fetch: undefined };
|
|
126
|
+
const mutationFn = () => {
|
|
127
|
+
return logout(fetchOptions);
|
|
128
|
+
};
|
|
129
|
+
return { mutationFn, ...mutationOptions };
|
|
130
|
+
};
|
|
131
|
+
/**
|
|
132
|
+
* @summary Revoke the current session and clear its cookie
|
|
133
|
+
*/
|
|
134
|
+
export const useLogout = (options, queryClient) => {
|
|
135
|
+
const mutationOptions = getLogoutMutationOptions(options);
|
|
136
|
+
return useMutation(mutationOptions, queryClient);
|
|
137
|
+
};
|
|
138
|
+
export const getCreateOwnerUrl = () => {
|
|
139
|
+
return `/identity/owner`;
|
|
140
|
+
};
|
|
141
|
+
export const createOwner = async (createOwnerBody, options) => {
|
|
142
|
+
const res = await fetch(getCreateOwnerUrl(), {
|
|
143
|
+
...options,
|
|
144
|
+
method: 'POST',
|
|
145
|
+
headers: { 'Content-Type': 'application/json', ...options?.headers },
|
|
146
|
+
body: JSON.stringify(createOwnerBody)
|
|
147
|
+
});
|
|
148
|
+
const body = [204, 205, 304].includes(res.status) ? null : await res.text();
|
|
149
|
+
const data = body ? JSON.parse(body) : {};
|
|
150
|
+
return { data, status: res.status, headers: res.headers };
|
|
151
|
+
};
|
|
152
|
+
export const getCreateOwnerMutationOptions = (options) => {
|
|
153
|
+
const mutationKey = ['createOwner'];
|
|
154
|
+
const { mutation: mutationOptions, fetch: fetchOptions } = options ?
|
|
155
|
+
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
|
|
156
|
+
options
|
|
157
|
+
: { ...options, mutation: { ...options.mutation, mutationKey } }
|
|
158
|
+
: { mutation: { mutationKey, }, fetch: undefined };
|
|
159
|
+
const mutationFn = (props) => {
|
|
160
|
+
const { data } = props ?? {};
|
|
161
|
+
return createOwner(data, fetchOptions);
|
|
162
|
+
};
|
|
163
|
+
return { mutationFn, ...mutationOptions };
|
|
164
|
+
};
|
|
165
|
+
/**
|
|
166
|
+
* @summary Create the owner account
|
|
167
|
+
*/
|
|
168
|
+
export const useCreateOwner = (options, queryClient) => {
|
|
169
|
+
const mutationOptions = getCreateOwnerMutationOptions(options);
|
|
170
|
+
return useMutation(mutationOptions, queryClient);
|
|
171
|
+
};
|
|
172
|
+
export const getSearchAddressesUrl = (params) => {
|
|
173
|
+
const normalizedParams = new URLSearchParams();
|
|
174
|
+
Object.entries(params || {}).forEach(([key, value]) => {
|
|
175
|
+
if (value !== undefined) {
|
|
176
|
+
normalizedParams.append(key, value === null ? 'null' : value.toString());
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
const stringifiedParams = normalizedParams.toString();
|
|
180
|
+
return stringifiedParams.length > 0 ? `/addresses/search?${stringifiedParams}` : `/addresses/search`;
|
|
181
|
+
};
|
|
182
|
+
export const searchAddresses = async (params, options) => {
|
|
183
|
+
const res = await fetch(getSearchAddressesUrl(params), {
|
|
184
|
+
...options,
|
|
185
|
+
method: 'GET'
|
|
186
|
+
});
|
|
187
|
+
const body = [204, 205, 304].includes(res.status) ? null : await res.text();
|
|
188
|
+
const data = body ? JSON.parse(body) : {};
|
|
189
|
+
return { data, status: res.status, headers: res.headers };
|
|
190
|
+
};
|
|
191
|
+
export const getSearchAddressesQueryKey = (params) => {
|
|
192
|
+
return [
|
|
193
|
+
`/addresses/search`, ...(params ? [params] : [])
|
|
194
|
+
];
|
|
195
|
+
};
|
|
196
|
+
export const getSearchAddressesQueryOptions = (params, options) => {
|
|
197
|
+
const { query: queryOptions, fetch: fetchOptions } = options ?? {};
|
|
198
|
+
const queryKey = queryOptions?.queryKey ?? getSearchAddressesQueryKey(params);
|
|
199
|
+
const queryFn = ({ signal }) => searchAddresses(params, { signal, ...fetchOptions });
|
|
200
|
+
return { queryKey, queryFn, ...queryOptions };
|
|
201
|
+
};
|
|
202
|
+
/**
|
|
203
|
+
* @summary Search addresses by keyword
|
|
204
|
+
*/
|
|
205
|
+
export function useSearchAddresses(params, options, queryClient) {
|
|
206
|
+
const queryOptions = getSearchAddressesQueryOptions(params, options);
|
|
207
|
+
const query = useQuery(queryOptions, queryClient);
|
|
208
|
+
query.queryKey = queryOptions.queryKey;
|
|
209
|
+
return query;
|
|
210
|
+
}
|
|
211
|
+
export const getInitiateUploadUrl = () => {
|
|
212
|
+
return `/files/initiate-upload`;
|
|
213
|
+
};
|
|
214
|
+
export const initiateUpload = async (initiateUploadBody, options) => {
|
|
215
|
+
const res = await fetch(getInitiateUploadUrl(), {
|
|
216
|
+
...options,
|
|
217
|
+
method: 'POST',
|
|
218
|
+
headers: { 'Content-Type': 'application/json', ...options?.headers },
|
|
219
|
+
body: JSON.stringify(initiateUploadBody)
|
|
220
|
+
});
|
|
221
|
+
const body = [204, 205, 304].includes(res.status) ? null : await res.text();
|
|
222
|
+
const data = body ? JSON.parse(body) : {};
|
|
223
|
+
return { data, status: res.status, headers: res.headers };
|
|
224
|
+
};
|
|
225
|
+
export const getInitiateUploadMutationOptions = (options) => {
|
|
226
|
+
const mutationKey = ['initiateUpload'];
|
|
227
|
+
const { mutation: mutationOptions, fetch: fetchOptions } = options ?
|
|
228
|
+
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
|
|
229
|
+
options
|
|
230
|
+
: { ...options, mutation: { ...options.mutation, mutationKey } }
|
|
231
|
+
: { mutation: { mutationKey, }, fetch: undefined };
|
|
232
|
+
const mutationFn = (props) => {
|
|
233
|
+
const { data } = props ?? {};
|
|
234
|
+
return initiateUpload(data, fetchOptions);
|
|
235
|
+
};
|
|
236
|
+
return { mutationFn, ...mutationOptions };
|
|
237
|
+
};
|
|
238
|
+
/**
|
|
239
|
+
* @summary Initiate direct file upload to storage
|
|
240
|
+
*/
|
|
241
|
+
export const useInitiateUpload = (options, queryClient) => {
|
|
242
|
+
const mutationOptions = getInitiateUploadMutationOptions(options);
|
|
243
|
+
return useMutation(mutationOptions, queryClient);
|
|
244
|
+
};
|
|
245
|
+
export const getUploadFileUrl = () => {
|
|
246
|
+
return `/files/upload`;
|
|
247
|
+
};
|
|
248
|
+
export const uploadFile = async (uploadFileBody, options) => {
|
|
249
|
+
const res = await fetch(getUploadFileUrl(), {
|
|
250
|
+
...options,
|
|
251
|
+
method: 'POST',
|
|
252
|
+
headers: { 'Content-Type': 'application/json', ...options?.headers },
|
|
253
|
+
body: JSON.stringify(uploadFileBody)
|
|
254
|
+
});
|
|
255
|
+
const body = [204, 205, 304].includes(res.status) ? null : await res.text();
|
|
256
|
+
const data = body ? JSON.parse(body) : {};
|
|
257
|
+
return { data, status: res.status, headers: res.headers };
|
|
258
|
+
};
|
|
259
|
+
export const getUploadFileMutationOptions = (options) => {
|
|
260
|
+
const mutationKey = ['uploadFile'];
|
|
261
|
+
const { mutation: mutationOptions, fetch: fetchOptions } = options ?
|
|
262
|
+
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
|
|
263
|
+
options
|
|
264
|
+
: { ...options, mutation: { ...options.mutation, mutationKey } }
|
|
265
|
+
: { mutation: { mutationKey, }, fetch: undefined };
|
|
266
|
+
const mutationFn = (props) => {
|
|
267
|
+
const { data } = props ?? {};
|
|
268
|
+
return uploadFile(data, fetchOptions);
|
|
269
|
+
};
|
|
270
|
+
return { mutationFn, ...mutationOptions };
|
|
271
|
+
};
|
|
272
|
+
/**
|
|
273
|
+
* @summary Direct upload file
|
|
274
|
+
*/
|
|
275
|
+
export const useUploadFile = (options, queryClient) => {
|
|
276
|
+
const mutationOptions = getUploadFileMutationOptions(options);
|
|
277
|
+
return useMutation(mutationOptions, queryClient);
|
|
278
|
+
};
|
|
279
|
+
export const getToggleWarehouseStatusUrl = (id) => {
|
|
280
|
+
return `/warehouses/${id}/toggle-status`;
|
|
281
|
+
};
|
|
282
|
+
export const toggleWarehouseStatus = async (id, options) => {
|
|
283
|
+
const res = await fetch(getToggleWarehouseStatusUrl(id), {
|
|
284
|
+
...options,
|
|
285
|
+
method: 'PATCH'
|
|
286
|
+
});
|
|
287
|
+
const body = [204, 205, 304].includes(res.status) ? null : await res.text();
|
|
288
|
+
const data = body ? JSON.parse(body) : {};
|
|
289
|
+
return { data, status: res.status, headers: res.headers };
|
|
290
|
+
};
|
|
291
|
+
export const getToggleWarehouseStatusMutationOptions = (options) => {
|
|
292
|
+
const mutationKey = ['toggleWarehouseStatus'];
|
|
293
|
+
const { mutation: mutationOptions, fetch: fetchOptions } = options ?
|
|
294
|
+
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
|
|
295
|
+
options
|
|
296
|
+
: { ...options, mutation: { ...options.mutation, mutationKey } }
|
|
297
|
+
: { mutation: { mutationKey, }, fetch: undefined };
|
|
298
|
+
const mutationFn = (props) => {
|
|
299
|
+
const { id } = props ?? {};
|
|
300
|
+
return toggleWarehouseStatus(id, fetchOptions);
|
|
301
|
+
};
|
|
302
|
+
return { mutationFn, ...mutationOptions };
|
|
303
|
+
};
|
|
304
|
+
/**
|
|
305
|
+
* @summary Toggle warehouse active status
|
|
306
|
+
*/
|
|
307
|
+
export const useToggleWarehouseStatus = (options, queryClient) => {
|
|
308
|
+
const mutationOptions = getToggleWarehouseStatusMutationOptions(options);
|
|
309
|
+
return useMutation(mutationOptions, queryClient);
|
|
310
|
+
};
|
|
311
|
+
export const getChangeStockItemStatusUrl = (id) => {
|
|
312
|
+
return `/stock-items/${id}/status`;
|
|
313
|
+
};
|
|
314
|
+
export const changeStockItemStatus = async (id, changeStockItemStatusBody, options) => {
|
|
315
|
+
const res = await fetch(getChangeStockItemStatusUrl(id), {
|
|
316
|
+
...options,
|
|
317
|
+
method: 'PATCH',
|
|
318
|
+
headers: { 'Content-Type': 'application/json', ...options?.headers },
|
|
319
|
+
body: JSON.stringify(changeStockItemStatusBody)
|
|
320
|
+
});
|
|
321
|
+
const body = [204, 205, 304].includes(res.status) ? null : await res.text();
|
|
322
|
+
const data = body ? JSON.parse(body) : {};
|
|
323
|
+
return { data, status: res.status, headers: res.headers };
|
|
324
|
+
};
|
|
325
|
+
export const getChangeStockItemStatusMutationOptions = (options) => {
|
|
326
|
+
const mutationKey = ['changeStockItemStatus'];
|
|
327
|
+
const { mutation: mutationOptions, fetch: fetchOptions } = options ?
|
|
328
|
+
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
|
|
329
|
+
options
|
|
330
|
+
: { ...options, mutation: { ...options.mutation, mutationKey } }
|
|
331
|
+
: { mutation: { mutationKey, }, fetch: undefined };
|
|
332
|
+
const mutationFn = (props) => {
|
|
333
|
+
const { id, data } = props ?? {};
|
|
334
|
+
return changeStockItemStatus(id, data, fetchOptions);
|
|
335
|
+
};
|
|
336
|
+
return { mutationFn, ...mutationOptions };
|
|
337
|
+
};
|
|
338
|
+
/**
|
|
339
|
+
* @summary Change stock item active status
|
|
340
|
+
*/
|
|
341
|
+
export const useChangeStockItemStatus = (options, queryClient) => {
|
|
342
|
+
const mutationOptions = getChangeStockItemStatusMutationOptions(options);
|
|
343
|
+
return useMutation(mutationOptions, queryClient);
|
|
344
|
+
};
|
|
345
|
+
export const getCompleteUploadUrl = (id) => {
|
|
346
|
+
return `/files/${id}/complete`;
|
|
347
|
+
};
|
|
348
|
+
export const completeUpload = async (id, completeUploadBody, options) => {
|
|
349
|
+
const res = await fetch(getCompleteUploadUrl(id), {
|
|
350
|
+
...options,
|
|
351
|
+
method: 'POST',
|
|
352
|
+
headers: { 'Content-Type': 'application/json', ...options?.headers },
|
|
353
|
+
body: JSON.stringify(completeUploadBody)
|
|
354
|
+
});
|
|
355
|
+
const body = [204, 205, 304].includes(res.status) ? null : await res.text();
|
|
356
|
+
const data = body ? JSON.parse(body) : {};
|
|
357
|
+
return { data, status: res.status, headers: res.headers };
|
|
358
|
+
};
|
|
359
|
+
export const getCompleteUploadMutationOptions = (options) => {
|
|
360
|
+
const mutationKey = ['completeUpload'];
|
|
361
|
+
const { mutation: mutationOptions, fetch: fetchOptions } = options ?
|
|
362
|
+
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
|
|
363
|
+
options
|
|
364
|
+
: { ...options, mutation: { ...options.mutation, mutationKey } }
|
|
365
|
+
: { mutation: { mutationKey, }, fetch: undefined };
|
|
366
|
+
const mutationFn = (props) => {
|
|
367
|
+
const { id, data } = props ?? {};
|
|
368
|
+
return completeUpload(id, data, fetchOptions);
|
|
369
|
+
};
|
|
370
|
+
return { mutationFn, ...mutationOptions };
|
|
371
|
+
};
|
|
372
|
+
/**
|
|
373
|
+
* @summary Complete direct file upload
|
|
374
|
+
*/
|
|
375
|
+
export const useCompleteUpload = (options, queryClient) => {
|
|
376
|
+
const mutationOptions = getCompleteUploadMutationOptions(options);
|
|
377
|
+
return useMutation(mutationOptions, queryClient);
|
|
378
|
+
};
|
|
379
|
+
export const getGetFileAccessUrlUrl = (id, params) => {
|
|
380
|
+
const normalizedParams = new URLSearchParams();
|
|
381
|
+
Object.entries(params || {}).forEach(([key, value]) => {
|
|
382
|
+
if (value !== undefined) {
|
|
383
|
+
normalizedParams.append(key, value === null ? 'null' : value.toString());
|
|
384
|
+
}
|
|
385
|
+
});
|
|
386
|
+
const stringifiedParams = normalizedParams.toString();
|
|
387
|
+
return stringifiedParams.length > 0 ? `/files/${id}/access-url?${stringifiedParams}` : `/files/${id}/access-url`;
|
|
388
|
+
};
|
|
389
|
+
export const getFileAccessUrl = async (id, params, options) => {
|
|
390
|
+
const res = await fetch(getGetFileAccessUrlUrl(id, params), {
|
|
391
|
+
...options,
|
|
392
|
+
method: 'GET'
|
|
393
|
+
});
|
|
394
|
+
const body = [204, 205, 304].includes(res.status) ? null : await res.text();
|
|
395
|
+
const data = body ? JSON.parse(body) : {};
|
|
396
|
+
return { data, status: res.status, headers: res.headers };
|
|
397
|
+
};
|
|
398
|
+
export const getGetFileAccessUrlQueryKey = (id, params) => {
|
|
399
|
+
return [
|
|
400
|
+
`/files/${id}/access-url`, ...(params ? [params] : [])
|
|
401
|
+
];
|
|
402
|
+
};
|
|
403
|
+
export const getGetFileAccessUrlQueryOptions = (id, params, options) => {
|
|
404
|
+
const { query: queryOptions, fetch: fetchOptions } = options ?? {};
|
|
405
|
+
const queryKey = queryOptions?.queryKey ?? getGetFileAccessUrlQueryKey(id, params);
|
|
406
|
+
const queryFn = ({ signal }) => getFileAccessUrl(id, params, { signal, ...fetchOptions });
|
|
407
|
+
return { queryKey, queryFn, enabled: !!(id), ...queryOptions };
|
|
408
|
+
};
|
|
409
|
+
/**
|
|
410
|
+
* @summary Get file download or CDN access URL
|
|
411
|
+
*/
|
|
412
|
+
export function useGetFileAccessUrl(id, params, options, queryClient) {
|
|
413
|
+
const queryOptions = getGetFileAccessUrlQueryOptions(id, params, options);
|
|
414
|
+
const query = useQuery(queryOptions, queryClient);
|
|
415
|
+
query.queryKey = queryOptions.queryKey;
|
|
416
|
+
return query;
|
|
417
|
+
}
|
|
418
|
+
export const getGetWarehouseByIdUrl = (id) => {
|
|
419
|
+
return `/warehouses/${id}`;
|
|
420
|
+
};
|
|
421
|
+
export const getWarehouseById = async (id, options) => {
|
|
422
|
+
const res = await fetch(getGetWarehouseByIdUrl(id), {
|
|
423
|
+
...options,
|
|
424
|
+
method: 'GET'
|
|
425
|
+
});
|
|
426
|
+
const body = [204, 205, 304].includes(res.status) ? null : await res.text();
|
|
427
|
+
const data = body ? JSON.parse(body) : {};
|
|
428
|
+
return { data, status: res.status, headers: res.headers };
|
|
429
|
+
};
|
|
430
|
+
export const getGetWarehouseByIdQueryKey = (id) => {
|
|
431
|
+
return [
|
|
432
|
+
`/warehouses/${id}`
|
|
433
|
+
];
|
|
434
|
+
};
|
|
435
|
+
export const getGetWarehouseByIdQueryOptions = (id, options) => {
|
|
436
|
+
const { query: queryOptions, fetch: fetchOptions } = options ?? {};
|
|
437
|
+
const queryKey = queryOptions?.queryKey ?? getGetWarehouseByIdQueryKey(id);
|
|
438
|
+
const queryFn = ({ signal }) => getWarehouseById(id, { signal, ...fetchOptions });
|
|
439
|
+
return { queryKey, queryFn, enabled: !!(id), ...queryOptions };
|
|
440
|
+
};
|
|
441
|
+
/**
|
|
442
|
+
* @summary Get warehouse by ID
|
|
443
|
+
*/
|
|
444
|
+
export function useGetWarehouseById(id, options, queryClient) {
|
|
445
|
+
const queryOptions = getGetWarehouseByIdQueryOptions(id, options);
|
|
446
|
+
const query = useQuery(queryOptions, queryClient);
|
|
447
|
+
query.queryKey = queryOptions.queryKey;
|
|
448
|
+
return query;
|
|
449
|
+
}
|
|
450
|
+
export const getUpdateWarehouseUrl = (id) => {
|
|
451
|
+
return `/warehouses/${id}`;
|
|
452
|
+
};
|
|
453
|
+
export const updateWarehouse = async (id, updateWarehouseBody, options) => {
|
|
454
|
+
const res = await fetch(getUpdateWarehouseUrl(id), {
|
|
455
|
+
...options,
|
|
456
|
+
method: 'PUT',
|
|
457
|
+
headers: { 'Content-Type': 'application/json', ...options?.headers },
|
|
458
|
+
body: JSON.stringify(updateWarehouseBody)
|
|
459
|
+
});
|
|
460
|
+
const body = [204, 205, 304].includes(res.status) ? null : await res.text();
|
|
461
|
+
const data = body ? JSON.parse(body) : {};
|
|
462
|
+
return { data, status: res.status, headers: res.headers };
|
|
463
|
+
};
|
|
464
|
+
export const getUpdateWarehouseMutationOptions = (options) => {
|
|
465
|
+
const mutationKey = ['updateWarehouse'];
|
|
466
|
+
const { mutation: mutationOptions, fetch: fetchOptions } = options ?
|
|
467
|
+
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
|
|
468
|
+
options
|
|
469
|
+
: { ...options, mutation: { ...options.mutation, mutationKey } }
|
|
470
|
+
: { mutation: { mutationKey, }, fetch: undefined };
|
|
471
|
+
const mutationFn = (props) => {
|
|
472
|
+
const { id, data } = props ?? {};
|
|
473
|
+
return updateWarehouse(id, data, fetchOptions);
|
|
474
|
+
};
|
|
475
|
+
return { mutationFn, ...mutationOptions };
|
|
476
|
+
};
|
|
477
|
+
/**
|
|
478
|
+
* @summary Update warehouse
|
|
479
|
+
*/
|
|
480
|
+
export const useUpdateWarehouse = (options, queryClient) => {
|
|
481
|
+
const mutationOptions = getUpdateWarehouseMutationOptions(options);
|
|
482
|
+
return useMutation(mutationOptions, queryClient);
|
|
483
|
+
};
|
|
484
|
+
export const getDeleteWarehouseUrl = (id) => {
|
|
485
|
+
return `/warehouses/${id}`;
|
|
486
|
+
};
|
|
487
|
+
export const deleteWarehouse = async (id, options) => {
|
|
488
|
+
const res = await fetch(getDeleteWarehouseUrl(id), {
|
|
489
|
+
...options,
|
|
490
|
+
method: 'DELETE'
|
|
491
|
+
});
|
|
492
|
+
const body = [204, 205, 304].includes(res.status) ? null : await res.text();
|
|
493
|
+
const data = body ? JSON.parse(body) : {};
|
|
494
|
+
return { data, status: res.status, headers: res.headers };
|
|
495
|
+
};
|
|
496
|
+
export const getDeleteWarehouseMutationOptions = (options) => {
|
|
497
|
+
const mutationKey = ['deleteWarehouse'];
|
|
498
|
+
const { mutation: mutationOptions, fetch: fetchOptions } = options ?
|
|
499
|
+
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
|
|
500
|
+
options
|
|
501
|
+
: { ...options, mutation: { ...options.mutation, mutationKey } }
|
|
502
|
+
: { mutation: { mutationKey, }, fetch: undefined };
|
|
503
|
+
const mutationFn = (props) => {
|
|
504
|
+
const { id } = props ?? {};
|
|
505
|
+
return deleteWarehouse(id, fetchOptions);
|
|
506
|
+
};
|
|
507
|
+
return { mutationFn, ...mutationOptions };
|
|
508
|
+
};
|
|
509
|
+
/**
|
|
510
|
+
* @summary Delete warehouse
|
|
511
|
+
*/
|
|
512
|
+
export const useDeleteWarehouse = (options, queryClient) => {
|
|
513
|
+
const mutationOptions = getDeleteWarehouseMutationOptions(options);
|
|
514
|
+
return useMutation(mutationOptions, queryClient);
|
|
515
|
+
};
|
|
516
|
+
export const getUpdateStockItemUrl = (id) => {
|
|
517
|
+
return `/stock-items/${id}`;
|
|
518
|
+
};
|
|
519
|
+
export const updateStockItem = async (id, updateStockItemBody, options) => {
|
|
520
|
+
const res = await fetch(getUpdateStockItemUrl(id), {
|
|
521
|
+
...options,
|
|
522
|
+
method: 'PUT',
|
|
523
|
+
headers: { 'Content-Type': 'application/json', ...options?.headers },
|
|
524
|
+
body: JSON.stringify(updateStockItemBody)
|
|
525
|
+
});
|
|
526
|
+
const body = [204, 205, 304].includes(res.status) ? null : await res.text();
|
|
527
|
+
const data = body ? JSON.parse(body) : {};
|
|
528
|
+
return { data, status: res.status, headers: res.headers };
|
|
529
|
+
};
|
|
530
|
+
export const getUpdateStockItemMutationOptions = (options) => {
|
|
531
|
+
const mutationKey = ['updateStockItem'];
|
|
532
|
+
const { mutation: mutationOptions, fetch: fetchOptions } = options ?
|
|
533
|
+
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
|
|
534
|
+
options
|
|
535
|
+
: { ...options, mutation: { ...options.mutation, mutationKey } }
|
|
536
|
+
: { mutation: { mutationKey, }, fetch: undefined };
|
|
537
|
+
const mutationFn = (props) => {
|
|
538
|
+
const { id, data } = props ?? {};
|
|
539
|
+
return updateStockItem(id, data, fetchOptions);
|
|
540
|
+
};
|
|
541
|
+
return { mutationFn, ...mutationOptions };
|
|
542
|
+
};
|
|
543
|
+
/**
|
|
544
|
+
* @summary Update stock item
|
|
545
|
+
*/
|
|
546
|
+
export const useUpdateStockItem = (options, queryClient) => {
|
|
547
|
+
const mutationOptions = getUpdateStockItemMutationOptions(options);
|
|
548
|
+
return useMutation(mutationOptions, queryClient);
|
|
549
|
+
};
|
|
550
|
+
export const getDeleteStockItemUrl = (id) => {
|
|
551
|
+
return `/stock-items/${id}`;
|
|
552
|
+
};
|
|
553
|
+
export const deleteStockItem = async (id, options) => {
|
|
554
|
+
const res = await fetch(getDeleteStockItemUrl(id), {
|
|
555
|
+
...options,
|
|
556
|
+
method: 'DELETE'
|
|
557
|
+
});
|
|
558
|
+
const body = [204, 205, 304].includes(res.status) ? null : await res.text();
|
|
559
|
+
const data = body ? JSON.parse(body) : {};
|
|
560
|
+
return { data, status: res.status, headers: res.headers };
|
|
561
|
+
};
|
|
562
|
+
export const getDeleteStockItemMutationOptions = (options) => {
|
|
563
|
+
const mutationKey = ['deleteStockItem'];
|
|
564
|
+
const { mutation: mutationOptions, fetch: fetchOptions } = options ?
|
|
565
|
+
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
|
|
566
|
+
options
|
|
567
|
+
: { ...options, mutation: { ...options.mutation, mutationKey } }
|
|
568
|
+
: { mutation: { mutationKey, }, fetch: undefined };
|
|
569
|
+
const mutationFn = (props) => {
|
|
570
|
+
const { id } = props ?? {};
|
|
571
|
+
return deleteStockItem(id, fetchOptions);
|
|
572
|
+
};
|
|
573
|
+
return { mutationFn, ...mutationOptions };
|
|
574
|
+
};
|
|
575
|
+
/**
|
|
576
|
+
* @summary Delete stock item
|
|
577
|
+
*/
|
|
578
|
+
export const useDeleteStockItem = (options, queryClient) => {
|
|
579
|
+
const mutationOptions = getDeleteStockItemMutationOptions(options);
|
|
580
|
+
return useMutation(mutationOptions, queryClient);
|
|
581
|
+
};
|
|
582
|
+
export const getGetStoredFileByIdUrl = (id) => {
|
|
583
|
+
return `/files/${id}`;
|
|
584
|
+
};
|
|
585
|
+
export const getStoredFileById = async (id, options) => {
|
|
586
|
+
const res = await fetch(getGetStoredFileByIdUrl(id), {
|
|
587
|
+
...options,
|
|
588
|
+
method: 'GET'
|
|
589
|
+
});
|
|
590
|
+
const body = [204, 205, 304].includes(res.status) ? null : await res.text();
|
|
591
|
+
const data = body ? JSON.parse(body) : {};
|
|
592
|
+
return { data, status: res.status, headers: res.headers };
|
|
593
|
+
};
|
|
594
|
+
export const getGetStoredFileByIdQueryKey = (id) => {
|
|
595
|
+
return [
|
|
596
|
+
`/files/${id}`
|
|
597
|
+
];
|
|
598
|
+
};
|
|
599
|
+
export const getGetStoredFileByIdQueryOptions = (id, options) => {
|
|
600
|
+
const { query: queryOptions, fetch: fetchOptions } = options ?? {};
|
|
601
|
+
const queryKey = queryOptions?.queryKey ?? getGetStoredFileByIdQueryKey(id);
|
|
602
|
+
const queryFn = ({ signal }) => getStoredFileById(id, { signal, ...fetchOptions });
|
|
603
|
+
return { queryKey, queryFn, enabled: !!(id), ...queryOptions };
|
|
604
|
+
};
|
|
605
|
+
/**
|
|
606
|
+
* @summary Get stored file by ID
|
|
607
|
+
*/
|
|
608
|
+
export function useGetStoredFileById(id, options, queryClient) {
|
|
609
|
+
const queryOptions = getGetStoredFileByIdQueryOptions(id, options);
|
|
610
|
+
const query = useQuery(queryOptions, queryClient);
|
|
611
|
+
query.queryKey = queryOptions.queryKey;
|
|
612
|
+
return query;
|
|
613
|
+
}
|
|
614
|
+
export const getDeleteStoredFileUrl = (id) => {
|
|
615
|
+
return `/files/${id}`;
|
|
616
|
+
};
|
|
617
|
+
export const deleteStoredFile = async (id, options) => {
|
|
618
|
+
const res = await fetch(getDeleteStoredFileUrl(id), {
|
|
619
|
+
...options,
|
|
620
|
+
method: 'DELETE'
|
|
621
|
+
});
|
|
622
|
+
const body = [204, 205, 304].includes(res.status) ? null : await res.text();
|
|
623
|
+
const data = body ? JSON.parse(body) : {};
|
|
624
|
+
return { data, status: res.status, headers: res.headers };
|
|
625
|
+
};
|
|
626
|
+
export const getDeleteStoredFileMutationOptions = (options) => {
|
|
627
|
+
const mutationKey = ['deleteStoredFile'];
|
|
628
|
+
const { mutation: mutationOptions, fetch: fetchOptions } = options ?
|
|
629
|
+
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
|
|
630
|
+
options
|
|
631
|
+
: { ...options, mutation: { ...options.mutation, mutationKey } }
|
|
632
|
+
: { mutation: { mutationKey, }, fetch: undefined };
|
|
633
|
+
const mutationFn = (props) => {
|
|
634
|
+
const { id } = props ?? {};
|
|
635
|
+
return deleteStoredFile(id, fetchOptions);
|
|
636
|
+
};
|
|
637
|
+
return { mutationFn, ...mutationOptions };
|
|
638
|
+
};
|
|
639
|
+
/**
|
|
640
|
+
* @summary Soft delete stored file
|
|
641
|
+
*/
|
|
642
|
+
export const useDeleteStoredFile = (options, queryClient) => {
|
|
643
|
+
const mutationOptions = getDeleteStoredFileMutationOptions(options);
|
|
644
|
+
return useMutation(mutationOptions, queryClient);
|
|
645
|
+
};
|
|
646
|
+
export const getGetHealthUrl = () => {
|
|
647
|
+
return `/health`;
|
|
648
|
+
};
|
|
649
|
+
export const getHealth = async (options) => {
|
|
650
|
+
const res = await fetch(getGetHealthUrl(), {
|
|
651
|
+
...options,
|
|
652
|
+
method: 'GET'
|
|
653
|
+
});
|
|
654
|
+
const body = [204, 205, 304].includes(res.status) ? null : await res.text();
|
|
655
|
+
const data = body ? JSON.parse(body) : {};
|
|
656
|
+
return { data, status: res.status, headers: res.headers };
|
|
657
|
+
};
|
|
658
|
+
export const getGetHealthQueryKey = () => {
|
|
659
|
+
return [
|
|
660
|
+
`/health`
|
|
661
|
+
];
|
|
662
|
+
};
|
|
663
|
+
export const getGetHealthQueryOptions = (options) => {
|
|
664
|
+
const { query: queryOptions, fetch: fetchOptions } = options ?? {};
|
|
665
|
+
const queryKey = queryOptions?.queryKey ?? getGetHealthQueryKey();
|
|
666
|
+
const queryFn = ({ signal }) => getHealth({ signal, ...fetchOptions });
|
|
667
|
+
return { queryKey, queryFn, ...queryOptions };
|
|
668
|
+
};
|
|
669
|
+
/**
|
|
670
|
+
* @summary Health check
|
|
671
|
+
*/
|
|
672
|
+
export function useGetHealth(options, queryClient) {
|
|
673
|
+
const queryOptions = getGetHealthQueryOptions(options);
|
|
674
|
+
const query = useQuery(queryOptions, queryClient);
|
|
675
|
+
query.queryKey = queryOptions.queryKey;
|
|
676
|
+
return query;
|
|
677
|
+
}
|
|
678
|
+
;
|
|
679
|
+
export const getGetCustomersUrl = () => {
|
|
680
|
+
return `/customers`;
|
|
681
|
+
};
|
|
682
|
+
export const getCustomers = async (options) => {
|
|
683
|
+
const res = await fetch(getGetCustomersUrl(), {
|
|
684
|
+
...options,
|
|
685
|
+
method: 'GET'
|
|
686
|
+
});
|
|
687
|
+
const body = [204, 205, 304].includes(res.status) ? null : await res.text();
|
|
688
|
+
const data = body ? JSON.parse(body) : {};
|
|
689
|
+
return { data, status: res.status, headers: res.headers };
|
|
690
|
+
};
|
|
691
|
+
export const getGetCustomersQueryKey = () => {
|
|
692
|
+
return [
|
|
693
|
+
`/customers`
|
|
694
|
+
];
|
|
695
|
+
};
|
|
696
|
+
export const getGetCustomersQueryOptions = (options) => {
|
|
697
|
+
const { query: queryOptions, fetch: fetchOptions } = options ?? {};
|
|
698
|
+
const queryKey = queryOptions?.queryKey ?? getGetCustomersQueryKey();
|
|
699
|
+
const queryFn = ({ signal }) => getCustomers({ signal, ...fetchOptions });
|
|
700
|
+
return { queryKey, queryFn, ...queryOptions };
|
|
701
|
+
};
|
|
702
|
+
export function useGetCustomers(options, queryClient) {
|
|
703
|
+
const queryOptions = getGetCustomersQueryOptions(options);
|
|
704
|
+
const query = useQuery(queryOptions, queryClient);
|
|
705
|
+
query.queryKey = queryOptions.queryKey;
|
|
706
|
+
return query;
|
|
707
|
+
}
|
|
708
|
+
export const getCreateWarehouseUrl = () => {
|
|
709
|
+
return `/warehouses`;
|
|
710
|
+
};
|
|
711
|
+
export const createWarehouse = async (createWarehouseBody, options) => {
|
|
712
|
+
const res = await fetch(getCreateWarehouseUrl(), {
|
|
713
|
+
...options,
|
|
714
|
+
method: 'POST',
|
|
715
|
+
headers: { 'Content-Type': 'application/json', ...options?.headers },
|
|
716
|
+
body: JSON.stringify(createWarehouseBody)
|
|
717
|
+
});
|
|
718
|
+
const body = [204, 205, 304].includes(res.status) ? null : await res.text();
|
|
719
|
+
const data = body ? JSON.parse(body) : {};
|
|
720
|
+
return { data, status: res.status, headers: res.headers };
|
|
721
|
+
};
|
|
722
|
+
export const getCreateWarehouseMutationOptions = (options) => {
|
|
723
|
+
const mutationKey = ['createWarehouse'];
|
|
724
|
+
const { mutation: mutationOptions, fetch: fetchOptions } = options ?
|
|
725
|
+
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
|
|
726
|
+
options
|
|
727
|
+
: { ...options, mutation: { ...options.mutation, mutationKey } }
|
|
728
|
+
: { mutation: { mutationKey, }, fetch: undefined };
|
|
729
|
+
const mutationFn = (props) => {
|
|
730
|
+
const { data } = props ?? {};
|
|
731
|
+
return createWarehouse(data, fetchOptions);
|
|
732
|
+
};
|
|
733
|
+
return { mutationFn, ...mutationOptions };
|
|
734
|
+
};
|
|
735
|
+
/**
|
|
736
|
+
* @summary Create a new warehouse
|
|
737
|
+
*/
|
|
738
|
+
export const useCreateWarehouse = (options, queryClient) => {
|
|
739
|
+
const mutationOptions = getCreateWarehouseMutationOptions(options);
|
|
740
|
+
return useMutation(mutationOptions, queryClient);
|
|
741
|
+
};
|
|
742
|
+
;
|
|
743
|
+
export const getListWarehousesUrl = (params) => {
|
|
744
|
+
const normalizedParams = new URLSearchParams();
|
|
745
|
+
Object.entries(params || {}).forEach(([key, value]) => {
|
|
746
|
+
if (value !== undefined) {
|
|
747
|
+
normalizedParams.append(key, value === null ? 'null' : value.toString());
|
|
748
|
+
}
|
|
749
|
+
});
|
|
750
|
+
const stringifiedParams = normalizedParams.toString();
|
|
751
|
+
return stringifiedParams.length > 0 ? `/warehouses?${stringifiedParams}` : `/warehouses`;
|
|
752
|
+
};
|
|
753
|
+
export const listWarehouses = async (params, options) => {
|
|
754
|
+
const res = await fetch(getListWarehousesUrl(params), {
|
|
755
|
+
...options,
|
|
756
|
+
method: 'GET'
|
|
757
|
+
});
|
|
758
|
+
const body = [204, 205, 304].includes(res.status) ? null : await res.text();
|
|
759
|
+
const data = body ? JSON.parse(body) : {};
|
|
760
|
+
return { data, status: res.status, headers: res.headers };
|
|
761
|
+
};
|
|
762
|
+
export const getListWarehousesQueryKey = (params) => {
|
|
763
|
+
return [
|
|
764
|
+
`/warehouses`, ...(params ? [params] : [])
|
|
765
|
+
];
|
|
766
|
+
};
|
|
767
|
+
export const getListWarehousesQueryOptions = (params, options) => {
|
|
768
|
+
const { query: queryOptions, fetch: fetchOptions } = options ?? {};
|
|
769
|
+
const queryKey = queryOptions?.queryKey ?? getListWarehousesQueryKey(params);
|
|
770
|
+
const queryFn = ({ signal }) => listWarehouses(params, { signal, ...fetchOptions });
|
|
771
|
+
return { queryKey, queryFn, ...queryOptions };
|
|
772
|
+
};
|
|
773
|
+
/**
|
|
774
|
+
* @summary List all warehouses
|
|
775
|
+
*/
|
|
776
|
+
export function useListWarehouses(params, options, queryClient) {
|
|
777
|
+
const queryOptions = getListWarehousesQueryOptions(params, options);
|
|
778
|
+
const query = useQuery(queryOptions, queryClient);
|
|
779
|
+
query.queryKey = queryOptions.queryKey;
|
|
780
|
+
return query;
|
|
781
|
+
}
|
|
782
|
+
;
|
|
783
|
+
export const getListStockMovementsUrl = (params) => {
|
|
784
|
+
const normalizedParams = new URLSearchParams();
|
|
785
|
+
Object.entries(params || {}).forEach(([key, value]) => {
|
|
786
|
+
if (value !== undefined) {
|
|
787
|
+
normalizedParams.append(key, value === null ? 'null' : value.toString());
|
|
788
|
+
}
|
|
789
|
+
});
|
|
790
|
+
const stringifiedParams = normalizedParams.toString();
|
|
791
|
+
return stringifiedParams.length > 0 ? `/stock-movements?${stringifiedParams}` : `/stock-movements`;
|
|
792
|
+
};
|
|
793
|
+
export const listStockMovements = async (params, options) => {
|
|
794
|
+
const res = await fetch(getListStockMovementsUrl(params), {
|
|
795
|
+
...options,
|
|
796
|
+
method: 'GET'
|
|
797
|
+
});
|
|
798
|
+
const body = [204, 205, 304].includes(res.status) ? null : await res.text();
|
|
799
|
+
const data = body ? JSON.parse(body) : {};
|
|
800
|
+
return { data, status: res.status, headers: res.headers };
|
|
801
|
+
};
|
|
802
|
+
export const getListStockMovementsQueryKey = (params) => {
|
|
803
|
+
return [
|
|
804
|
+
`/stock-movements`, ...(params ? [params] : [])
|
|
805
|
+
];
|
|
806
|
+
};
|
|
807
|
+
export const getListStockMovementsQueryOptions = (params, options) => {
|
|
808
|
+
const { query: queryOptions, fetch: fetchOptions } = options ?? {};
|
|
809
|
+
const queryKey = queryOptions?.queryKey ?? getListStockMovementsQueryKey(params);
|
|
810
|
+
const queryFn = ({ signal }) => listStockMovements(params, { signal, ...fetchOptions });
|
|
811
|
+
return { queryKey, queryFn, ...queryOptions };
|
|
812
|
+
};
|
|
813
|
+
/**
|
|
814
|
+
* @summary List stock movements
|
|
815
|
+
*/
|
|
816
|
+
export function useListStockMovements(params, options, queryClient) {
|
|
817
|
+
const queryOptions = getListStockMovementsQueryOptions(params, options);
|
|
818
|
+
const query = useQuery(queryOptions, queryClient);
|
|
819
|
+
query.queryKey = queryOptions.queryKey;
|
|
820
|
+
return query;
|
|
821
|
+
}
|
|
822
|
+
export const getCreateStockItemUrl = () => {
|
|
823
|
+
return `/stock-items`;
|
|
824
|
+
};
|
|
825
|
+
export const createStockItem = async (createStockItemBody, options) => {
|
|
826
|
+
const res = await fetch(getCreateStockItemUrl(), {
|
|
827
|
+
...options,
|
|
828
|
+
method: 'POST',
|
|
829
|
+
headers: { 'Content-Type': 'application/json', ...options?.headers },
|
|
830
|
+
body: JSON.stringify(createStockItemBody)
|
|
831
|
+
});
|
|
832
|
+
const body = [204, 205, 304].includes(res.status) ? null : await res.text();
|
|
833
|
+
const data = body ? JSON.parse(body) : {};
|
|
834
|
+
return { data, status: res.status, headers: res.headers };
|
|
835
|
+
};
|
|
836
|
+
export const getCreateStockItemMutationOptions = (options) => {
|
|
837
|
+
const mutationKey = ['createStockItem'];
|
|
838
|
+
const { mutation: mutationOptions, fetch: fetchOptions } = options ?
|
|
839
|
+
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
|
|
840
|
+
options
|
|
841
|
+
: { ...options, mutation: { ...options.mutation, mutationKey } }
|
|
842
|
+
: { mutation: { mutationKey, }, fetch: undefined };
|
|
843
|
+
const mutationFn = (props) => {
|
|
844
|
+
const { data } = props ?? {};
|
|
845
|
+
return createStockItem(data, fetchOptions);
|
|
846
|
+
};
|
|
847
|
+
return { mutationFn, ...mutationOptions };
|
|
848
|
+
};
|
|
849
|
+
/**
|
|
850
|
+
* @summary Create a new stock item
|
|
851
|
+
*/
|
|
852
|
+
export const useCreateStockItem = (options, queryClient) => {
|
|
853
|
+
const mutationOptions = getCreateStockItemMutationOptions(options);
|
|
854
|
+
return useMutation(mutationOptions, queryClient);
|
|
855
|
+
};
|
|
856
|
+
;
|
|
857
|
+
export const getListStockItemsUrl = (params) => {
|
|
858
|
+
const normalizedParams = new URLSearchParams();
|
|
859
|
+
Object.entries(params || {}).forEach(([key, value]) => {
|
|
860
|
+
if (value !== undefined) {
|
|
861
|
+
normalizedParams.append(key, value === null ? 'null' : value.toString());
|
|
862
|
+
}
|
|
863
|
+
});
|
|
864
|
+
const stringifiedParams = normalizedParams.toString();
|
|
865
|
+
return stringifiedParams.length > 0 ? `/stock-items?${stringifiedParams}` : `/stock-items`;
|
|
866
|
+
};
|
|
867
|
+
export const listStockItems = async (params, options) => {
|
|
868
|
+
const res = await fetch(getListStockItemsUrl(params), {
|
|
869
|
+
...options,
|
|
870
|
+
method: 'GET'
|
|
871
|
+
});
|
|
872
|
+
const body = [204, 205, 304].includes(res.status) ? null : await res.text();
|
|
873
|
+
const data = body ? JSON.parse(body) : {};
|
|
874
|
+
return { data, status: res.status, headers: res.headers };
|
|
875
|
+
};
|
|
876
|
+
export const getListStockItemsQueryKey = (params) => {
|
|
877
|
+
return [
|
|
878
|
+
`/stock-items`, ...(params ? [params] : [])
|
|
879
|
+
];
|
|
880
|
+
};
|
|
881
|
+
export const getListStockItemsQueryOptions = (params, options) => {
|
|
882
|
+
const { query: queryOptions, fetch: fetchOptions } = options ?? {};
|
|
883
|
+
const queryKey = queryOptions?.queryKey ?? getListStockItemsQueryKey(params);
|
|
884
|
+
const queryFn = ({ signal }) => listStockItems(params, { signal, ...fetchOptions });
|
|
885
|
+
return { queryKey, queryFn, ...queryOptions };
|
|
886
|
+
};
|
|
887
|
+
/**
|
|
888
|
+
* @summary List stock items
|
|
889
|
+
*/
|
|
890
|
+
export function useListStockItems(params, options, queryClient) {
|
|
891
|
+
const queryOptions = getListStockItemsQueryOptions(params, options);
|
|
892
|
+
const query = useQuery(queryOptions, queryClient);
|
|
893
|
+
query.queryKey = queryOptions.queryKey;
|
|
894
|
+
return query;
|
|
895
|
+
}
|
|
896
|
+
export const getCreateBatchUrl = () => {
|
|
897
|
+
return `/batches`;
|
|
898
|
+
};
|
|
899
|
+
export const createBatch = async (createBatchBody, options) => {
|
|
900
|
+
const res = await fetch(getCreateBatchUrl(), {
|
|
901
|
+
...options,
|
|
902
|
+
method: 'POST',
|
|
903
|
+
headers: { 'Content-Type': 'application/json', ...options?.headers },
|
|
904
|
+
body: JSON.stringify(createBatchBody)
|
|
905
|
+
});
|
|
906
|
+
const body = [204, 205, 304].includes(res.status) ? null : await res.text();
|
|
907
|
+
const data = body ? JSON.parse(body) : {};
|
|
908
|
+
return { data, status: res.status, headers: res.headers };
|
|
909
|
+
};
|
|
910
|
+
export const getCreateBatchMutationOptions = (options) => {
|
|
911
|
+
const mutationKey = ['createBatch'];
|
|
912
|
+
const { mutation: mutationOptions, fetch: fetchOptions } = options ?
|
|
913
|
+
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
|
|
914
|
+
options
|
|
915
|
+
: { ...options, mutation: { ...options.mutation, mutationKey } }
|
|
916
|
+
: { mutation: { mutationKey, }, fetch: undefined };
|
|
917
|
+
const mutationFn = (props) => {
|
|
918
|
+
const { data } = props ?? {};
|
|
919
|
+
return createBatch(data, fetchOptions);
|
|
920
|
+
};
|
|
921
|
+
return { mutationFn, ...mutationOptions };
|
|
922
|
+
};
|
|
923
|
+
/**
|
|
924
|
+
* @summary Create a new stock batch
|
|
925
|
+
*/
|
|
926
|
+
export const useCreateBatch = (options, queryClient) => {
|
|
927
|
+
const mutationOptions = getCreateBatchMutationOptions(options);
|
|
928
|
+
return useMutation(mutationOptions, queryClient);
|
|
929
|
+
};
|
|
930
|
+
export const getGetUrl = () => {
|
|
931
|
+
return `/`;
|
|
932
|
+
};
|
|
933
|
+
export const get = async (options) => {
|
|
934
|
+
const res = await fetch(getGetUrl(), {
|
|
935
|
+
...options,
|
|
936
|
+
method: 'GET'
|
|
937
|
+
});
|
|
938
|
+
const body = [204, 205, 304].includes(res.status) ? null : await res.text();
|
|
939
|
+
const data = body ? JSON.parse(body) : {};
|
|
940
|
+
return { data, status: res.status, headers: res.headers };
|
|
941
|
+
};
|
|
942
|
+
export const getGetQueryKey = () => {
|
|
943
|
+
return [
|
|
944
|
+
`/`
|
|
945
|
+
];
|
|
946
|
+
};
|
|
947
|
+
export const getGetQueryOptions = (options) => {
|
|
948
|
+
const { query: queryOptions, fetch: fetchOptions } = options ?? {};
|
|
949
|
+
const queryKey = queryOptions?.queryKey ?? getGetQueryKey();
|
|
950
|
+
const queryFn = ({ signal }) => get({ signal, ...fetchOptions });
|
|
951
|
+
return { queryKey, queryFn, ...queryOptions };
|
|
952
|
+
};
|
|
953
|
+
/**
|
|
954
|
+
* @summary API welcome message
|
|
955
|
+
*/
|
|
956
|
+
export function useGet(options, queryClient) {
|
|
957
|
+
const queryOptions = getGetQueryOptions(options);
|
|
958
|
+
const query = useQuery(queryOptions, queryClient);
|
|
959
|
+
query.queryKey = queryOptions.queryKey;
|
|
960
|
+
return query;
|
|
961
|
+
}
|