@go-avro/avro-js 0.0.61 → 0.0.62
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.
|
@@ -188,6 +188,14 @@ declare module '../client/QueryClient' {
|
|
|
188
188
|
useGetChat(chatId: string): UseQueryResult<Chat, StandardError>;
|
|
189
189
|
useGetCatalogItem(catalogItemId: string): UseQueryResult<CatalogItem, StandardError>;
|
|
190
190
|
useGetUserSessions(): UseQueryResult<Session[], StandardError>;
|
|
191
|
+
useGetCompanySessionsByIds(sessionIds: string[], params?: {
|
|
192
|
+
companyId?: string;
|
|
193
|
+
enabled?: boolean;
|
|
194
|
+
}): UseQueryResult<Session[], StandardError>;
|
|
195
|
+
useGetActiveCompanySessions(params?: {
|
|
196
|
+
companyId?: string;
|
|
197
|
+
enabled?: boolean;
|
|
198
|
+
}): UseQueryResult<Session[], StandardError>;
|
|
191
199
|
useGetCompanyTimecards(params?: {
|
|
192
200
|
companyId?: string;
|
|
193
201
|
periodStart?: number;
|
|
@@ -7,6 +7,56 @@ AvroQueryClient.prototype.useGetUserSessions = function () {
|
|
|
7
7
|
enabled: Boolean(this.companyId),
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
+
AvroQueryClient.prototype.useGetCompanySessionsByIds = function (sessionIds, params = {}) {
|
|
11
|
+
const companyId = params.companyId ?? this.companyId;
|
|
12
|
+
const sortedIds = [...sessionIds].sort();
|
|
13
|
+
return useQuery({
|
|
14
|
+
queryKey: ['sessions', companyId, 'by-ids', sortedIds],
|
|
15
|
+
queryFn: async () => {
|
|
16
|
+
const amount = Math.max(sortedIds.length, 50);
|
|
17
|
+
const sessions = await this.post({
|
|
18
|
+
path: `/company/${companyId}/sessions?amount=${amount}`,
|
|
19
|
+
data: JSON.stringify({ unknown_ids: sortedIds }),
|
|
20
|
+
headers: { 'Content-Type': 'application/json' },
|
|
21
|
+
});
|
|
22
|
+
return Array.isArray(sessions) ? sessions : [];
|
|
23
|
+
},
|
|
24
|
+
enabled: Boolean(companyId) && sortedIds.length > 0 && (params.enabled ?? true),
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
AvroQueryClient.prototype.useGetActiveCompanySessions = function (params = {}) {
|
|
28
|
+
const companyId = params.companyId ?? this.companyId;
|
|
29
|
+
return useQuery({
|
|
30
|
+
queryKey: ['sessions', companyId, 'active'],
|
|
31
|
+
queryFn: async () => {
|
|
32
|
+
const pageSize = 100;
|
|
33
|
+
const maxPages = 10;
|
|
34
|
+
const knownIds = [];
|
|
35
|
+
const openSessions = [];
|
|
36
|
+
for (let page = 0; page < maxPages; page += 1) {
|
|
37
|
+
const pageSessions = await this.post({
|
|
38
|
+
path: `/company/${companyId}/sessions?amount=${pageSize}`,
|
|
39
|
+
data: JSON.stringify({ known_ids: knownIds }),
|
|
40
|
+
headers: { 'Content-Type': 'application/json' },
|
|
41
|
+
});
|
|
42
|
+
if (!Array.isArray(pageSessions) || pageSessions.length === 0)
|
|
43
|
+
break;
|
|
44
|
+
for (const session of pageSessions) {
|
|
45
|
+
const isOpen = session.time_ended == null ||
|
|
46
|
+
session.time_ended <= 0 ||
|
|
47
|
+
session.time_ended <= session.time_started;
|
|
48
|
+
if (isOpen)
|
|
49
|
+
openSessions.push(session);
|
|
50
|
+
}
|
|
51
|
+
knownIds.push(...pageSessions.map((s) => s.id).filter(Boolean));
|
|
52
|
+
if (pageSessions.length < pageSize)
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
return openSessions;
|
|
56
|
+
},
|
|
57
|
+
enabled: Boolean(companyId) && (params.enabled ?? true),
|
|
58
|
+
});
|
|
59
|
+
};
|
|
10
60
|
AvroQueryClient.prototype.useCreateUserSession = function () {
|
|
11
61
|
const queryClient = this.getQueryClient();
|
|
12
62
|
return useMutation({
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const AVRO_JS_VERSION = "0.0.
|
|
1
|
+
export declare const AVRO_JS_VERSION = "0.0.62";
|
package/dist/version.js
CHANGED