@go-avro/avro-js 0.0.2-beta.163 → 0.0.2-beta.165

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.
@@ -205,6 +205,9 @@ declare module '../client/QueryClient' {
205
205
  sessionId: string;
206
206
  breakData: Partial<Break>;
207
207
  }>>;
208
+ useManageJobs(): ReturnType<typeof useMutation<void, StandardError, {
209
+ jobs: Partial<Job>[];
210
+ }>>;
208
211
  useScheduleRoutes(): ReturnType<typeof useMutation<{
209
212
  msg: string;
210
213
  }, StandardError, {
@@ -296,6 +299,11 @@ declare module '../client/QueryClient' {
296
299
  useUpdateSelf(): ReturnType<typeof useMutation<{
297
300
  msg: string;
298
301
  }, StandardError, Partial<User>>>;
302
+ useDeleteJobs(): ReturnType<typeof useMutation<{
303
+ msg: string;
304
+ }, StandardError, {
305
+ ids: string[];
306
+ }>>;
299
307
  useDeleteJob(): ReturnType<typeof useMutation<{
300
308
  msg: string;
301
309
  }, StandardError, {
@@ -119,6 +119,49 @@ AvroQueryClient.prototype.useCreateJob = function () {
119
119
  },
120
120
  });
121
121
  };
122
+ AvroQueryClient.prototype.useManageJobs = function () {
123
+ const queryClient = this.getQueryClient();
124
+ return useMutation({
125
+ mutationFn: ({ jobs }) => {
126
+ return this.post(`/company/${this.companyId}/jobs/manage`, JSON.stringify({ jobs }), undefined, {
127
+ "Content-Type": "application/json",
128
+ });
129
+ },
130
+ onMutate: async ({ jobs }) => {
131
+ await queryClient.cancelQueries({ queryKey: ['jobs'] });
132
+ const previousJobs = queryClient.getQueryData(['jobs']);
133
+ queryClient.setQueryData(['jobs'], (oldData) => {
134
+ if (!oldData)
135
+ return oldData;
136
+ if (oldData.pages) {
137
+ return {
138
+ ...oldData,
139
+ pages: oldData.pages.map((page) => page.map((job) => {
140
+ const updatedJob = jobs.find((j) => j.id === job.id);
141
+ return updatedJob ? { ...job, ...updatedJob } : job;
142
+ })),
143
+ };
144
+ }
145
+ if (Array.isArray(oldData)) {
146
+ return oldData.map((job) => {
147
+ const updatedJob = jobs.find((j) => j.id === job.id);
148
+ return updatedJob ? { ...job, ...updatedJob } : job;
149
+ });
150
+ }
151
+ return oldData;
152
+ });
153
+ return { previousJobs };
154
+ },
155
+ onError: (err, variables, context) => {
156
+ if (context?.previousJobs) {
157
+ queryClient.setQueryData(['jobs'], context.previousJobs);
158
+ }
159
+ },
160
+ onSettled: (_data, _error, _variables) => {
161
+ queryClient.invalidateQueries({ queryKey: ['jobs'] });
162
+ },
163
+ });
164
+ };
122
165
  AvroQueryClient.prototype.useUpdateJob = function () {
123
166
  const queryClient = this.getQueryClient();
124
167
  return useMutation({
@@ -165,6 +208,44 @@ AvroQueryClient.prototype.useUpdateJob = function () {
165
208
  },
166
209
  });
167
210
  };
211
+ AvroQueryClient.prototype.useDeleteJobs = function () {
212
+ const queryClient = this.getQueryClient();
213
+ return useMutation({
214
+ mutationFn: ({ ids }) => {
215
+ return this.post(`/company/${this.companyId}/jobs/delete`, JSON.stringify({ ids }), undefined, {
216
+ "Content-Type": "application/json",
217
+ });
218
+ },
219
+ onMutate: async ({ ids }) => {
220
+ await queryClient.cancelQueries({ queryKey: ['jobs'] });
221
+ const previousJobs = queryClient.getQueryData(['jobs']);
222
+ queryClient.setQueryData(['jobs'], (oldData) => {
223
+ if (!oldData)
224
+ return oldData;
225
+ if (oldData.pages) {
226
+ const updatedPages = oldData.pages.map((page) => page.filter((job) => !ids.includes(job.id)));
227
+ return { ...oldData, pages: updatedPages };
228
+ }
229
+ if (Array.isArray(oldData)) {
230
+ return oldData.filter((job) => !ids.includes(job.id));
231
+ }
232
+ return oldData;
233
+ });
234
+ return { previousJobs };
235
+ },
236
+ onError: (_err, variables, context) => {
237
+ if (context?.previousJobs) {
238
+ queryClient.setQueryData(['jobs'], context.previousJobs);
239
+ }
240
+ },
241
+ onSettled: (_data, _error, _variables) => {
242
+ queryClient.invalidateQueries({ queryKey: ['jobs'] });
243
+ queryClient.invalidateQueries({ queryKey: ['routes'] });
244
+ queryClient.invalidateQueries({ queryKey: ['job'] });
245
+ queryClient.invalidateQueries({ queryKey: ['route'] });
246
+ },
247
+ });
248
+ };
168
249
  AvroQueryClient.prototype.useDeleteJob = function () {
169
250
  const queryClient = this.getQueryClient();
170
251
  return useMutation({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@go-avro/avro-js",
3
- "version": "0.0.2-beta.163",
3
+ "version": "0.0.2-beta.165",
4
4
  "description": "JS client for Avro backend integration.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",