@go-avro/avro-js 0.0.23 → 0.0.25

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.
@@ -424,7 +424,7 @@ declare module '../client/QueryClient' {
424
424
  breakId: string;
425
425
  updates: Partial<Break>;
426
426
  }>>;
427
- useUpdateSelf(): ReturnType<typeof useMutation<{
427
+ useUpdateUser(userId: string): ReturnType<typeof useMutation<{
428
428
  msg: string;
429
429
  }, StandardError, Partial<User>>>;
430
430
  useDeleteJobs(): ReturnType<typeof useMutation<{
@@ -59,12 +59,12 @@ AvroQueryClient.prototype.useCreateUser = function () {
59
59
  },
60
60
  });
61
61
  };
62
- AvroQueryClient.prototype.useUpdateSelf = function () {
62
+ AvroQueryClient.prototype.useUpdateUser = function (userId) {
63
63
  const queryClient = this.getQueryClient();
64
64
  return useMutation({
65
65
  mutationFn: async (data) => {
66
66
  return this.put({
67
- path: `/user`,
67
+ path: `/user/${userId}`,
68
68
  data: JSON.stringify(data),
69
69
  headers: { "Content-Type": "application/json" }
70
70
  });
@@ -72,19 +72,28 @@ AvroQueryClient.prototype.useUpdateSelf = function () {
72
72
  // Optimistically update the user data in the cache
73
73
  onMutate: async (data) => {
74
74
  await queryClient.cancelQueries({ queryKey: ['user'] });
75
- const previousUser = queryClient.getQueryData(['user']);
75
+ await queryClient.cancelQueries({ queryKey: ['users', userId] });
76
+ const previousSelf = queryClient.getQueryData(['user']);
77
+ const previousUser = queryClient.getQueryData(['users', userId]);
78
+ if (previousSelf && previousSelf.id === userId) {
79
+ queryClient.setQueryData(['user'], { ...previousSelf, ...data });
80
+ }
76
81
  if (previousUser) {
77
- queryClient.setQueryData(['user'], { ...previousUser, ...data });
82
+ queryClient.setQueryData(['users', userId], { ...previousUser, ...data });
78
83
  }
79
- return { previousUser };
84
+ return { previousSelf, previousUser };
80
85
  },
81
86
  onError: (err, _, context) => {
87
+ if (context?.previousSelf) {
88
+ queryClient.setQueryData(['user'], context.previousSelf);
89
+ }
82
90
  if (context?.previousUser) {
83
- queryClient.setQueryData(['user'], context.previousUser);
91
+ queryClient.setQueryData(['users', userId], context.previousUser);
84
92
  }
85
93
  },
86
94
  onSettled: () => {
87
95
  queryClient.invalidateQueries({ queryKey: ['user'] });
96
+ queryClient.invalidateQueries({ queryKey: ['users', userId] });
88
97
  },
89
98
  });
90
99
  };
@@ -14,6 +14,7 @@ export interface Company {
14
14
  id: string;
15
15
  name: string;
16
16
  email: string;
17
+ address: string;
17
18
  emails: Email[];
18
19
  skills: Skill[];
19
20
  catalog_items: CatalogItem[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@go-avro/avro-js",
3
- "version": "0.0.23",
3
+ "version": "0.0.25",
4
4
  "description": "JS client for Avro backend integration.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",