@go-avro/avro-js 0.0.2-beta.58 → 0.0.2-beta.59

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.
@@ -103,6 +103,15 @@ declare module '../client/QueryClient' {
103
103
  password: string;
104
104
  phone_number: string;
105
105
  }>>;
106
+ useCreateSessionBreak(): ReturnType<typeof useMutation<{
107
+ id: string;
108
+ }, StandardError, {
109
+ sessionId: string;
110
+ breakData: {
111
+ start_time: string;
112
+ end_time?: string;
113
+ };
114
+ }>>;
106
115
  useUpdateEvent(): ReturnType<typeof useMutation<{
107
116
  msg: string;
108
117
  }, StandardError, {
@@ -154,6 +163,15 @@ declare module '../client/QueryClient' {
154
163
  user_id: string;
155
164
  data: Partial<UserCompanyAssociation>;
156
165
  }>>;
166
+ useUpdateSessionBreak(): ReturnType<typeof useMutation<{
167
+ msg: string;
168
+ }, StandardError, {
169
+ breakId: string;
170
+ updates: {
171
+ start_time?: string;
172
+ end_time?: string;
173
+ };
174
+ }>>;
157
175
  useDeleteJob(): ReturnType<typeof useMutation<{
158
176
  msg: string;
159
177
  }, StandardError, {
@@ -44,6 +44,49 @@ AvroQueryClient.prototype.useCreateUserSession = function () {
44
44
  },
45
45
  });
46
46
  };
47
+ AvroQueryClient.prototype.useCreateSessionBreak = function () {
48
+ const queryClient = useQueryClient();
49
+ return useMutation({
50
+ mutationFn: ({ sessionId, breakData }) => {
51
+ return this.post(`/session/${sessionId}/break`, JSON.stringify(breakData), undefined, {
52
+ "Content-Type": "application/json",
53
+ });
54
+ },
55
+ onMutate: async ({ sessionId, breakData }) => {
56
+ await queryClient.cancelQueries({ queryKey: ['sessions'] });
57
+ const previousSessions = queryClient.getQueryData(['sessions']);
58
+ queryClient.setQueryData(['sessions'], (oldData) => {
59
+ if (!oldData)
60
+ return oldData;
61
+ if (Array.isArray(oldData)) {
62
+ return oldData.map((session) => session.id === sessionId
63
+ ? {
64
+ ...session,
65
+ breaks: [
66
+ ...(session.breaks || []),
67
+ {
68
+ ...breakData,
69
+ id: Math.random().toString(36).substr(2, 9),
70
+ session_id: sessionId,
71
+ }
72
+ ]
73
+ }
74
+ : session);
75
+ }
76
+ return oldData;
77
+ });
78
+ return { previousSessions };
79
+ },
80
+ onError: (err, variables, context) => {
81
+ if (context?.previousSessions) {
82
+ queryClient.setQueryData(['sessions'], context.previousSessions);
83
+ }
84
+ },
85
+ onSettled: () => {
86
+ queryClient.invalidateQueries({ queryKey: ['sessions'] });
87
+ },
88
+ });
89
+ };
47
90
  AvroQueryClient.prototype.useUpdateUserSession = function () {
48
91
  const queryClient = useQueryClient();
49
92
  return useMutation({
@@ -75,3 +118,37 @@ AvroQueryClient.prototype.useUpdateUserSession = function () {
75
118
  },
76
119
  });
77
120
  };
121
+ AvroQueryClient.prototype.useUpdateSessionBreak = function () {
122
+ const queryClient = useQueryClient();
123
+ return useMutation({
124
+ mutationFn: ({ breakId, updates }) => {
125
+ return this.put(`/break/${breakId}`, JSON.stringify(updates), undefined, {
126
+ "Content-Type": "application/json",
127
+ });
128
+ },
129
+ onMutate: async ({ breakId, updates }) => {
130
+ await queryClient.cancelQueries({ queryKey: ['sessions'] });
131
+ const previousSessions = queryClient.getQueryData(['sessions']);
132
+ queryClient.setQueryData(['sessions'], (oldData) => {
133
+ if (!oldData)
134
+ return oldData;
135
+ if (Array.isArray(oldData)) {
136
+ return oldData.map((session) => ({
137
+ ...session,
138
+ breaks: session.breaks?.map(b => b.id === breakId ? { ...b, ...updates } : b)
139
+ }));
140
+ }
141
+ return oldData;
142
+ });
143
+ return { previousSessions };
144
+ },
145
+ onError: (err, variables, context) => {
146
+ if (context?.previousSessions) {
147
+ queryClient.setQueryData(['sessions'], context.previousSessions);
148
+ }
149
+ },
150
+ onSettled: () => {
151
+ queryClient.invalidateQueries({ queryKey: ['sessions'] });
152
+ },
153
+ });
154
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@go-avro/avro-js",
3
- "version": "0.0.2-beta.58",
3
+ "version": "0.0.2-beta.59",
4
4
  "description": "JS client for Avro backend integration.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",