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

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,10 @@ declare module '../client/QueryClient' {
205
205
  sessionId: string;
206
206
  breakData: Partial<Break>;
207
207
  }>>;
208
+ useManageJobs(): ReturnType<typeof useMutation<void, StandardError, {
209
+ companyId: string;
210
+ jobs: Partial<Job>[];
211
+ }>>;
208
212
  useScheduleRoutes(): ReturnType<typeof useMutation<{
209
213
  msg: string;
210
214
  }, 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: ({ companyId, jobs }) => {
126
+ return this.post(`/company/${companyId}/jobs/manage`, JSON.stringify({ jobs }), undefined, {
127
+ "Content-Type": "application/json",
128
+ });
129
+ },
130
+ onMutate: async ({ companyId, 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({
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.164",
4
4
  "description": "JS client for Avro backend integration.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",