@go-avro/avro-js 0.0.2-beta.117 → 0.0.2-beta.119
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/client/QueryClient.d.ts +6 -2
- package/dist/client/QueryClient.js +10 -6
- package/dist/client/hooks/bills.js +6 -6
- package/dist/client/hooks/chats.js +2 -2
- package/dist/client/hooks/companies.js +5 -5
- package/dist/client/hooks/events.js +6 -6
- package/dist/client/hooks/jobs.js +53 -6
- package/dist/client/hooks/messages.js +2 -2
- package/dist/client/hooks/months.js +3 -3
- package/dist/client/hooks/plans.js +1 -2
- package/dist/client/hooks/routes.js +6 -6
- package/dist/client/hooks/sessions.js +6 -6
- package/dist/client/hooks/teams.js +5 -5
- package/dist/client/hooks/users.js +4 -4
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Socket } from 'socket.io-client';
|
|
2
|
-
import { InfiniteData, UseInfiniteQueryResult, useMutation, UseQueryResult } from '@tanstack/react-query';
|
|
2
|
+
import { InfiniteData, QueryClient, UseInfiniteQueryResult, useMutation, UseQueryResult } from '@tanstack/react-query';
|
|
3
3
|
import { AuthManager } from '../auth/AuthManager';
|
|
4
4
|
import { _Event, ApiInfo, Avro, Bill, Break, Chat, Company, FinancialInsightData, Job, EventInsightData, LoginResponse, Message, Plan, Route, ServiceMonth, Session, Team, User, UserCompanyAssociation } from '../types/api';
|
|
5
5
|
import { Tokens } from '../types/auth';
|
|
@@ -9,6 +9,7 @@ import { CacheData } from '../types/cache';
|
|
|
9
9
|
export interface AvroQueryClientConfig {
|
|
10
10
|
baseUrl: string;
|
|
11
11
|
authManager: AuthManager;
|
|
12
|
+
queryClient: QueryClient;
|
|
12
13
|
maxRetries?: number;
|
|
13
14
|
retryStrategy?: RetryStrategy;
|
|
14
15
|
timeout?: number;
|
|
@@ -20,7 +21,9 @@ declare module '../client/QueryClient' {
|
|
|
20
21
|
getDelay(strategy: RetryStrategy, attempt: number): number;
|
|
21
22
|
sleep(ms: number): Promise<void>;
|
|
22
23
|
useGetRoot(): UseQueryResult<ApiInfo, StandardError>;
|
|
23
|
-
useGetJobs(
|
|
24
|
+
useGetJobs(total: number, onProgress?: (fraction: number) => void): UseQueryResult<Job[], StandardError>;
|
|
25
|
+
getJobsFromCache(): Job[];
|
|
26
|
+
useGetInfiniteJobs(body: {
|
|
24
27
|
amt?: number;
|
|
25
28
|
query?: string;
|
|
26
29
|
routeId?: string;
|
|
@@ -318,6 +321,7 @@ export declare class AvroQueryClient {
|
|
|
318
321
|
clearCache(): Promise<void>;
|
|
319
322
|
isAuthenticated(): boolean;
|
|
320
323
|
isAuthenticatedAsync(): Promise<boolean>;
|
|
324
|
+
getQueryClient(): QueryClient;
|
|
321
325
|
useLogout(): ReturnType<typeof useMutation<void, StandardError, CancelToken | undefined>>;
|
|
322
326
|
fetchJobs(body?: {
|
|
323
327
|
amt?: number;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import io from 'socket.io-client';
|
|
2
|
-
import { useMutation
|
|
2
|
+
import { useMutation } from '@tanstack/react-query';
|
|
3
3
|
import { LoginResponse } from '../types/api';
|
|
4
4
|
import { StandardError } from '../types/error';
|
|
5
5
|
export class AvroQueryClient {
|
|
@@ -9,6 +9,7 @@ export class AvroQueryClient {
|
|
|
9
9
|
this.config = {
|
|
10
10
|
baseUrl: config.baseUrl,
|
|
11
11
|
authManager: config.authManager,
|
|
12
|
+
queryClient: config.queryClient,
|
|
12
13
|
maxRetries: config.maxRetries ?? 3,
|
|
13
14
|
retryStrategy: config.retryStrategy ?? 'fixed',
|
|
14
15
|
timeout: config.timeout ?? 0,
|
|
@@ -78,7 +79,7 @@ export class AvroQueryClient {
|
|
|
78
79
|
return this._xhr('DELETE', path, null, cancelToken, headers, false, this.config.maxRetries, progressUpdateCallback);
|
|
79
80
|
}
|
|
80
81
|
useLogin() {
|
|
81
|
-
const queryClient =
|
|
82
|
+
const queryClient = this.getQueryClient();
|
|
82
83
|
return useMutation({
|
|
83
84
|
mutationFn: async ({ username, password, code, cancelToken }) => {
|
|
84
85
|
const resp = await this.post('/login', JSON.stringify({ username, password, code }), cancelToken, { 'Content-Type': 'application/json' });
|
|
@@ -106,7 +107,7 @@ export class AvroQueryClient {
|
|
|
106
107
|
});
|
|
107
108
|
}
|
|
108
109
|
useRequestCode() {
|
|
109
|
-
const queryClient =
|
|
110
|
+
const queryClient = this.getQueryClient();
|
|
110
111
|
return useMutation({
|
|
111
112
|
mutationFn: async ({ username, email, cancelToken }) => {
|
|
112
113
|
const resp = await this.post('/code', JSON.stringify({ username, email }), cancelToken, { 'Content-Type': 'application/json' });
|
|
@@ -121,7 +122,7 @@ export class AvroQueryClient {
|
|
|
121
122
|
});
|
|
122
123
|
}
|
|
123
124
|
useUpdatePassword() {
|
|
124
|
-
const queryClient =
|
|
125
|
+
const queryClient = this.getQueryClient();
|
|
125
126
|
return useMutation({
|
|
126
127
|
mutationFn: async ({ username, email, code, newPassword, cancelToken }) => {
|
|
127
128
|
await this.post(`/user/${username ?? email}/password`, JSON.stringify({ code, password: newPassword }), cancelToken, { 'Content-Type': 'application/json' });
|
|
@@ -135,7 +136,7 @@ export class AvroQueryClient {
|
|
|
135
136
|
});
|
|
136
137
|
}
|
|
137
138
|
useGoogleLogin() {
|
|
138
|
-
const queryClient =
|
|
139
|
+
const queryClient = this.getQueryClient();
|
|
139
140
|
return useMutation({
|
|
140
141
|
mutationFn: async ({ token, cancelToken }) => {
|
|
141
142
|
const resp = await this._xhr('POST', `/google/authorize?token=${token}`, {}, cancelToken, { 'Content-Type': 'application/json' });
|
|
@@ -184,8 +185,11 @@ export class AvroQueryClient {
|
|
|
184
185
|
isAuthenticatedAsync() {
|
|
185
186
|
return this.config.authManager.isAuthenticated();
|
|
186
187
|
}
|
|
188
|
+
getQueryClient() {
|
|
189
|
+
return this.config.queryClient;
|
|
190
|
+
}
|
|
187
191
|
useLogout() {
|
|
188
|
-
const queryClient =
|
|
192
|
+
const queryClient = this.getQueryClient();
|
|
189
193
|
return useMutation({
|
|
190
194
|
mutationFn: async (cancelToken) => {
|
|
191
195
|
await this.post('/logout', null, cancelToken);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useInfiniteQuery, useQuery, useMutation } from '@tanstack/react-query';
|
|
2
2
|
import { AvroQueryClient } from '../../client/QueryClient';
|
|
3
3
|
AvroQueryClient.prototype.useGetBills = function (body) {
|
|
4
|
-
const queryClient =
|
|
4
|
+
const queryClient = this.getQueryClient();
|
|
5
5
|
const result = useInfiniteQuery({
|
|
6
6
|
queryKey: [
|
|
7
7
|
'bills',
|
|
@@ -36,7 +36,7 @@ AvroQueryClient.prototype.useGetBill = function (billId) {
|
|
|
36
36
|
});
|
|
37
37
|
};
|
|
38
38
|
AvroQueryClient.prototype.useCreateBill = function () {
|
|
39
|
-
const queryClient =
|
|
39
|
+
const queryClient = this.getQueryClient();
|
|
40
40
|
return useMutation({
|
|
41
41
|
mutationFn: async ({ data }) => {
|
|
42
42
|
const body = {
|
|
@@ -70,7 +70,7 @@ AvroQueryClient.prototype.useCreateBill = function () {
|
|
|
70
70
|
});
|
|
71
71
|
};
|
|
72
72
|
AvroQueryClient.prototype.useUpdateBill = function () {
|
|
73
|
-
const queryClient =
|
|
73
|
+
const queryClient = this.getQueryClient();
|
|
74
74
|
return useMutation({
|
|
75
75
|
mutationFn: ({ billId, updates }) => {
|
|
76
76
|
return this.put(`/bill/${billId}`, JSON.stringify(updates), undefined, {
|
|
@@ -116,7 +116,7 @@ AvroQueryClient.prototype.useUpdateBill = function () {
|
|
|
116
116
|
});
|
|
117
117
|
};
|
|
118
118
|
AvroQueryClient.prototype.useDeleteBill = function () {
|
|
119
|
-
const queryClient =
|
|
119
|
+
const queryClient = this.getQueryClient();
|
|
120
120
|
return useMutation({
|
|
121
121
|
mutationFn: async ({ billId }) => {
|
|
122
122
|
return this.delete(`/bill/${billId}`);
|
|
@@ -140,7 +140,7 @@ AvroQueryClient.prototype.useDeleteBill = function () {
|
|
|
140
140
|
});
|
|
141
141
|
};
|
|
142
142
|
AvroQueryClient.prototype.useSyncBillToIntuit = function () {
|
|
143
|
-
const queryClient =
|
|
143
|
+
const queryClient = this.getQueryClient();
|
|
144
144
|
return useMutation({
|
|
145
145
|
mutationFn: async ({ billId }) => {
|
|
146
146
|
return this.post(`/company/${this.companyId}/bill/${billId}/intuit/sync`, null);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { useInfiniteQuery, useQuery
|
|
1
|
+
import { useInfiniteQuery, useQuery } from "@tanstack/react-query";
|
|
2
2
|
import { AvroQueryClient } from "../../client/QueryClient";
|
|
3
3
|
AvroQueryClient.prototype.useGetChats = function (body) {
|
|
4
|
-
const queryClient =
|
|
4
|
+
const queryClient = this.getQueryClient();
|
|
5
5
|
const result = useInfiniteQuery({
|
|
6
6
|
queryKey: [
|
|
7
7
|
'chats',
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useMutation, useQuery
|
|
1
|
+
import { useMutation, useQuery } from '@tanstack/react-query';
|
|
2
2
|
import { AvroQueryClient } from '../../client/QueryClient';
|
|
3
3
|
AvroQueryClient.prototype.useGetCompanies = function (options = {}) {
|
|
4
4
|
return useQuery({
|
|
@@ -32,7 +32,7 @@ AvroQueryClient.prototype.useGetCurrentCompany = function () {
|
|
|
32
32
|
});
|
|
33
33
|
};
|
|
34
34
|
AvroQueryClient.prototype.useCreateCompany = function () {
|
|
35
|
-
const queryClient =
|
|
35
|
+
const queryClient = this.getQueryClient();
|
|
36
36
|
return useMutation({
|
|
37
37
|
mutationFn: async ({ companyData }) => {
|
|
38
38
|
return this.post(`/company`, JSON.stringify(companyData), undefined, { "Content-Type": "application/json" });
|
|
@@ -43,7 +43,7 @@ AvroQueryClient.prototype.useCreateCompany = function () {
|
|
|
43
43
|
});
|
|
44
44
|
};
|
|
45
45
|
AvroQueryClient.prototype.useUpdateCompany = function () {
|
|
46
|
-
const queryClient =
|
|
46
|
+
const queryClient = this.getQueryClient();
|
|
47
47
|
return useMutation({
|
|
48
48
|
mutationFn: async ({ companyId, companyData, }) => {
|
|
49
49
|
return this.put(`/company/${companyId}`, JSON.stringify(companyData), undefined, { "Content-Type": "application/json" });
|
|
@@ -78,7 +78,7 @@ AvroQueryClient.prototype.useUpdateCompany = function () {
|
|
|
78
78
|
});
|
|
79
79
|
};
|
|
80
80
|
AvroQueryClient.prototype.useRemoveUserCompany = function () {
|
|
81
|
-
const queryClient =
|
|
81
|
+
const queryClient = this.getQueryClient();
|
|
82
82
|
return useMutation({
|
|
83
83
|
mutationFn: async ({ companyId, userId }) => {
|
|
84
84
|
return this.delete(`/company/${companyId}/user/${userId}`);
|
|
@@ -109,7 +109,7 @@ AvroQueryClient.prototype.useRemoveUserCompany = function () {
|
|
|
109
109
|
});
|
|
110
110
|
};
|
|
111
111
|
AvroQueryClient.prototype.useDeleteCompany = function () {
|
|
112
|
-
const queryClient =
|
|
112
|
+
const queryClient = this.getQueryClient();
|
|
113
113
|
return useMutation({
|
|
114
114
|
mutationFn: async ({ companyId }) => {
|
|
115
115
|
return this.delete(`/company/${companyId}`);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useInfiniteQuery, useQuery, useMutation } from '@tanstack/react-query';
|
|
2
2
|
import { AvroQueryClient } from '../../client/QueryClient';
|
|
3
3
|
AvroQueryClient.prototype.useGetEvents = function (body) {
|
|
4
|
-
const queryClient =
|
|
4
|
+
const queryClient = this.getQueryClient();
|
|
5
5
|
const result = useInfiniteQuery({
|
|
6
6
|
queryKey: [
|
|
7
7
|
'events',
|
|
@@ -40,7 +40,7 @@ AvroQueryClient.prototype.useGetEvent = function (eventId) {
|
|
|
40
40
|
});
|
|
41
41
|
};
|
|
42
42
|
AvroQueryClient.prototype.useCreateEvent = function () {
|
|
43
|
-
const queryClient =
|
|
43
|
+
const queryClient = this.getQueryClient();
|
|
44
44
|
return useMutation({
|
|
45
45
|
mutationFn: ({ eventData }) => {
|
|
46
46
|
return this.post(`/company/${this.companyId}/event`, JSON.stringify(eventData), undefined, {
|
|
@@ -125,7 +125,7 @@ AvroQueryClient.prototype.useCreateEvent = function () {
|
|
|
125
125
|
});
|
|
126
126
|
};
|
|
127
127
|
AvroQueryClient.prototype.useUpdateEvent = function () {
|
|
128
|
-
const queryClient =
|
|
128
|
+
const queryClient = this.getQueryClient();
|
|
129
129
|
return useMutation({
|
|
130
130
|
mutationFn: ({ eventId, updates }) => {
|
|
131
131
|
return this.put(`/event/${eventId}`, JSON.stringify(updates), undefined, {
|
|
@@ -200,7 +200,7 @@ AvroQueryClient.prototype.useUpdateEvent = function () {
|
|
|
200
200
|
});
|
|
201
201
|
};
|
|
202
202
|
AvroQueryClient.prototype.useUpdateEvents = function () {
|
|
203
|
-
const queryClient =
|
|
203
|
+
const queryClient = this.getQueryClient();
|
|
204
204
|
return useMutation({
|
|
205
205
|
mutationFn: async ({ events, action, }) => {
|
|
206
206
|
const eventIds = events.map(event => event.id);
|
|
@@ -262,7 +262,7 @@ AvroQueryClient.prototype.useUpdateEvents = function () {
|
|
|
262
262
|
});
|
|
263
263
|
};
|
|
264
264
|
AvroQueryClient.prototype.useDeleteEvent = function () {
|
|
265
|
-
const queryClient =
|
|
265
|
+
const queryClient = this.getQueryClient();
|
|
266
266
|
return useMutation({
|
|
267
267
|
mutationFn: async ({ eventId, }) => {
|
|
268
268
|
return this.delete(`/event/${eventId}`, undefined, {
|
|
@@ -1,7 +1,54 @@
|
|
|
1
|
-
import { useMutation, useQuery,
|
|
1
|
+
import { useMutation, useQuery, useInfiniteQuery } from '@tanstack/react-query';
|
|
2
2
|
import { AvroQueryClient } from '../../client/QueryClient';
|
|
3
|
-
AvroQueryClient.prototype.
|
|
4
|
-
const queryClient =
|
|
3
|
+
AvroQueryClient.prototype.getJobsFromCache = function () {
|
|
4
|
+
const queryClient = this.getQueryClient();
|
|
5
|
+
const cachedJobsData = queryClient.getQueryData(['jobs', this.companyId]);
|
|
6
|
+
if (cachedJobsData && cachedJobsData.pages) {
|
|
7
|
+
return cachedJobsData.pages.flat();
|
|
8
|
+
}
|
|
9
|
+
const cachedJobs = queryClient.getQueryData(['jobs', this.companyId]);
|
|
10
|
+
return cachedJobs || [];
|
|
11
|
+
};
|
|
12
|
+
AvroQueryClient.prototype.useGetJobs = function (total = 0, onProgress) {
|
|
13
|
+
const queryClient = this.getQueryClient();
|
|
14
|
+
const amt = 50;
|
|
15
|
+
return useQuery({
|
|
16
|
+
queryKey: ['jobs', this.companyId],
|
|
17
|
+
queryFn: async () => {
|
|
18
|
+
if (total === 0) {
|
|
19
|
+
onProgress?.(1);
|
|
20
|
+
return [];
|
|
21
|
+
}
|
|
22
|
+
onProgress?.(0);
|
|
23
|
+
const pageCount = amt ? Math.ceil(total / amt) : 0;
|
|
24
|
+
let completed = 0;
|
|
25
|
+
const promises = Array.from({ length: pageCount }, (_, i) => this.fetchJobs({ offset: i * amt }));
|
|
26
|
+
const trackedPromises = promises.map((promise) => promise.then((result) => {
|
|
27
|
+
completed++;
|
|
28
|
+
const fraction = completed / pageCount;
|
|
29
|
+
onProgress?.(fraction);
|
|
30
|
+
return result;
|
|
31
|
+
}));
|
|
32
|
+
const pages = await Promise.all(trackedPromises);
|
|
33
|
+
const jobs = pages.flat();
|
|
34
|
+
jobs.forEach((job) => {
|
|
35
|
+
job.current_event = job.tasks.reduce((latest, task) => {
|
|
36
|
+
return task.current_event && (!latest || task.current_event.time_started > latest.time_started) ? task.current_event : latest;
|
|
37
|
+
}, null);
|
|
38
|
+
job.last_completed_event = job.tasks.reduce((latest, task) => {
|
|
39
|
+
return task.last_completed_event && (!latest || task.last_completed_event.time_started > latest.time_started) ? task.last_completed_event : latest;
|
|
40
|
+
}, null);
|
|
41
|
+
job.overdue_time = job.tasks.reduce((maxOverdue, task) => {
|
|
42
|
+
return task.overdue_time && task.overdue_time > maxOverdue ? task.overdue_time : maxOverdue;
|
|
43
|
+
}, 0);
|
|
44
|
+
queryClient.setQueryData(['job', job.id], job);
|
|
45
|
+
});
|
|
46
|
+
return jobs;
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
AvroQueryClient.prototype.useGetInfiniteJobs = function (body, onProgress) {
|
|
51
|
+
const queryClient = this.getQueryClient();
|
|
5
52
|
const result = useInfiniteQuery({
|
|
6
53
|
queryKey: ['jobs', this.companyId, body.amt ?? 50, body.query ?? "", body.routeId ?? ""],
|
|
7
54
|
initialPageParam: 0,
|
|
@@ -39,7 +86,7 @@ AvroQueryClient.prototype.useGetJob = function (jobId) {
|
|
|
39
86
|
});
|
|
40
87
|
};
|
|
41
88
|
AvroQueryClient.prototype.useCreateJob = function () {
|
|
42
|
-
const queryClient =
|
|
89
|
+
const queryClient = this.getQueryClient();
|
|
43
90
|
return useMutation({
|
|
44
91
|
mutationFn: ({ jobData }) => {
|
|
45
92
|
return this.post(`/company/${this.companyId}/job`, JSON.stringify(jobData), undefined, {
|
|
@@ -79,7 +126,7 @@ AvroQueryClient.prototype.useCreateJob = function () {
|
|
|
79
126
|
});
|
|
80
127
|
};
|
|
81
128
|
AvroQueryClient.prototype.useUpdateJob = function () {
|
|
82
|
-
const queryClient =
|
|
129
|
+
const queryClient = this.getQueryClient();
|
|
83
130
|
return useMutation({
|
|
84
131
|
mutationFn: ({ jobId, updates }) => {
|
|
85
132
|
return this.put(`/job/${jobId}`, JSON.stringify(updates), undefined, {
|
|
@@ -125,7 +172,7 @@ AvroQueryClient.prototype.useUpdateJob = function () {
|
|
|
125
172
|
});
|
|
126
173
|
};
|
|
127
174
|
AvroQueryClient.prototype.useDeleteJob = function () {
|
|
128
|
-
const queryClient =
|
|
175
|
+
const queryClient = this.getQueryClient();
|
|
129
176
|
return useMutation({
|
|
130
177
|
mutationFn: async ({ jobId }) => {
|
|
131
178
|
return this.delete(`/job/${jobId}`, undefined, {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { useInfiniteQuery
|
|
1
|
+
import { useInfiniteQuery } from "@tanstack/react-query";
|
|
2
2
|
import { AvroQueryClient } from "../../client/QueryClient";
|
|
3
3
|
AvroQueryClient.prototype.useGetMessages = function (chatId, body) {
|
|
4
|
-
const queryClient =
|
|
4
|
+
const queryClient = this.getQueryClient();
|
|
5
5
|
const result = useInfiniteQuery({
|
|
6
6
|
queryKey: [
|
|
7
7
|
'messages',
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useInfiniteQuery, useMutation } from '@tanstack/react-query';
|
|
2
2
|
import { AvroQueryClient } from '../../client/QueryClient';
|
|
3
3
|
AvroQueryClient.prototype.useGetMonths = function (body) {
|
|
4
|
-
const queryClient =
|
|
4
|
+
const queryClient = this.getQueryClient();
|
|
5
5
|
const result = useInfiniteQuery({
|
|
6
6
|
queryKey: [
|
|
7
7
|
'months',
|
|
@@ -33,7 +33,7 @@ AvroQueryClient.prototype.useGetMonths = function (body) {
|
|
|
33
33
|
return result;
|
|
34
34
|
};
|
|
35
35
|
AvroQueryClient.prototype.useUpdateMonths = function () {
|
|
36
|
-
const queryClient =
|
|
36
|
+
const queryClient = this.getQueryClient();
|
|
37
37
|
return useMutation({
|
|
38
38
|
mutationFn: async ({ months, action, }) => {
|
|
39
39
|
const monthIds = months.map(month => month.id);
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { useQuery
|
|
1
|
+
import { useQuery } from "@tanstack/react-query";
|
|
2
2
|
import { AvroQueryClient } from "../../client/QueryClient";
|
|
3
3
|
AvroQueryClient.prototype.useGetPlans = function (code) {
|
|
4
|
-
const queryClient = useQueryClient();
|
|
5
4
|
return useQuery({
|
|
6
5
|
queryKey: ['plans', code],
|
|
7
6
|
queryFn: async () => this.get(`/plans${code ? `?code=${code}` : ''}`),
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { useMutation, useQuery
|
|
1
|
+
import { useMutation, useQuery } from '@tanstack/react-query';
|
|
2
2
|
import { AvroQueryClient } from '../../client/QueryClient';
|
|
3
3
|
AvroQueryClient.prototype.useGetRoutes = function (body, total, onProgress) {
|
|
4
4
|
return useQuery({
|
|
5
|
-
queryKey: ['routes', this.companyId, body.amt ?? 50, body.query ?? ""],
|
|
5
|
+
queryKey: ['routes', this.companyId, body.amt ?? 50, body.query ?? "", total ?? "all"],
|
|
6
6
|
queryFn: async () => {
|
|
7
7
|
if (typeof total !== "number") {
|
|
8
8
|
return this.fetchRoutes({ ...body, offset: 0 });
|
|
@@ -27,7 +27,7 @@ AvroQueryClient.prototype.useGetRoutes = function (body, total, onProgress) {
|
|
|
27
27
|
});
|
|
28
28
|
};
|
|
29
29
|
AvroQueryClient.prototype.useGetRoute = function (routeId) {
|
|
30
|
-
const queryClient =
|
|
30
|
+
const queryClient = this.getQueryClient();
|
|
31
31
|
return useQuery({
|
|
32
32
|
queryKey: ['route', routeId],
|
|
33
33
|
queryFn: () => this.get(`/route/${routeId}`),
|
|
@@ -35,7 +35,7 @@ AvroQueryClient.prototype.useGetRoute = function (routeId) {
|
|
|
35
35
|
});
|
|
36
36
|
};
|
|
37
37
|
AvroQueryClient.prototype.useCreateRoute = function () {
|
|
38
|
-
const queryClient =
|
|
38
|
+
const queryClient = this.getQueryClient();
|
|
39
39
|
return useMutation({
|
|
40
40
|
mutationFn: async ({ routeData }) => {
|
|
41
41
|
return this.post(`/company/${this.companyId}/route`, JSON.stringify(routeData), undefined, { "Content-Type": "application/json" });
|
|
@@ -76,7 +76,7 @@ AvroQueryClient.prototype.useCreateRoute = function () {
|
|
|
76
76
|
});
|
|
77
77
|
};
|
|
78
78
|
AvroQueryClient.prototype.useUpdateRoute = function () {
|
|
79
|
-
const queryClient =
|
|
79
|
+
const queryClient = this.getQueryClient();
|
|
80
80
|
return useMutation({
|
|
81
81
|
mutationFn: async ({ routeId, updates, }) => {
|
|
82
82
|
return this.put(`/route/${routeId}`, JSON.stringify(updates), undefined, { "Content-Type": "application/json" });
|
|
@@ -122,7 +122,7 @@ AvroQueryClient.prototype.useUpdateRoute = function () {
|
|
|
122
122
|
});
|
|
123
123
|
};
|
|
124
124
|
AvroQueryClient.prototype.useDeleteRoute = function () {
|
|
125
|
-
const queryClient =
|
|
125
|
+
const queryClient = this.getQueryClient();
|
|
126
126
|
return useMutation({
|
|
127
127
|
mutationFn: async ({ routeId, }) => {
|
|
128
128
|
return this.delete(`/route/${routeId}`);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useMutation, useQuery,
|
|
1
|
+
import { useMutation, useQuery, useInfiniteQuery } from "@tanstack/react-query";
|
|
2
2
|
import { AvroQueryClient } from "../../client/QueryClient";
|
|
3
3
|
AvroQueryClient.prototype.useGetUserSessions = function () {
|
|
4
4
|
return useQuery({
|
|
@@ -7,7 +7,7 @@ AvroQueryClient.prototype.useGetUserSessions = function () {
|
|
|
7
7
|
});
|
|
8
8
|
};
|
|
9
9
|
AvroQueryClient.prototype.useCreateUserSession = function () {
|
|
10
|
-
const queryClient =
|
|
10
|
+
const queryClient = this.getQueryClient();
|
|
11
11
|
return useMutation({
|
|
12
12
|
mutationFn: ({ sessionData }) => {
|
|
13
13
|
return this.post(`/company/${this.companyId}/session`, JSON.stringify(sessionData), undefined, {
|
|
@@ -45,7 +45,7 @@ AvroQueryClient.prototype.useCreateUserSession = function () {
|
|
|
45
45
|
});
|
|
46
46
|
};
|
|
47
47
|
AvroQueryClient.prototype.useCreateSessionBreak = function () {
|
|
48
|
-
const queryClient =
|
|
48
|
+
const queryClient = this.getQueryClient();
|
|
49
49
|
return useMutation({
|
|
50
50
|
mutationFn: ({ sessionId, breakData }) => {
|
|
51
51
|
return this.post(`/session/${sessionId}/break`, JSON.stringify(breakData), undefined, {
|
|
@@ -88,7 +88,7 @@ AvroQueryClient.prototype.useCreateSessionBreak = function () {
|
|
|
88
88
|
});
|
|
89
89
|
};
|
|
90
90
|
AvroQueryClient.prototype.useUpdateUserSession = function () {
|
|
91
|
-
const queryClient =
|
|
91
|
+
const queryClient = this.getQueryClient();
|
|
92
92
|
return useMutation({
|
|
93
93
|
mutationFn: ({ sessionId, updates }) => {
|
|
94
94
|
return this.put(`/session/${sessionId}`, JSON.stringify(updates), undefined, {
|
|
@@ -119,7 +119,7 @@ AvroQueryClient.prototype.useUpdateUserSession = function () {
|
|
|
119
119
|
});
|
|
120
120
|
};
|
|
121
121
|
AvroQueryClient.prototype.useUpdateSessionBreak = function () {
|
|
122
|
-
const queryClient =
|
|
122
|
+
const queryClient = this.getQueryClient();
|
|
123
123
|
return useMutation({
|
|
124
124
|
mutationFn: ({ breakId, updates }) => {
|
|
125
125
|
return this.put(`/break/${breakId}`, JSON.stringify(updates), undefined, {
|
|
@@ -153,7 +153,7 @@ AvroQueryClient.prototype.useUpdateSessionBreak = function () {
|
|
|
153
153
|
});
|
|
154
154
|
};
|
|
155
155
|
AvroQueryClient.prototype.useGetSessions = function (body) {
|
|
156
|
-
const queryClient =
|
|
156
|
+
const queryClient = this.getQueryClient();
|
|
157
157
|
const result = useInfiniteQuery({
|
|
158
158
|
queryKey: ['sessions', this.companyId, body.amt ?? 50, body.query ?? ""],
|
|
159
159
|
initialPageParam: 0,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { useMutation, useQuery
|
|
1
|
+
import { useMutation, useQuery } from "@tanstack/react-query";
|
|
2
2
|
import { AvroQueryClient } from "../../client/QueryClient";
|
|
3
3
|
AvroQueryClient.prototype.useGetTeams = function (body, total, onProgress) {
|
|
4
4
|
return useQuery({
|
|
5
|
-
queryKey: ['teams', this.companyId, body.amt ?? 50, body.query ?? ""],
|
|
5
|
+
queryKey: ['teams', this.companyId, body.amt ?? 50, body.query ?? "", total ?? "all"],
|
|
6
6
|
queryFn: async () => {
|
|
7
7
|
if (typeof total !== "number") {
|
|
8
8
|
return this.fetchTeams({ ...body, offset: 0 });
|
|
@@ -27,7 +27,7 @@ AvroQueryClient.prototype.useGetTeams = function (body, total, onProgress) {
|
|
|
27
27
|
});
|
|
28
28
|
};
|
|
29
29
|
AvroQueryClient.prototype.useCreateTeam = function () {
|
|
30
|
-
const queryClient =
|
|
30
|
+
const queryClient = this.getQueryClient();
|
|
31
31
|
return useMutation({
|
|
32
32
|
mutationFn: async ({ teamData }) => {
|
|
33
33
|
return this.post(`/company/${this.companyId}/team`, JSON.stringify(teamData), undefined, { "Content-Type": "application/json" });
|
|
@@ -38,7 +38,7 @@ AvroQueryClient.prototype.useCreateTeam = function () {
|
|
|
38
38
|
});
|
|
39
39
|
};
|
|
40
40
|
AvroQueryClient.prototype.useUpdateTeam = function () {
|
|
41
|
-
const queryClient =
|
|
41
|
+
const queryClient = this.getQueryClient();
|
|
42
42
|
return useMutation({
|
|
43
43
|
mutationFn: async ({ teamId, teamData }) => {
|
|
44
44
|
return this.put(`/team/${teamId}`, JSON.stringify(teamData), undefined, { "Content-Type": "application/json" });
|
|
@@ -84,7 +84,7 @@ AvroQueryClient.prototype.useUpdateTeam = function () {
|
|
|
84
84
|
});
|
|
85
85
|
};
|
|
86
86
|
AvroQueryClient.prototype.useDeleteTeam = function () {
|
|
87
|
-
const queryClient =
|
|
87
|
+
const queryClient = this.getQueryClient();
|
|
88
88
|
return useMutation({
|
|
89
89
|
mutationFn: async ({ teamId, }) => {
|
|
90
90
|
return this.delete(`/team/${teamId}`);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useMutation, useQuery
|
|
1
|
+
import { useMutation, useQuery } from "@tanstack/react-query";
|
|
2
2
|
import { AvroQueryClient } from "../../client/QueryClient";
|
|
3
3
|
AvroQueryClient.prototype.useGetUser = function (userId) {
|
|
4
4
|
return useQuery({
|
|
@@ -26,7 +26,7 @@ AvroQueryClient.prototype.useGetSelf = function () {
|
|
|
26
26
|
});
|
|
27
27
|
};
|
|
28
28
|
AvroQueryClient.prototype.useCreateSelf = function () {
|
|
29
|
-
const queryClient =
|
|
29
|
+
const queryClient = this.getQueryClient();
|
|
30
30
|
return useMutation({
|
|
31
31
|
mutationFn: async (data) => {
|
|
32
32
|
return this.post('/user', JSON.stringify(data), undefined, { "Content-Type": "application/json" });
|
|
@@ -37,7 +37,7 @@ AvroQueryClient.prototype.useCreateSelf = function () {
|
|
|
37
37
|
});
|
|
38
38
|
};
|
|
39
39
|
AvroQueryClient.prototype.useUpdateUserCompany = function () {
|
|
40
|
-
const queryClient =
|
|
40
|
+
const queryClient = this.getQueryClient();
|
|
41
41
|
return useMutation({
|
|
42
42
|
mutationFn: async ({ user_id, data }) => {
|
|
43
43
|
return this.put(`/company/${this.companyId}/user/${user_id}`, JSON.stringify(data), undefined, { "Content-Type": "application/json" });
|
|
@@ -81,7 +81,7 @@ AvroQueryClient.prototype.useUpdateUserCompany = function () {
|
|
|
81
81
|
});
|
|
82
82
|
};
|
|
83
83
|
AvroQueryClient.prototype.useDeleteSelf = function () {
|
|
84
|
-
const queryClient =
|
|
84
|
+
const queryClient = this.getQueryClient();
|
|
85
85
|
return useMutation({
|
|
86
86
|
mutationFn: async () => {
|
|
87
87
|
return this.delete(`/user`);
|