@go-avro/avro-js 0.0.2-beta.96 → 0.0.2-beta.98
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.
|
@@ -133,6 +133,12 @@ declare module '../client/QueryClient' {
|
|
|
133
133
|
companyId: string;
|
|
134
134
|
jobData: Partial<Job>;
|
|
135
135
|
}>>;
|
|
136
|
+
useCreateRoute(): ReturnType<typeof useMutation<{
|
|
137
|
+
id: string;
|
|
138
|
+
}, StandardError, {
|
|
139
|
+
companyId: string;
|
|
140
|
+
routeData: Partial<Route>;
|
|
141
|
+
}>>;
|
|
136
142
|
useCreateSelf(): ReturnType<typeof useMutation<{
|
|
137
143
|
msg: string;
|
|
138
144
|
}, StandardError, {
|
|
@@ -179,7 +179,9 @@ AvroQueryClient.prototype.useDeleteJob = function () {
|
|
|
179
179
|
onSettled: (_data, _error, variables) => {
|
|
180
180
|
const { jobId } = variables;
|
|
181
181
|
queryClient.invalidateQueries({ queryKey: ['jobs'] });
|
|
182
|
+
queryClient.invalidateQueries({ queryKey: ['routes'] });
|
|
182
183
|
queryClient.invalidateQueries({ queryKey: ['job', jobId] });
|
|
184
|
+
queryClient.invalidateQueries({ queryKey: ['route'] });
|
|
183
185
|
},
|
|
184
186
|
});
|
|
185
187
|
};
|
|
@@ -35,6 +35,47 @@ AvroQueryClient.prototype.useGetRoute = function (routeId) {
|
|
|
35
35
|
enabled: Boolean(routeId) && routeId.length > 0,
|
|
36
36
|
});
|
|
37
37
|
};
|
|
38
|
+
AvroQueryClient.prototype.useCreateRoute = function () {
|
|
39
|
+
const queryClient = useQueryClient();
|
|
40
|
+
return useMutation({
|
|
41
|
+
mutationFn: async ({ companyId, routeData }) => {
|
|
42
|
+
return this.post(`/company/${companyId}/route`, JSON.stringify(routeData), undefined, { "Content-Type": "application/json" });
|
|
43
|
+
},
|
|
44
|
+
onMutate: async ({ companyId, routeData }) => {
|
|
45
|
+
await queryClient.cancelQueries({ queryKey: ['routes'] });
|
|
46
|
+
const previousRoutes = queryClient.getQueryData(['routes']);
|
|
47
|
+
queryClient.setQueriesData({ queryKey: ['routes'] }, (oldData) => {
|
|
48
|
+
if (!oldData)
|
|
49
|
+
return oldData;
|
|
50
|
+
if (oldData.pages) {
|
|
51
|
+
return {
|
|
52
|
+
...oldData,
|
|
53
|
+
pages: [
|
|
54
|
+
[{ ...routeData, id: 'temp-id' }],
|
|
55
|
+
...oldData.pages,
|
|
56
|
+
],
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
if (Array.isArray(oldData)) {
|
|
60
|
+
return [{ ...routeData, id: 'temp-id' }, ...oldData];
|
|
61
|
+
}
|
|
62
|
+
return oldData;
|
|
63
|
+
});
|
|
64
|
+
return { previousRoutes };
|
|
65
|
+
},
|
|
66
|
+
onError: (_err, _variables, context) => {
|
|
67
|
+
if (context?.previousRoutes) {
|
|
68
|
+
queryClient.setQueryData(['routes'], context.previousRoutes);
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
onSettled: (_data, _error, variables) => {
|
|
72
|
+
const { companyId } = variables;
|
|
73
|
+
queryClient.invalidateQueries({ queryKey: ['routes'] });
|
|
74
|
+
queryClient.invalidateQueries({ queryKey: ['jobs'] });
|
|
75
|
+
queryClient.invalidateQueries({ queryKey: ['company', companyId] });
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
};
|
|
38
79
|
AvroQueryClient.prototype.useUpdateRoute = function () {
|
|
39
80
|
const queryClient = useQueryClient();
|
|
40
81
|
return useMutation({
|
|
@@ -117,7 +158,9 @@ AvroQueryClient.prototype.useDeleteRoute = function () {
|
|
|
117
158
|
onSettled: (_data, _error, variables) => {
|
|
118
159
|
const { routeId } = variables;
|
|
119
160
|
queryClient.invalidateQueries({ queryKey: ['routes'] });
|
|
161
|
+
queryClient.invalidateQueries({ queryKey: ['jobs'] });
|
|
120
162
|
queryClient.invalidateQueries({ queryKey: ['route', routeId] });
|
|
163
|
+
queryClient.invalidateQueries({ queryKey: ['job'] });
|
|
121
164
|
},
|
|
122
165
|
});
|
|
123
166
|
};
|
package/dist/types/api.d.ts
CHANGED