@go-avro/avro-js 0.0.2-beta.164 → 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.
@@ -206,7 +206,6 @@ declare module '../client/QueryClient' {
206
206
  breakData: Partial<Break>;
207
207
  }>>;
208
208
  useManageJobs(): ReturnType<typeof useMutation<void, StandardError, {
209
- companyId: string;
210
209
  jobs: Partial<Job>[];
211
210
  }>>;
212
211
  useScheduleRoutes(): ReturnType<typeof useMutation<{
@@ -300,6 +299,11 @@ declare module '../client/QueryClient' {
300
299
  useUpdateSelf(): ReturnType<typeof useMutation<{
301
300
  msg: string;
302
301
  }, StandardError, Partial<User>>>;
302
+ useDeleteJobs(): ReturnType<typeof useMutation<{
303
+ msg: string;
304
+ }, StandardError, {
305
+ ids: string[];
306
+ }>>;
303
307
  useDeleteJob(): ReturnType<typeof useMutation<{
304
308
  msg: string;
305
309
  }, StandardError, {
@@ -122,12 +122,12 @@ AvroQueryClient.prototype.useCreateJob = function () {
122
122
  AvroQueryClient.prototype.useManageJobs = function () {
123
123
  const queryClient = this.getQueryClient();
124
124
  return useMutation({
125
- mutationFn: ({ companyId, jobs }) => {
126
- return this.post(`/company/${companyId}/jobs/manage`, JSON.stringify({ jobs }), undefined, {
125
+ mutationFn: ({ jobs }) => {
126
+ return this.post(`/company/${this.companyId}/jobs/manage`, JSON.stringify({ jobs }), undefined, {
127
127
  "Content-Type": "application/json",
128
128
  });
129
129
  },
130
- onMutate: async ({ companyId, jobs }) => {
130
+ onMutate: async ({ jobs }) => {
131
131
  await queryClient.cancelQueries({ queryKey: ['jobs'] });
132
132
  const previousJobs = queryClient.getQueryData(['jobs']);
133
133
  queryClient.setQueryData(['jobs'], (oldData) => {
@@ -208,6 +208,44 @@ AvroQueryClient.prototype.useUpdateJob = function () {
208
208
  },
209
209
  });
210
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
+ };
211
249
  AvroQueryClient.prototype.useDeleteJob = function () {
212
250
  const queryClient = this.getQueryClient();
213
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.164",
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",