@go-avro/avro-js 0.0.4-beta.8 → 0.0.5
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/auth/AuthManager.d.ts +2 -2
- package/dist/client/QueryClient.d.ts +67 -3
- package/dist/client/QueryClient.js +28 -1
- package/dist/client/core/fetch.js +5 -0
- package/dist/client/core/xhr.js +12 -0
- package/dist/client/hooks/bills.js +8 -0
- package/dist/client/hooks/catalog_items.js +8 -1
- package/dist/client/hooks/events.js +14 -17
- package/dist/client/hooks/jobs.js +7 -3
- package/dist/client/hooks/prepayments.js +60 -1
- package/dist/client/hooks/proposal.js +8 -1
- package/dist/client/hooks/routes.js +13 -8
- package/dist/client/hooks/users.js +11 -0
- package/dist/client/hooks/waivers.d.ts +1 -0
- package/dist/client/hooks/waivers.js +123 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/types/api/Job.d.ts +31 -24
- package/dist/types/api/Job.js +23 -1
- package/dist/types/api/LineItem.d.ts +1 -0
- package/dist/types/api/LineItem.js +2 -1
- package/dist/types/api/Prepayment.d.ts +13 -8
- package/dist/types/api/Prepayment.js +7 -1
- package/dist/types/api/Route.d.ts +35 -17
- package/dist/types/api/Route.js +82 -1
- package/dist/types/api/RouteJob.d.ts +14 -9
- package/dist/types/api/RouteJob.js +5 -1
- package/dist/types/api/ServiceMonth.d.ts +1 -0
- package/dist/types/api/Task.d.ts +7 -0
- package/dist/types/api/Task.js +37 -1
- package/dist/types/api/User.d.ts +3 -1
- package/dist/types/api/UserCompanyAssociation.d.ts +1 -0
- package/dist/types/api/Waiver.d.ts +9 -0
- package/dist/types/api/Waiver.js +1 -0
- package/dist/types/api/_Event.d.ts +22 -15
- package/dist/types/api/_Event.js +18 -1
- package/dist/types/api.d.ts +3 -0
- package/dist/types/api.js +1 -0
- package/dist/types/cache.d.ts +2 -2
- package/package.json +1 -1
|
@@ -16,8 +16,8 @@ export declare class AuthManager {
|
|
|
16
16
|
onTokenRefreshFailed(callback: () => void): void;
|
|
17
17
|
refreshTokens(): Promise<Tokens>;
|
|
18
18
|
setTokens(tokens: Tokens): Promise<void>;
|
|
19
|
-
setCache(data: Partial<CacheData>): Promise<void>;
|
|
20
|
-
getCache(key?: keyof CacheData): Promise<CacheData | string | null>;
|
|
19
|
+
setCache(data: Partial<CacheData> | Object): Promise<void>;
|
|
20
|
+
getCache(key?: keyof CacheData | string): Promise<CacheData[keyof CacheData] | Object | string | null>;
|
|
21
21
|
clearCache(): Promise<void>;
|
|
22
22
|
getCompanyId(): Promise<string | undefined>;
|
|
23
23
|
setCompanyId(companyId: string): Promise<void[]>;
|
|
@@ -6,6 +6,7 @@ import { AuthState, Tokens } from '../types/auth';
|
|
|
6
6
|
import { CancelToken, RetryStrategy } from '../types/client';
|
|
7
7
|
import { StandardError } from '../types/error';
|
|
8
8
|
import { CacheData } from '../types/cache';
|
|
9
|
+
import { Waiver } from '../types/api/Waiver';
|
|
9
10
|
export interface AvroQueryClientConfig {
|
|
10
11
|
baseUrl: string;
|
|
11
12
|
authManager: AuthManager;
|
|
@@ -106,6 +107,13 @@ declare module '../client/QueryClient' {
|
|
|
106
107
|
query?: string;
|
|
107
108
|
offset?: number;
|
|
108
109
|
}, total: number, onProgress?: (fraction: number) => void): UseQueryResult<Label[], StandardError>;
|
|
110
|
+
useGetWaivers(body: {
|
|
111
|
+
amt?: number;
|
|
112
|
+
known_ids?: string[];
|
|
113
|
+
unknown_ids?: string[];
|
|
114
|
+
query?: string;
|
|
115
|
+
offset?: number;
|
|
116
|
+
}, total: number, onProgress?: (fraction: number) => void): UseQueryResult<Waiver[], StandardError>;
|
|
109
117
|
useGetGroups(body: {
|
|
110
118
|
amt?: number;
|
|
111
119
|
known_ids?: string[];
|
|
@@ -115,6 +123,16 @@ declare module '../client/QueryClient' {
|
|
|
115
123
|
}, total: number, onProgress?: (fraction: number) => void): UseQueryResult<Group[], StandardError>;
|
|
116
124
|
useGetPlans(code: string): UseQueryResult<Plan[], StandardError>;
|
|
117
125
|
useGetCompanies(options?: {}): UseQueryResult<Company[], StandardError>;
|
|
126
|
+
generatePDFFromBackend({ billId }: {
|
|
127
|
+
billId: string;
|
|
128
|
+
}): Promise<Blob>;
|
|
129
|
+
sendBillingEmail(options: {
|
|
130
|
+
billId: string;
|
|
131
|
+
subject?: string;
|
|
132
|
+
recipients?: string[][];
|
|
133
|
+
}): Promise<{
|
|
134
|
+
msg: string;
|
|
135
|
+
}>;
|
|
118
136
|
useGetProposal(proposal_id: string): UseQueryResult<any, StandardError>;
|
|
119
137
|
useGetAnalytics(): UseQueryResult<any, StandardError>;
|
|
120
138
|
useFinanceAnalytics({ periods, cumulative }: {
|
|
@@ -143,6 +161,7 @@ declare module '../client/QueryClient' {
|
|
|
143
161
|
tasks: {
|
|
144
162
|
id: string;
|
|
145
163
|
status: string;
|
|
164
|
+
payment_option_id: string;
|
|
146
165
|
}[];
|
|
147
166
|
}>>;
|
|
148
167
|
useCreateProposal(): ReturnType<typeof useMutation<{
|
|
@@ -156,6 +175,11 @@ declare module '../client/QueryClient' {
|
|
|
156
175
|
}, StandardError, {
|
|
157
176
|
groupData: Partial<Group>;
|
|
158
177
|
}>>;
|
|
178
|
+
useCreateWaiver(): ReturnType<typeof useMutation<{
|
|
179
|
+
id: string;
|
|
180
|
+
}, StandardError, {
|
|
181
|
+
waiverData: Partial<Waiver>;
|
|
182
|
+
}>>;
|
|
159
183
|
useCreateLabel(): ReturnType<typeof useMutation<{
|
|
160
184
|
id: string;
|
|
161
185
|
}, StandardError, {
|
|
@@ -221,6 +245,17 @@ declare module '../client/QueryClient' {
|
|
|
221
245
|
password?: string;
|
|
222
246
|
company_id?: string;
|
|
223
247
|
}>>;
|
|
248
|
+
useCreateUser(): ReturnType<typeof useMutation<{
|
|
249
|
+
msg: string;
|
|
250
|
+
id?: string;
|
|
251
|
+
access_token?: string;
|
|
252
|
+
refresh_token?: string;
|
|
253
|
+
}, StandardError, Partial<User> & {
|
|
254
|
+
code?: string;
|
|
255
|
+
invite_token?: string;
|
|
256
|
+
password?: string;
|
|
257
|
+
company_id?: string;
|
|
258
|
+
}>>;
|
|
224
259
|
useCreateSessionBreak(): ReturnType<typeof useMutation<{
|
|
225
260
|
id: string;
|
|
226
261
|
}, StandardError, {
|
|
@@ -264,6 +299,12 @@ declare module '../client/QueryClient' {
|
|
|
264
299
|
labelId: string;
|
|
265
300
|
labelData: Partial<Label>;
|
|
266
301
|
}>>;
|
|
302
|
+
useUpdateWaiver(): ReturnType<typeof useMutation<{
|
|
303
|
+
msg: string;
|
|
304
|
+
}, StandardError, {
|
|
305
|
+
waiverId: string;
|
|
306
|
+
updates: Partial<Waiver>;
|
|
307
|
+
}>>;
|
|
267
308
|
useUpdateCatalogItem(): ReturnType<typeof useMutation<{
|
|
268
309
|
msg: string;
|
|
269
310
|
}, StandardError, {
|
|
@@ -312,6 +353,12 @@ declare module '../client/QueryClient' {
|
|
|
312
353
|
})[];
|
|
313
354
|
action: "billed" | "paid";
|
|
314
355
|
}>>;
|
|
356
|
+
useUpdatePrepayments(): ReturnType<typeof useMutation<void, StandardError, {
|
|
357
|
+
prepayments: (Prepayment & {
|
|
358
|
+
page?: number;
|
|
359
|
+
})[];
|
|
360
|
+
action: "billed" | "paid";
|
|
361
|
+
}>>;
|
|
315
362
|
useUpdateUserCompany(): ReturnType<typeof useMutation<{
|
|
316
363
|
msg: string;
|
|
317
364
|
}, StandardError, {
|
|
@@ -366,6 +413,11 @@ declare module '../client/QueryClient' {
|
|
|
366
413
|
}, StandardError, {
|
|
367
414
|
groupId: string;
|
|
368
415
|
}>>;
|
|
416
|
+
useDeleteWaiver(): ReturnType<typeof useMutation<{
|
|
417
|
+
msg: string;
|
|
418
|
+
}, StandardError, {
|
|
419
|
+
waiverId: string;
|
|
420
|
+
}>>;
|
|
369
421
|
useDeleteLabel(): ReturnType<typeof useMutation<{
|
|
370
422
|
msg: string;
|
|
371
423
|
}, StandardError, {
|
|
@@ -447,8 +499,8 @@ export declare class AvroQueryClient {
|
|
|
447
499
|
cancelToken?: CancelToken;
|
|
448
500
|
}>>;
|
|
449
501
|
setTokens(tokens: Tokens): Promise<void>;
|
|
450
|
-
setCache(data: Partial<CacheData>): Promise<void>;
|
|
451
|
-
getCache(key?: keyof CacheData |
|
|
502
|
+
setCache(data: Partial<CacheData> | Object): Promise<void>;
|
|
503
|
+
getCache(key?: keyof CacheData | string): Promise<CacheData[keyof CacheData] | Object | string | null>;
|
|
452
504
|
setCompanyId(companyId: string): Promise<void[]>;
|
|
453
505
|
getCompanyId(): Promise<string | undefined>;
|
|
454
506
|
clearCache(): Promise<void>;
|
|
@@ -492,6 +544,13 @@ export declare class AvroQueryClient {
|
|
|
492
544
|
paid?: boolean;
|
|
493
545
|
taskId?: string | null;
|
|
494
546
|
}, cancelToken?: CancelToken, headers?: Record<string, string>): Promise<any>;
|
|
547
|
+
fetchWaivers(body?: {
|
|
548
|
+
amt?: number;
|
|
549
|
+
query?: string;
|
|
550
|
+
offset?: number;
|
|
551
|
+
known_ids?: string[];
|
|
552
|
+
unknown_ids?: string[];
|
|
553
|
+
}, cancelToken?: CancelToken, headers?: Record<string, string>): Promise<any>;
|
|
495
554
|
fetchEvents(body?: {
|
|
496
555
|
amt?: number;
|
|
497
556
|
known_ids?: string[];
|
|
@@ -501,7 +560,7 @@ export declare class AvroQueryClient {
|
|
|
501
560
|
unbilled?: boolean;
|
|
502
561
|
billed?: boolean;
|
|
503
562
|
paid?: boolean;
|
|
504
|
-
|
|
563
|
+
job_id?: string | null;
|
|
505
564
|
}, cancelToken?: CancelToken, headers?: Record<string, string>): Promise<any>;
|
|
506
565
|
fetchMonths(body?: {
|
|
507
566
|
amt?: number;
|
|
@@ -563,4 +622,9 @@ export declare class AvroQueryClient {
|
|
|
563
622
|
offset?: number;
|
|
564
623
|
}, cancelToken?: CancelToken, headers?: Record<string, string>): Promise<any>;
|
|
565
624
|
sendEmail(emailId: string, formData: FormData, progressUpdateCallback?: (loaded: number, total: number) => void): Promise<void>;
|
|
625
|
+
sendBillEmail(billId: string, body?: {
|
|
626
|
+
subject?: string;
|
|
627
|
+
recipients?: string[][];
|
|
628
|
+
base_url?: string;
|
|
629
|
+
}): Promise<void>;
|
|
566
630
|
}
|
|
@@ -176,7 +176,7 @@ export class AvroQueryClient {
|
|
|
176
176
|
setCache(data) {
|
|
177
177
|
return this.config.authManager.setCache(data);
|
|
178
178
|
}
|
|
179
|
-
getCache(key) {
|
|
179
|
+
async getCache(key) {
|
|
180
180
|
return this.config.authManager.getCache(key);
|
|
181
181
|
}
|
|
182
182
|
setCompanyId(companyId) {
|
|
@@ -318,6 +318,25 @@ export class AvroQueryClient {
|
|
|
318
318
|
throw new StandardError(500, 'Failed to fetch prepayments');
|
|
319
319
|
});
|
|
320
320
|
}
|
|
321
|
+
async fetchWaivers(body = {}, cancelToken, headers = {}) {
|
|
322
|
+
if (!this.companyId || this.companyId.trim() === '') {
|
|
323
|
+
throw new StandardError(400, 'Company ID is required');
|
|
324
|
+
}
|
|
325
|
+
return this._fetch('POST', `/company/${this.companyId}/waivers`, JSON.stringify(body), cancelToken, {
|
|
326
|
+
...headers,
|
|
327
|
+
'Content-Type': 'application/json',
|
|
328
|
+
})
|
|
329
|
+
.then(response => {
|
|
330
|
+
if (!response || !Array.isArray(response)) {
|
|
331
|
+
throw new StandardError(400, 'Invalid waivers response');
|
|
332
|
+
}
|
|
333
|
+
return response;
|
|
334
|
+
})
|
|
335
|
+
.catch(err => {
|
|
336
|
+
console.error('Failed to fetch waivers:', err);
|
|
337
|
+
throw new StandardError(500, 'Failed to fetch waivers');
|
|
338
|
+
});
|
|
339
|
+
}
|
|
321
340
|
async fetchEvents(body = {}, cancelToken, headers = {}) {
|
|
322
341
|
if (!this.companyId || this.companyId.trim() === '') {
|
|
323
342
|
throw new StandardError(400, 'Company ID is required');
|
|
@@ -497,4 +516,12 @@ export class AvroQueryClient {
|
|
|
497
516
|
throw new StandardError(500, `Failed to send email: ${error}`);
|
|
498
517
|
}
|
|
499
518
|
}
|
|
519
|
+
sendBillEmail(billId, body = {}) {
|
|
520
|
+
try {
|
|
521
|
+
return this.post(`/bill/${billId}/email`, JSON.stringify(body), undefined, { 'Content-Type': 'application/json' });
|
|
522
|
+
}
|
|
523
|
+
catch (error) {
|
|
524
|
+
throw new StandardError(500, `Failed to send bill email: ${error}`);
|
|
525
|
+
}
|
|
526
|
+
}
|
|
500
527
|
}
|
|
@@ -28,6 +28,11 @@ AvroQueryClient.prototype._fetch = async function (method, path, body, cancelTok
|
|
|
28
28
|
};
|
|
29
29
|
const response = await fetch(url, options);
|
|
30
30
|
if (response.ok) {
|
|
31
|
+
const contentType = response.headers.get('content-type') ?? '';
|
|
32
|
+
if (contentType.includes('application/pdf') ||
|
|
33
|
+
contentType.includes('application/octet-stream')) {
|
|
34
|
+
return response.blob();
|
|
35
|
+
}
|
|
31
36
|
const text = await response.text();
|
|
32
37
|
if (!text) {
|
|
33
38
|
return undefined;
|
package/dist/client/core/xhr.js
CHANGED
|
@@ -22,6 +22,12 @@ AvroQueryClient.prototype._xhr = async function (method, path, body, cancelToken
|
|
|
22
22
|
xhr.onload = () => {
|
|
23
23
|
if (xhr.status >= 200 && xhr.status < 300) {
|
|
24
24
|
try {
|
|
25
|
+
const contentType = xhr.getResponseHeader('content-type') || '';
|
|
26
|
+
if (contentType.includes('application/pdf') ||
|
|
27
|
+
contentType.includes('application/octet-stream')) {
|
|
28
|
+
resolve(new Blob([xhr.response], { type: contentType }));
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
25
31
|
const responseText = xhr.responseText;
|
|
26
32
|
if (!responseText) {
|
|
27
33
|
return resolve(undefined);
|
|
@@ -56,6 +62,12 @@ AvroQueryClient.prototype._xhr = async function (method, path, body, cancelToken
|
|
|
56
62
|
}
|
|
57
63
|
};
|
|
58
64
|
}
|
|
65
|
+
// Set responseType to 'blob' if expecting binary
|
|
66
|
+
const contentType = headers['Content-Type'] || '';
|
|
67
|
+
if (contentType.includes('application/pdf') ||
|
|
68
|
+
contentType.includes('application/octet-stream')) {
|
|
69
|
+
xhr.responseType = 'blob';
|
|
70
|
+
}
|
|
59
71
|
xhr.send(body);
|
|
60
72
|
});
|
|
61
73
|
return result;
|
|
@@ -165,3 +165,11 @@ AvroQueryClient.prototype.useSyncBillToIntuit = function () {
|
|
|
165
165
|
},
|
|
166
166
|
});
|
|
167
167
|
};
|
|
168
|
+
AvroQueryClient.prototype.generatePDFFromBackend = function ({ billId }) {
|
|
169
|
+
return this.get(`/company/${this.companyId}/bill/${billId}/pdf`).then((response) => {
|
|
170
|
+
return response;
|
|
171
|
+
});
|
|
172
|
+
};
|
|
173
|
+
AvroQueryClient.prototype.sendBillingEmail = async function ({ subject, billId, recipients, }) {
|
|
174
|
+
return this.post(`/bill/${billId}/email`, JSON.stringify({ recipients, subject }), undefined, { "Content-Type": "application/json" });
|
|
175
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useMutation } from '@tanstack/react-query';
|
|
1
|
+
import { useQuery, useMutation } from '@tanstack/react-query';
|
|
2
2
|
import { AvroQueryClient } from '../../client/QueryClient';
|
|
3
3
|
AvroQueryClient.prototype.useCreateCatalogItem = function () {
|
|
4
4
|
const queryClient = this.getQueryClient();
|
|
@@ -67,6 +67,13 @@ AvroQueryClient.prototype.useUpdateCatalogItem = function () {
|
|
|
67
67
|
},
|
|
68
68
|
});
|
|
69
69
|
};
|
|
70
|
+
AvroQueryClient.prototype.useGetCatalogItem = function (catalogItemId) {
|
|
71
|
+
return useQuery({
|
|
72
|
+
queryKey: ['catalog_item', catalogItemId],
|
|
73
|
+
queryFn: () => this.get(`/catalog_item/${catalogItemId}`),
|
|
74
|
+
enabled: Boolean(catalogItemId),
|
|
75
|
+
});
|
|
76
|
+
};
|
|
70
77
|
AvroQueryClient.prototype.useDeleteCatalogItem = function () {
|
|
71
78
|
const queryClient = this.getQueryClient();
|
|
72
79
|
return useMutation({
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useInfiniteQuery, useQuery, useMutation } from '@tanstack/react-query';
|
|
2
2
|
import { AvroQueryClient } from '../../client/QueryClient';
|
|
3
|
-
import { LineItemStatus } from '../../types/api';
|
|
3
|
+
import { _Event, LineItemStatus } from '../../types/api';
|
|
4
4
|
AvroQueryClient.prototype.useGetEvents = function (body) {
|
|
5
5
|
const queryClient = this.getQueryClient();
|
|
6
6
|
const result = useInfiniteQuery({
|
|
@@ -23,7 +23,7 @@ AvroQueryClient.prototype.useGetEvents = function (body) {
|
|
|
23
23
|
return undefined;
|
|
24
24
|
return allPages.flat().length; // next offset
|
|
25
25
|
},
|
|
26
|
-
queryFn: ({ pageParam = 0 }) => this.fetchEvents({ ...body, offset: pageParam }),
|
|
26
|
+
queryFn: ({ pageParam = 0 }) => this.fetchEvents({ ...body, job_id: body.jobId, offset: pageParam }).then((events) => events.map((event) => new _Event(event))),
|
|
27
27
|
enabled: body.enabled ?? true,
|
|
28
28
|
});
|
|
29
29
|
if (result.data) {
|
|
@@ -38,7 +38,7 @@ AvroQueryClient.prototype.useGetEvents = function (body) {
|
|
|
38
38
|
AvroQueryClient.prototype.useGetEvent = function (eventId) {
|
|
39
39
|
return useQuery({
|
|
40
40
|
queryKey: ['event', eventId],
|
|
41
|
-
queryFn: () => this.get(`/event/${eventId}`),
|
|
41
|
+
queryFn: () => this.get(`/event/${eventId}`).then((event) => new _Event(event)),
|
|
42
42
|
enabled: Boolean(eventId),
|
|
43
43
|
});
|
|
44
44
|
};
|
|
@@ -55,18 +55,23 @@ AvroQueryClient.prototype.useCreateEvent = function () {
|
|
|
55
55
|
const previousEvents = queryClient.getQueryData(['events']);
|
|
56
56
|
const previousJob = queryClient.getQueryData(['job', eventData.job_id]);
|
|
57
57
|
const previousJobs = queryClient.getQueryData(['jobs']);
|
|
58
|
+
const optimisticEvent = new _Event({
|
|
59
|
+
...eventData,
|
|
60
|
+
id: Math.random().toString(36).substring(2, 11),
|
|
61
|
+
company_id: this.companyId,
|
|
62
|
+
});
|
|
58
63
|
if (previousJob) {
|
|
59
64
|
const updatedJob = {
|
|
60
65
|
...previousJob,
|
|
61
|
-
current_event:
|
|
62
|
-
last_completed_event: (
|
|
66
|
+
current_event: optimisticEvent,
|
|
67
|
+
last_completed_event: (optimisticEvent.time_ended ?? -1) > -1 ? optimisticEvent : previousJob.last_completed_event,
|
|
63
68
|
};
|
|
64
69
|
updatedJob.tasks = previousJob.tasks.map((task) => {
|
|
65
70
|
if (eventData.tasks?.includes(task.id ?? "")) {
|
|
66
71
|
return {
|
|
67
72
|
...task,
|
|
68
|
-
current_event:
|
|
69
|
-
last_completed_event: (
|
|
73
|
+
current_event: optimisticEvent,
|
|
74
|
+
last_completed_event: (optimisticEvent.time_ended ?? -1) > -1 ? optimisticEvent : task.last_completed_event,
|
|
70
75
|
};
|
|
71
76
|
}
|
|
72
77
|
return task;
|
|
@@ -84,11 +89,7 @@ AvroQueryClient.prototype.useCreateEvent = function () {
|
|
|
84
89
|
...oldData,
|
|
85
90
|
pages: [
|
|
86
91
|
[
|
|
87
|
-
|
|
88
|
-
...eventData,
|
|
89
|
-
id: Math.random().toString(36).substring(2, 11),
|
|
90
|
-
company_id: this.companyId,
|
|
91
|
-
},
|
|
92
|
+
optimisticEvent,
|
|
92
93
|
...firstPage,
|
|
93
94
|
],
|
|
94
95
|
...oldData.pages.slice(1),
|
|
@@ -97,11 +98,7 @@ AvroQueryClient.prototype.useCreateEvent = function () {
|
|
|
97
98
|
}
|
|
98
99
|
if (Array.isArray(oldData)) {
|
|
99
100
|
return [
|
|
100
|
-
|
|
101
|
-
...eventData,
|
|
102
|
-
id: Math.random().toString(36).substring(2, 11),
|
|
103
|
-
company_id: this.companyId,
|
|
104
|
-
},
|
|
101
|
+
optimisticEvent,
|
|
105
102
|
...oldData,
|
|
106
103
|
];
|
|
107
104
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { useMutation, useQuery, useInfiniteQuery } from '@tanstack/react-query';
|
|
2
2
|
import { AvroQueryClient } from '../../client/QueryClient';
|
|
3
|
+
import { Job } from '../../types/api';
|
|
3
4
|
AvroQueryClient.prototype.getJobsFromCache = function (queryClient) {
|
|
4
5
|
if (!queryClient) {
|
|
5
6
|
queryClient = this.getQueryClient();
|
|
@@ -25,7 +26,7 @@ AvroQueryClient.prototype.useGetJobs = function (params) {
|
|
|
25
26
|
return result;
|
|
26
27
|
}));
|
|
27
28
|
const pages = await Promise.all(trackedPromises);
|
|
28
|
-
const jobs = pages.flat();
|
|
29
|
+
const jobs = pages.flat().map((job) => new Job(job));
|
|
29
30
|
jobs.forEach((job) => {
|
|
30
31
|
job.current_event = job.tasks.reduce((latest, task) => {
|
|
31
32
|
return task.current_event && (!latest || task.current_event.time_started > latest.time_started) ? task.current_event : latest;
|
|
@@ -58,7 +59,7 @@ AvroQueryClient.prototype.useGetInfiniteJobs = function (body, onProgress) {
|
|
|
58
59
|
...body,
|
|
59
60
|
route_id: body.routeId,
|
|
60
61
|
offset: pageParam,
|
|
61
|
-
});
|
|
62
|
+
}).then((jobs) => jobs.map((job) => new Job(job)));
|
|
62
63
|
},
|
|
63
64
|
});
|
|
64
65
|
if (result.data) {
|
|
@@ -76,7 +77,10 @@ AvroQueryClient.prototype.useGetInfiniteJobs = function (body, onProgress) {
|
|
|
76
77
|
AvroQueryClient.prototype.useGetJob = function (jobId) {
|
|
77
78
|
return useQuery({
|
|
78
79
|
queryKey: ['job', jobId],
|
|
79
|
-
queryFn: () =>
|
|
80
|
+
queryFn: async () => {
|
|
81
|
+
const job = await this.get(`/job/${jobId}`);
|
|
82
|
+
return new Job(job);
|
|
83
|
+
},
|
|
80
84
|
enabled: Boolean(jobId),
|
|
81
85
|
});
|
|
82
86
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { useInfiniteQuery } from '@tanstack/react-query';
|
|
1
|
+
import { useInfiniteQuery, useMutation } from '@tanstack/react-query';
|
|
2
2
|
import { AvroQueryClient } from '../../client/QueryClient';
|
|
3
|
+
import { LineItemStatus } from '../../types/api';
|
|
3
4
|
AvroQueryClient.prototype.useGetPrepayments = function (body) {
|
|
4
5
|
const queryClient = this.getQueryClient();
|
|
5
6
|
const result = useInfiniteQuery({
|
|
@@ -34,3 +35,61 @@ AvroQueryClient.prototype.useGetPrepayments = function (body) {
|
|
|
34
35
|
}
|
|
35
36
|
return result;
|
|
36
37
|
};
|
|
38
|
+
AvroQueryClient.prototype.useUpdatePrepayments = function () {
|
|
39
|
+
const queryClient = this.getQueryClient();
|
|
40
|
+
return useMutation({
|
|
41
|
+
mutationFn: async ({ prepayments, action, }) => {
|
|
42
|
+
const prepaymentIds = prepayments.map(prepayment => prepayment.id);
|
|
43
|
+
return this.put(`/company/${this.companyId}/prepayments`, JSON.stringify({
|
|
44
|
+
prepayments: prepaymentIds,
|
|
45
|
+
status: action === "billed" ? LineItemStatus.EXTERNALLY_BILLED : LineItemStatus.EXTERNALLY_PAID,
|
|
46
|
+
}), undefined, {
|
|
47
|
+
"Content-Type": "application/json",
|
|
48
|
+
});
|
|
49
|
+
},
|
|
50
|
+
onMutate: async ({ prepayments, action }) => {
|
|
51
|
+
await queryClient.cancelQueries({ queryKey: ['prepayments'] });
|
|
52
|
+
await queryClient.cancelQueries({ queryKey: ['prepayment'] });
|
|
53
|
+
const previousPrepayments = queryClient.getQueryData(['prepayments']);
|
|
54
|
+
const previousPrepaymentObjs = prepayments.map(prepayment => queryClient.getQueryData(['prepayment', prepayment.id]));
|
|
55
|
+
const prepaymentIds = prepayments.map(prepayment => prepayment.id);
|
|
56
|
+
prepaymentIds.forEach((prepaymentId, idx) => {
|
|
57
|
+
queryClient.setQueryData(['prepayment', prepaymentId], (oldData) => {
|
|
58
|
+
return oldData
|
|
59
|
+
? { ...oldData, status: action === "billed" ? LineItemStatus.EXTERNALLY_BILLED : LineItemStatus.EXTERNALLY_PAID }
|
|
60
|
+
: oldData;
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
queryClient.setQueriesData({ queryKey: ['prepayments'] }, (oldData) => {
|
|
64
|
+
if (!oldData)
|
|
65
|
+
return oldData;
|
|
66
|
+
if (oldData.pages) {
|
|
67
|
+
const updatedPages = oldData.pages.map((page) => page.map((prepayment) => prepaymentIds.includes(prepayment.id)
|
|
68
|
+
? { ...prepayment, status: action === "billed" ? LineItemStatus.EXTERNALLY_BILLED : LineItemStatus.EXTERNALLY_PAID }
|
|
69
|
+
: prepayment));
|
|
70
|
+
return { ...oldData, pages: updatedPages };
|
|
71
|
+
}
|
|
72
|
+
if (Array.isArray(oldData)) {
|
|
73
|
+
return oldData.map((prepayment) => prepaymentIds.includes(prepayment.id)
|
|
74
|
+
? { ...prepayment, status: action === "billed" ? LineItemStatus.EXTERNALLY_BILLED : LineItemStatus.EXTERNALLY_PAID }
|
|
75
|
+
: prepayment);
|
|
76
|
+
}
|
|
77
|
+
return oldData;
|
|
78
|
+
});
|
|
79
|
+
return { previousPrepayments, previousPrepaymentObjs };
|
|
80
|
+
},
|
|
81
|
+
onError: (err, variables, context) => {
|
|
82
|
+
if (context) {
|
|
83
|
+
queryClient.setQueryData(['prepayments'], context.previousPrepayments);
|
|
84
|
+
context.previousPrepaymentObjs.forEach((prepaymentObj) => {
|
|
85
|
+
queryClient.setQueryData(['prepayment', prepaymentObj.id], prepaymentObj);
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
onSettled: () => {
|
|
90
|
+
queryClient.invalidateQueries({ queryKey: ['prepayments'] });
|
|
91
|
+
queryClient.invalidateQueries({ queryKey: ['prepayment'] });
|
|
92
|
+
queryClient.invalidateQueries({ queryKey: ['company'] });
|
|
93
|
+
},
|
|
94
|
+
});
|
|
95
|
+
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { useMutation, useQuery } from "@tanstack/react-query";
|
|
2
2
|
import { AvroQueryClient } from "../../client/QueryClient";
|
|
3
|
+
import { Task } from "../../types/api/Task";
|
|
3
4
|
AvroQueryClient.prototype.useCreateProposal = function () {
|
|
4
5
|
return useMutation({
|
|
5
6
|
mutationFn: async ({ job_id, data }) => {
|
|
@@ -17,6 +18,12 @@ AvroQueryClient.prototype.useAcceptProposal = function (proposal_id) {
|
|
|
17
18
|
AvroQueryClient.prototype.useGetProposal = function (proposal_id) {
|
|
18
19
|
return useQuery({
|
|
19
20
|
queryKey: ['proposal', proposal_id],
|
|
20
|
-
queryFn: async () =>
|
|
21
|
+
queryFn: async () => {
|
|
22
|
+
const proposal = await this.get(`/proposal/${proposal_id}`);
|
|
23
|
+
if (proposal && Array.isArray(proposal.tasks)) {
|
|
24
|
+
proposal.tasks = proposal.tasks.map((task) => new Task(task));
|
|
25
|
+
}
|
|
26
|
+
return proposal;
|
|
27
|
+
},
|
|
21
28
|
});
|
|
22
29
|
};
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { useMutation, useQuery } from '@tanstack/react-query';
|
|
2
2
|
import { AvroQueryClient } from '../../client/QueryClient';
|
|
3
|
+
import { Route } from '../../types/api';
|
|
3
4
|
AvroQueryClient.prototype.useGetRoutes = function (body, total, onProgress) {
|
|
4
5
|
return useQuery({
|
|
5
6
|
queryKey: ['routes', this.companyId, body.amt ?? 50, body.query ?? "", total ?? "all"],
|
|
6
7
|
queryFn: async () => {
|
|
7
8
|
if (typeof total !== "number") {
|
|
8
|
-
|
|
9
|
+
const routes = await this.fetchRoutes({ ...body, offset: 0 });
|
|
10
|
+
return routes.map((route) => new Route(route));
|
|
9
11
|
}
|
|
10
12
|
onProgress?.(0);
|
|
11
13
|
const pageCount = body.amt ? Math.ceil(total / body.amt) + 1 : 1;
|
|
@@ -21,7 +23,7 @@ AvroQueryClient.prototype.useGetRoutes = function (body, total, onProgress) {
|
|
|
21
23
|
return result;
|
|
22
24
|
}));
|
|
23
25
|
const pages = await Promise.all(trackedPromises);
|
|
24
|
-
const routes = pages.flat();
|
|
26
|
+
const routes = pages.flat().map((route) => new Route(route));
|
|
25
27
|
return routes;
|
|
26
28
|
},
|
|
27
29
|
});
|
|
@@ -30,7 +32,10 @@ AvroQueryClient.prototype.useGetRoute = function (routeId) {
|
|
|
30
32
|
const queryClient = this.getQueryClient();
|
|
31
33
|
return useQuery({
|
|
32
34
|
queryKey: ['route', routeId],
|
|
33
|
-
queryFn: () =>
|
|
35
|
+
queryFn: async () => {
|
|
36
|
+
const route = await this.get(`/route/${routeId}`);
|
|
37
|
+
return new Route(route);
|
|
38
|
+
},
|
|
34
39
|
enabled: Boolean(routeId) && routeId.length > 0,
|
|
35
40
|
});
|
|
36
41
|
};
|
|
@@ -50,13 +55,13 @@ AvroQueryClient.prototype.useCreateRoute = function () {
|
|
|
50
55
|
return {
|
|
51
56
|
...oldData,
|
|
52
57
|
pages: [
|
|
53
|
-
[{ ...routeData, id: 'temp-id' }],
|
|
58
|
+
[new Route({ ...routeData, id: 'temp-id' })],
|
|
54
59
|
...oldData.pages,
|
|
55
60
|
],
|
|
56
61
|
};
|
|
57
62
|
}
|
|
58
63
|
if (Array.isArray(oldData)) {
|
|
59
|
-
return [{ ...routeData, id: 'temp-id' }, ...oldData];
|
|
64
|
+
return [new Route({ ...routeData, id: 'temp-id' }), ...oldData];
|
|
60
65
|
}
|
|
61
66
|
return oldData;
|
|
62
67
|
});
|
|
@@ -93,18 +98,18 @@ AvroQueryClient.prototype.useUpdateRoute = function () {
|
|
|
93
98
|
await queryClient.cancelQueries({ queryKey: ['routes'] });
|
|
94
99
|
const previousRoute = queryClient.getQueryData(['route', routeId]);
|
|
95
100
|
const previousRoutes = queryClient.getQueryData(['routes']);
|
|
96
|
-
queryClient.setQueryData(['route', routeId], (oldData) => oldData ? { ...oldData, ...updates } : undefined);
|
|
101
|
+
queryClient.setQueryData(['route', routeId], (oldData) => oldData ? new Route({ ...oldData, ...updates }) : undefined);
|
|
97
102
|
queryClient.setQueriesData({ queryKey: ['routes'] }, (oldData) => {
|
|
98
103
|
if (!oldData)
|
|
99
104
|
return oldData;
|
|
100
105
|
if (oldData.pages) {
|
|
101
106
|
return {
|
|
102
107
|
...oldData,
|
|
103
|
-
pages: oldData.pages.map((page) => page.map((route) => route.id === routeId ? { ...route, ...updates } : route)),
|
|
108
|
+
pages: oldData.pages.map((page) => page.map((route) => route.id === routeId ? new Route({ ...route, ...updates }) : route)),
|
|
104
109
|
};
|
|
105
110
|
}
|
|
106
111
|
if (Array.isArray(oldData)) {
|
|
107
|
-
return oldData.map((route) => route.id === routeId ? { ...route, ...updates } : route);
|
|
112
|
+
return oldData.map((route) => route.id === routeId ? new Route({ ...route, ...updates }) : route);
|
|
108
113
|
}
|
|
109
114
|
return oldData;
|
|
110
115
|
});
|
|
@@ -40,6 +40,17 @@ AvroQueryClient.prototype.useCreateSelf = function () {
|
|
|
40
40
|
},
|
|
41
41
|
});
|
|
42
42
|
};
|
|
43
|
+
AvroQueryClient.prototype.useCreateUser = function () {
|
|
44
|
+
const queryClient = this.getQueryClient();
|
|
45
|
+
return useMutation({
|
|
46
|
+
mutationFn: async (data) => {
|
|
47
|
+
return this.post('/user', JSON.stringify(data), undefined, { "Content-Type": "application/json" });
|
|
48
|
+
},
|
|
49
|
+
onSettled: (data) => {
|
|
50
|
+
queryClient.invalidateQueries({ queryKey: ['user'] });
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
};
|
|
43
54
|
AvroQueryClient.prototype.useUpdateSelf = function () {
|
|
44
55
|
const queryClient = this.getQueryClient();
|
|
45
56
|
return useMutation({
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|