@adventurelabs/scout-core 1.5.5 → 2.0.1
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.
- package/README.md +47 -0
- package/dist/api_keys/actions.d.ts +0 -1
- package/dist/api_keys/actions.js +0 -14
- package/dist/client/index.d.ts +76 -0
- package/dist/client/index.js +83 -0
- package/dist/constants/index.d.ts +1 -0
- package/dist/constants/index.js +1 -0
- package/dist/helpers/analysis_usage/jobs_server.d.ts +25 -0
- package/dist/helpers/analysis_usage/jobs_server.js +10 -0
- package/dist/helpers/analysis_usage/tasks_server.d.ts +63 -0
- package/dist/helpers/analysis_usage/tasks_server.js +14 -0
- package/dist/helpers/artifacts.d.ts +0 -1
- package/dist/helpers/artifacts.js +10 -147
- package/dist/helpers/artifacts.queries.d.ts +26 -0
- package/dist/helpers/{artifacts.internal.js → artifacts.queries.js} +24 -41
- package/dist/helpers/auth.d.ts +1 -1
- package/dist/helpers/auth.js +2 -3
- package/dist/helpers/auth_server.d.ts +2 -0
- package/dist/helpers/auth_server.js +10 -0
- package/dist/helpers/certificates_server.d.ts +101 -0
- package/dist/helpers/certificates_server.js +42 -0
- package/dist/helpers/chat.d.ts +1 -2
- package/dist/helpers/chat.js +3 -38
- package/dist/helpers/chat.queries.d.ts +13 -0
- package/dist/helpers/chat.queries.js +39 -0
- package/dist/helpers/client_abilities_jwt_keys.js +0 -1
- package/dist/helpers/client_abilities_token_server.d.ts +1 -0
- package/dist/helpers/client_abilities_token_server.js +5 -2
- package/dist/helpers/compliance.d.ts +26 -0
- package/dist/helpers/compliance.js +74 -0
- package/dist/helpers/compliance.queries.d.ts +28 -0
- package/dist/helpers/compliance.queries.js +167 -0
- package/dist/helpers/connectivity.d.ts +1 -5
- package/dist/helpers/connectivity.js +7 -140
- package/dist/helpers/connectivity.queries.d.ts +18 -0
- package/dist/helpers/connectivity.queries.js +121 -0
- package/dist/helpers/contacts_server.d.ts +75 -0
- package/dist/helpers/contacts_server.js +18 -0
- package/dist/helpers/deviceTransfer.js +2 -11
- package/dist/helpers/deviceTransfer.queries.d.ts +4 -0
- package/dist/helpers/deviceTransfer.queries.js +11 -0
- package/dist/helpers/devices.js +4 -61
- package/dist/helpers/devices.queries.d.ts +4 -1
- package/dist/helpers/devices.queries.js +52 -0
- package/dist/helpers/document_templates.js +6 -52
- package/dist/helpers/document_templates.queries.d.ts +9 -0
- package/dist/helpers/document_templates.queries.js +56 -0
- package/dist/helpers/documents_server.d.ts +226 -0
- package/dist/helpers/documents_server.js +38 -0
- package/dist/helpers/email.d.ts +0 -6
- package/dist/helpers/email.js +1 -19
- package/dist/helpers/embeddings.d.ts +0 -5
- package/dist/helpers/embeddings.js +2 -19
- package/dist/helpers/embeddings.queries.d.ts +7 -0
- package/dist/helpers/{embeddings.internal.js → embeddings.queries.js} +2 -2
- package/dist/helpers/eventUtils.d.ts +3 -12
- package/dist/helpers/eventUtils.js +0 -10
- package/dist/helpers/events.d.ts +0 -1
- package/dist/helpers/events.js +7 -107
- package/dist/helpers/events.queries.d.ts +17 -0
- package/dist/helpers/{events.internal.js → events.queries.js} +24 -15
- package/dist/helpers/health_metrics.js +3 -38
- package/dist/helpers/health_metrics.queries.d.ts +12 -0
- package/dist/helpers/health_metrics.queries.js +39 -0
- package/dist/helpers/heartbeats.js +4 -83
- package/dist/helpers/heartbeats.queries.d.ts +11 -0
- package/dist/helpers/heartbeats.queries.js +76 -0
- package/dist/helpers/herd_allowed_domains.js +2 -12
- package/dist/helpers/{herd_allowed_domains_internal.d.ts → herd_allowed_domains.queries.d.ts} +1 -1
- package/dist/helpers/{herd_allowed_domains_internal.js → herd_allowed_domains.queries.js} +2 -2
- package/dist/helpers/herd_credentials_server.d.ts +76 -0
- package/dist/helpers/herd_credentials_server.js +22 -0
- package/dist/helpers/herd_modules.queries.js +10 -7
- package/dist/helpers/herd_roles.js +13 -148
- package/dist/helpers/herd_roles.queries.d.ts +18 -0
- package/dist/helpers/{herd_roles_internal.js → herd_roles.queries.js} +28 -28
- package/dist/helpers/herds.js +5 -47
- package/dist/helpers/herds.queries.d.ts +8 -1
- package/dist/helpers/herds.queries.js +48 -0
- package/dist/helpers/invitations.js +7 -58
- package/dist/helpers/invitations.queries.d.ts +10 -0
- package/dist/helpers/{invitations_internal.js → invitations.queries.js} +12 -12
- package/dist/helpers/issuers.js +6 -52
- package/dist/helpers/issuers.queries.d.ts +9 -0
- package/dist/helpers/issuers.queries.js +53 -0
- package/dist/helpers/layers.js +2 -20
- package/dist/helpers/layers.queries.d.ts +2 -1
- package/dist/helpers/layers.queries.js +9 -13
- package/dist/helpers/lifecycle_server.d.ts +178 -0
- package/dist/helpers/lifecycle_server.js +38 -0
- package/dist/helpers/localizations.js +5 -42
- package/dist/helpers/localizations.queries.d.ts +8 -0
- package/dist/helpers/localizations.queries.js +45 -0
- package/dist/helpers/maintenance_requests_server.d.ts +124 -0
- package/dist/helpers/maintenance_requests_server.js +34 -0
- package/dist/helpers/manufacturers.js +5 -43
- package/dist/helpers/manufacturers.queries.d.ts +10 -0
- package/dist/helpers/manufacturers.queries.js +46 -0
- package/dist/helpers/media_urls.d.ts +13 -0
- package/dist/helpers/media_urls.js +21 -0
- package/dist/helpers/models.js +8 -80
- package/dist/helpers/models.queries.d.ts +13 -0
- package/dist/helpers/models.queries.js +79 -0
- package/dist/helpers/observations_server.d.ts +51 -0
- package/dist/helpers/observations_server.js +22 -0
- package/dist/helpers/operating_contexts.js +39 -154
- package/dist/helpers/operating_contexts.queries.d.ts +48 -0
- package/dist/helpers/operating_contexts.queries.js +223 -0
- package/dist/helpers/operators.js +4 -57
- package/dist/helpers/operators.queries.d.ts +7 -0
- package/dist/helpers/operators.queries.js +55 -0
- package/dist/helpers/parts.d.ts +0 -87
- package/dist/helpers/parts.js +1 -89
- package/dist/helpers/parts_server.d.ts +260 -0
- package/dist/helpers/parts_server.js +71 -0
- package/dist/helpers/pins_server.d.ts +118 -0
- package/dist/helpers/pins_server.js +38 -0
- package/dist/helpers/plans.js +4 -56
- package/dist/helpers/plans.queries.d.ts +4 -1
- package/dist/helpers/plans.queries.js +39 -12
- package/dist/helpers/points_for_user_server.d.ts +9 -0
- package/dist/helpers/points_for_user_server.js +14 -0
- package/dist/helpers/product_compatibilities.js +6 -78
- package/dist/helpers/product_compatibilities.queries.d.ts +9 -0
- package/dist/helpers/product_compatibilities.queries.js +83 -0
- package/dist/helpers/product_numbers.js +6 -55
- package/dist/helpers/product_numbers.queries.d.ts +9 -0
- package/dist/helpers/product_numbers.queries.js +58 -0
- package/dist/helpers/products.js +6 -54
- package/dist/helpers/products.queries.d.ts +11 -0
- package/dist/helpers/products.queries.js +58 -0
- package/dist/helpers/providers.js +5 -71
- package/dist/helpers/providers.queries.d.ts +5 -1
- package/dist/helpers/providers.queries.js +52 -11
- package/dist/helpers/pubsub_token_server.d.ts +1 -0
- package/dist/helpers/pubsub_token_server.js +5 -2
- package/dist/helpers/segmentations_sam3.js +5 -78
- package/dist/helpers/segmentations_sam3.queries.d.ts +16 -0
- package/dist/helpers/segmentations_sam3.queries.js +81 -0
- package/dist/helpers/sensor_poses_server.d.ts +98 -0
- package/dist/helpers/sensor_poses_server.js +26 -0
- package/dist/helpers/session_incidents_server.d.ts +106 -0
- package/dist/helpers/session_incidents_server.js +22 -0
- package/dist/helpers/session_summaries.d.ts +2 -0
- package/dist/helpers/session_summaries.js +7 -23
- package/dist/helpers/session_summaries.queries.d.ts +6 -3
- package/dist/helpers/session_summaries.queries.js +27 -0
- package/dist/helpers/sessions.js +8 -122
- package/dist/helpers/sessions.queries.d.ts +14 -2
- package/dist/helpers/sessions.queries.js +88 -1
- package/dist/helpers/storage.js +0 -1
- package/dist/helpers/supabase_auth.d.ts +6 -0
- package/dist/helpers/supabase_auth.js +37 -0
- package/dist/helpers/tags.d.ts +0 -1
- package/dist/helpers/tags.js +13 -559
- package/dist/helpers/tags.queries.d.ts +33 -0
- package/dist/helpers/tags.queries.js +454 -0
- package/dist/helpers/user_credentials_server.d.ts +76 -0
- package/dist/helpers/user_credentials_server.js +22 -0
- package/dist/helpers/users.d.ts +2 -2
- package/dist/helpers/users.js +8 -107
- package/dist/helpers/users.queries.d.ts +9 -1
- package/dist/helpers/users.queries.js +107 -0
- package/dist/helpers/versions_software.d.ts +3 -1
- package/dist/helpers/versions_software.js +24 -0
- package/dist/helpers/versions_software_server.d.ts +83 -4
- package/dist/helpers/versions_software_server.js +23 -50
- package/dist/helpers/zones.d.ts +1 -16
- package/dist/helpers/zones.js +4 -104
- package/dist/helpers/zones.queries.d.ts +6 -0
- package/dist/helpers/zones.queries.js +78 -0
- package/dist/hooks/useAuthorizedRealtimeTopics.js +8 -2
- package/dist/hooks/useInfiniteQuery.js +18 -14
- package/dist/hooks/useScoutRealtimeBroadcast.js +8 -6
- package/dist/hooks/useScoutRealtimeDocuments.js +3 -2
- package/dist/hooks/useScoutRefresh.d.ts +9 -25
- package/dist/hooks/useScoutRefresh.js +33 -213
- package/dist/providers/ScoutRefreshProvider.d.ts +1 -1
- package/dist/providers/ScoutRefreshProvider.js +56 -13
- package/dist/server/index.d.ts +78 -0
- package/dist/server/index.js +80 -0
- package/dist/server/middleware.d.ts +2 -0
- package/dist/server/middleware.js +2 -0
- package/dist/server/supabase.d.ts +2 -0
- package/dist/server/supabase.js +2 -0
- package/dist/store/api.d.ts +40 -40
- package/dist/store/api.js +38 -109
- package/dist/store/configureStore.d.ts +0 -55
- package/dist/store/configureStore.js +1 -8
- package/dist/store/hooks.js +1 -0
- package/dist/supabase/client.d.ts +3 -0
- package/dist/supabase/client.js +10 -0
- package/dist/supabase/middleware.d.ts +1 -0
- package/dist/supabase/middleware.js +6 -20
- package/dist/supabase/server.d.ts +7 -2
- package/dist/supabase/server.js +13 -1
- package/dist/types/db.d.ts +47 -3
- package/dist/types/index.d.ts +5 -0
- package/dist/types/index.js +5 -0
- package/dist/types/supabase.d.ts +512 -0
- package/package.json +53 -4
- package/dist/api_keys/index.d.ts +0 -1
- package/dist/api_keys/index.js +0 -1
- package/dist/helpers/artifacts.internal.d.ts +0 -22
- package/dist/helpers/client_abilities_jwt_keys_internal.d.ts +0 -9
- package/dist/helpers/client_abilities_jwt_keys_internal.js +0 -20
- package/dist/helpers/connectivity.internal.d.ts +0 -10
- package/dist/helpers/connectivity.internal.js +0 -47
- package/dist/helpers/credentials.d.ts +0 -9
- package/dist/helpers/credentials.js +0 -92
- package/dist/helpers/embeddings.internal.d.ts +0 -5
- package/dist/helpers/events.internal.d.ts +0 -13
- package/dist/helpers/herd_roles_internal.d.ts +0 -18
- package/dist/helpers/index.d.ts +0 -56
- package/dist/helpers/index.js +0 -56
- package/dist/helpers/invitations_internal.d.ts +0 -10
- package/dist/helpers/versions_software_internal.d.ts +0 -6
- package/dist/helpers/versions_software_internal.js +0 -53
- package/dist/hooks/useDeviceDisplayName.d.ts +0 -8
- package/dist/hooks/useDeviceDisplayName.js +0 -49
- package/dist/index.d.ts +0 -108
- package/dist/index.js +0 -114
- package/dist/supabase/index.d.ts +0 -2
- package/dist/supabase/index.js +0 -2
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { IWebResponse } from "../types/requests";
|
|
2
|
+
function responseError(message) {
|
|
3
|
+
return IWebResponse.error(message).to_compatible();
|
|
4
|
+
}
|
|
5
|
+
function pageLimit(options) {
|
|
6
|
+
const limit = options?.limit ?? 100;
|
|
7
|
+
return limit < 1 || limit > 500 ? null : limit;
|
|
8
|
+
}
|
|
9
|
+
function updateError(updates) {
|
|
10
|
+
if (Object.keys(updates).length === 0)
|
|
11
|
+
return "no fields to update";
|
|
12
|
+
if (updates.lifecycle_reason !== undefined && updates.lifecycle === undefined) {
|
|
13
|
+
return "lifecycle_reason requires lifecycle";
|
|
14
|
+
}
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
async function authenticatedUserId(client) {
|
|
18
|
+
const { data, error } = await client.auth.getUser();
|
|
19
|
+
return error ? null : (data.user?.id ?? null);
|
|
20
|
+
}
|
|
21
|
+
function withLifecycleActor(updates, userId) {
|
|
22
|
+
return updates.lifecycle
|
|
23
|
+
? { ...updates, lifecycle_changed_by: userId }
|
|
24
|
+
: updates;
|
|
25
|
+
}
|
|
26
|
+
async function listBy(client, table, column, value, options) {
|
|
27
|
+
const limit = pageLimit(options);
|
|
28
|
+
if (limit == null)
|
|
29
|
+
return responseError("limit must be between 1 and 500");
|
|
30
|
+
let query = client
|
|
31
|
+
.from(table)
|
|
32
|
+
.select("*")
|
|
33
|
+
.eq(column, value)
|
|
34
|
+
.order("id")
|
|
35
|
+
.limit(limit);
|
|
36
|
+
if (!options?.include_inactive)
|
|
37
|
+
query = query.eq("lifecycle", "active");
|
|
38
|
+
if (options?.after_id != null)
|
|
39
|
+
query = query.gt("id", options.after_id);
|
|
40
|
+
const { data, error } = await query;
|
|
41
|
+
return error
|
|
42
|
+
? responseError(error.message)
|
|
43
|
+
: IWebResponse.success((data ?? [])).to_compatible();
|
|
44
|
+
}
|
|
45
|
+
async function listAll(client, table, options) {
|
|
46
|
+
const limit = pageLimit(options);
|
|
47
|
+
if (limit == null)
|
|
48
|
+
return responseError("limit must be between 1 and 500");
|
|
49
|
+
let query = client.from(table).select("*").order("id").limit(limit);
|
|
50
|
+
if (!options?.include_inactive)
|
|
51
|
+
query = query.eq("lifecycle", "active");
|
|
52
|
+
if (options?.after_id != null)
|
|
53
|
+
query = query.gt("id", options.after_id);
|
|
54
|
+
const { data, error } = await query;
|
|
55
|
+
return error
|
|
56
|
+
? responseError(error.message)
|
|
57
|
+
: IWebResponse.success((data ?? [])).to_compatible();
|
|
58
|
+
}
|
|
59
|
+
async function insertRow(client, table, row) {
|
|
60
|
+
const { data, error } = await client
|
|
61
|
+
.from(table)
|
|
62
|
+
.insert(row)
|
|
63
|
+
.select("*")
|
|
64
|
+
.single();
|
|
65
|
+
return error
|
|
66
|
+
? responseError(error.message)
|
|
67
|
+
: IWebResponse.success(data).to_compatible();
|
|
68
|
+
}
|
|
69
|
+
async function insertWithCreator(client, table, row) {
|
|
70
|
+
const userId = await authenticatedUserId(client);
|
|
71
|
+
if (!userId)
|
|
72
|
+
return responseError("authentication required");
|
|
73
|
+
return insertRow(client, table, { ...row, created_by: userId });
|
|
74
|
+
}
|
|
75
|
+
async function patchRow(client, table, id, updates, trackUpdater = false) {
|
|
76
|
+
const invalid = updateError(updates);
|
|
77
|
+
if (invalid)
|
|
78
|
+
return responseError(invalid);
|
|
79
|
+
const userId = await authenticatedUserId(client);
|
|
80
|
+
if (!userId)
|
|
81
|
+
return responseError("authentication required");
|
|
82
|
+
const payload = {
|
|
83
|
+
...withLifecycleActor(updates, userId),
|
|
84
|
+
...(trackUpdater && { updated_by: userId }),
|
|
85
|
+
};
|
|
86
|
+
const { data, error } = await client
|
|
87
|
+
.from(table)
|
|
88
|
+
.update(payload)
|
|
89
|
+
.eq("id", id)
|
|
90
|
+
.select("*")
|
|
91
|
+
.single();
|
|
92
|
+
return error
|
|
93
|
+
? responseError(error.message)
|
|
94
|
+
: IWebResponse.success(data).to_compatible();
|
|
95
|
+
}
|
|
96
|
+
export async function get_contact_types_by_localization_query(client, localizationId, options) {
|
|
97
|
+
return listBy(client, "contact_types", "localization_id", localizationId, options);
|
|
98
|
+
}
|
|
99
|
+
export async function create_contact_type_query(client, row) {
|
|
100
|
+
return insertRow(client, "contact_types", row);
|
|
101
|
+
}
|
|
102
|
+
export async function update_contact_type_query(client, id, updates) {
|
|
103
|
+
return patchRow(client, "contact_types", id, updates);
|
|
104
|
+
}
|
|
105
|
+
export async function get_operating_context_point_of_interest_types_by_localization_query(client, localizationId, options) {
|
|
106
|
+
return listBy(client, "operating_context_point_of_interest_types", "localization_id", localizationId, options);
|
|
107
|
+
}
|
|
108
|
+
export async function create_operating_context_point_of_interest_type_query(client, row) {
|
|
109
|
+
return insertRow(client, "operating_context_point_of_interest_types", row);
|
|
110
|
+
}
|
|
111
|
+
export async function update_operating_context_point_of_interest_type_query(client, id, updates) {
|
|
112
|
+
return patchRow(client, "operating_context_point_of_interest_types", id, updates);
|
|
113
|
+
}
|
|
114
|
+
export async function get_operating_permissions_by_localization_query(client, localizationId, options) {
|
|
115
|
+
return listBy(client, "operating_permissions", "localization_id", localizationId, options);
|
|
116
|
+
}
|
|
117
|
+
export async function create_operating_permission_query(client, row) {
|
|
118
|
+
return insertRow(client, "operating_permissions", row);
|
|
119
|
+
}
|
|
120
|
+
export async function update_operating_permission_query(client, id, updates) {
|
|
121
|
+
return patchRow(client, "operating_permissions", id, updates);
|
|
122
|
+
}
|
|
123
|
+
export async function get_compliance_resource_types_query(client, options) {
|
|
124
|
+
return listAll(client, "compliance_resource_types", options);
|
|
125
|
+
}
|
|
126
|
+
export async function create_compliance_resource_type_query(client, row) {
|
|
127
|
+
return insertRow(client, "compliance_resource_types", row);
|
|
128
|
+
}
|
|
129
|
+
export async function update_compliance_resource_type_query(client, id, updates) {
|
|
130
|
+
return patchRow(client, "compliance_resource_types", id, updates);
|
|
131
|
+
}
|
|
132
|
+
export async function get_compliance_resources_by_localization_query(client, localizationId, options) {
|
|
133
|
+
return listBy(client, "compliance_resources", "localization_id", localizationId, options);
|
|
134
|
+
}
|
|
135
|
+
export async function create_compliance_resource_query(client, row) {
|
|
136
|
+
return insertRow(client, "compliance_resources", row);
|
|
137
|
+
}
|
|
138
|
+
export async function update_compliance_resource_query(client, id, updates) {
|
|
139
|
+
return patchRow(client, "compliance_resources", id, updates);
|
|
140
|
+
}
|
|
141
|
+
export async function get_operating_context_points_of_interest_by_operating_context_query(client, operatingContextId, options) {
|
|
142
|
+
return listBy(client, "operating_context_points_of_interest", "operating_context_id", operatingContextId, options);
|
|
143
|
+
}
|
|
144
|
+
export async function create_operating_context_point_of_interest_query(client, row) {
|
|
145
|
+
return insertWithCreator(client, "operating_context_points_of_interest", row);
|
|
146
|
+
}
|
|
147
|
+
export async function update_operating_context_point_of_interest_query(client, id, updates) {
|
|
148
|
+
return patchRow(client, "operating_context_points_of_interest", id, updates, true);
|
|
149
|
+
}
|
|
150
|
+
export async function get_operating_context_contacts_by_operating_context_query(client, operatingContextId, options) {
|
|
151
|
+
return listBy(client, "operating_context_contacts", "operating_context_id", operatingContextId, options);
|
|
152
|
+
}
|
|
153
|
+
export async function create_operating_context_contact_query(client, row) {
|
|
154
|
+
return insertRow(client, "operating_context_contacts", row);
|
|
155
|
+
}
|
|
156
|
+
export async function update_operating_context_contact_query(client, id, updates) {
|
|
157
|
+
return patchRow(client, "operating_context_contacts", id, updates);
|
|
158
|
+
}
|
|
159
|
+
export async function get_herd_operating_permissions_by_herd_query(client, herdId, options) {
|
|
160
|
+
return listBy(client, "herd_operating_permissions", "herd_id", herdId, options);
|
|
161
|
+
}
|
|
162
|
+
export async function create_herd_operating_permission_query(client, row) {
|
|
163
|
+
return insertRow(client, "herd_operating_permissions", row);
|
|
164
|
+
}
|
|
165
|
+
export async function update_herd_operating_permission_query(client, id, updates) {
|
|
166
|
+
return patchRow(client, "herd_operating_permissions", id, updates);
|
|
167
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { IWebResponseCompatible } from "../types/requests";
|
|
2
2
|
import { IConnectivityWithCoordinates, IConnectivity, ConnectivityInsert, ConnectivityUpdate } from "../types/db";
|
|
3
|
+
import { type HerdConnectivityTimeRangeResponse } from "./connectivity.queries";
|
|
3
4
|
export declare function server_get_connectivity_by_session_id(sessionId: number): Promise<IWebResponseCompatible<IConnectivityWithCoordinates[]>>;
|
|
4
5
|
export declare function server_get_connectivity_by_device_id(deviceId: number, timestamp: string): Promise<IWebResponseCompatible<IConnectivityWithCoordinates[]>>;
|
|
5
6
|
export declare function server_insert_connectivity(connectivity: ConnectivityInsert | ConnectivityInsert[]): Promise<IWebResponseCompatible<IConnectivity[]>>;
|
|
@@ -8,11 +9,6 @@ export declare function server_update_connectivity(connectivity: (ConnectivityUp
|
|
|
8
9
|
}) | (ConnectivityUpdate & {
|
|
9
10
|
id: number;
|
|
10
11
|
})[]): Promise<IWebResponseCompatible<IConnectivity[]>>;
|
|
11
|
-
/** Pagination info returned with herd time range connectivity. */
|
|
12
|
-
export type HerdConnectivityTimeRangeResponse = IWebResponseCompatible<IConnectivityWithCoordinates[]> & {
|
|
13
|
-
hasMore: boolean;
|
|
14
|
-
nextOffset: number;
|
|
15
|
-
};
|
|
16
12
|
/** Connectivity records for a herd within a time range. Returns most recent rows with hasMore and nextOffset for pagination. */
|
|
17
13
|
export declare function server_get_connectivity_for_herd_time_range(herdId: number, startTimestamp: string, endTimestamp: string, maxCount?: number, offset?: number): Promise<HerdConnectivityTimeRangeResponse>;
|
|
18
14
|
/** Connectivity records for an artifact (uses session when set, else device + time window). */
|
|
@@ -1,155 +1,22 @@
|
|
|
1
|
-
"use server";
|
|
2
1
|
import { newServerClient } from "../supabase/server";
|
|
3
|
-
import {
|
|
4
|
-
// Get connectivity by session id using RPC function with coordinates
|
|
2
|
+
import { get_connectivity_by_device_id_query, get_connectivity_by_session_id_query, get_connectivity_for_artifact_query, get_connectivity_for_herd_time_range_query, insert_connectivity_query, update_connectivity_query, } from "./connectivity.queries";
|
|
5
3
|
export async function server_get_connectivity_by_session_id(sessionId) {
|
|
6
|
-
|
|
7
|
-
const { data, error } = await supabase.rpc("get_connectivity_with_coordinates", { session_id_caller: sessionId });
|
|
8
|
-
if (error) {
|
|
9
|
-
console.warn("Error fetching connectivity by session id:", error.message);
|
|
10
|
-
return {
|
|
11
|
-
status: EnumWebResponse.ERROR,
|
|
12
|
-
msg: error.message,
|
|
13
|
-
data: [],
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
// Sort by timestamp_start in ascending order
|
|
17
|
-
const sortedConnectivity = (data || []).sort((a, b) => {
|
|
18
|
-
if (!a.timestamp_start || !b.timestamp_start)
|
|
19
|
-
return 0;
|
|
20
|
-
return (new Date(a.timestamp_start).getTime() -
|
|
21
|
-
new Date(b.timestamp_start).getTime());
|
|
22
|
-
});
|
|
23
|
-
return IWebResponse.success(sortedConnectivity).to_compatible();
|
|
4
|
+
return get_connectivity_by_session_id_query(await newServerClient(), sessionId);
|
|
24
5
|
}
|
|
25
|
-
// Get all connectivity items after a specific timestamp, filtered by device ID
|
|
26
|
-
// Timestamp should be formatted as YYYY-MM-DDTHH:mm:ss.SSSZ
|
|
27
6
|
export async function server_get_connectivity_by_device_id(deviceId, timestamp) {
|
|
28
|
-
|
|
29
|
-
const { data, error } = await supabase.rpc("get_connectivity_with_coordinates_by_device_and_timestamp", { device_id_caller: deviceId, timestamp_filter: timestamp });
|
|
30
|
-
if (error) {
|
|
31
|
-
console.warn("Error fetching connectivity by session id:", error.message);
|
|
32
|
-
return {
|
|
33
|
-
status: EnumWebResponse.ERROR,
|
|
34
|
-
msg: error.message,
|
|
35
|
-
data: [],
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
// Sort by timestamp_start in ascending order
|
|
39
|
-
const sortedConnectivity = (data || []).sort((a, b) => {
|
|
40
|
-
if (!a.timestamp_start || !b.timestamp_start)
|
|
41
|
-
return 0;
|
|
42
|
-
return (new Date(a.timestamp_start).getTime() -
|
|
43
|
-
new Date(b.timestamp_start).getTime());
|
|
44
|
-
});
|
|
45
|
-
return IWebResponse.success(sortedConnectivity).to_compatible();
|
|
7
|
+
return get_connectivity_by_device_id_query(await newServerClient(), deviceId, timestamp);
|
|
46
8
|
}
|
|
47
|
-
// Insert new connectivity records (accepts array for batch operations)
|
|
48
9
|
export async function server_insert_connectivity(connectivity) {
|
|
49
|
-
|
|
50
|
-
const connectivityArray = Array.isArray(connectivity)
|
|
51
|
-
? connectivity
|
|
52
|
-
: [connectivity];
|
|
53
|
-
const { data, error } = await client
|
|
54
|
-
.from("connectivity")
|
|
55
|
-
.insert(connectivityArray)
|
|
56
|
-
.select("*");
|
|
57
|
-
if (error) {
|
|
58
|
-
console.warn("Error inserting connectivity:", error.message);
|
|
59
|
-
return {
|
|
60
|
-
status: EnumWebResponse.ERROR,
|
|
61
|
-
msg: error.message,
|
|
62
|
-
data: [],
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
return IWebResponse.success(data || []).to_compatible();
|
|
10
|
+
return insert_connectivity_query(await newServerClient(), connectivity);
|
|
66
11
|
}
|
|
67
|
-
// Update existing connectivity records (accepts array for batch operations)
|
|
68
|
-
// Each connectivity record in the array must include an 'id' field
|
|
69
12
|
export async function server_update_connectivity(connectivity) {
|
|
70
|
-
|
|
71
|
-
const connectivityArray = Array.isArray(connectivity)
|
|
72
|
-
? connectivity
|
|
73
|
-
: [connectivity];
|
|
74
|
-
const updatedConnectivity = [];
|
|
75
|
-
for (const record of connectivityArray) {
|
|
76
|
-
const { id, ...updateData } = record;
|
|
77
|
-
delete updateData.inserted_at;
|
|
78
|
-
const { data, error } = await client
|
|
79
|
-
.from("connectivity")
|
|
80
|
-
.update(updateData)
|
|
81
|
-
.eq("id", id)
|
|
82
|
-
.select("*")
|
|
83
|
-
.single();
|
|
84
|
-
if (error) {
|
|
85
|
-
console.warn("Error updating connectivity:", error.message);
|
|
86
|
-
return {
|
|
87
|
-
status: EnumWebResponse.ERROR,
|
|
88
|
-
msg: error.message,
|
|
89
|
-
data: [],
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
if (data) {
|
|
93
|
-
updatedConnectivity.push(data);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
return IWebResponse.success(updatedConnectivity).to_compatible();
|
|
13
|
+
return update_connectivity_query(await newServerClient(), connectivity);
|
|
97
14
|
}
|
|
98
15
|
/** Connectivity records for a herd within a time range. Returns most recent rows with hasMore and nextOffset for pagination. */
|
|
99
16
|
export async function server_get_connectivity_for_herd_time_range(herdId, startTimestamp, endTimestamp, maxCount = 1000, offset = 0) {
|
|
100
|
-
|
|
101
|
-
const { data, error } = await supabase.rpc("get_connectivity_for_herd_time_range", {
|
|
102
|
-
herd_id_caller: herdId,
|
|
103
|
-
start_timestamp_caller: startTimestamp,
|
|
104
|
-
end_timestamp_caller: endTimestamp,
|
|
105
|
-
max_elements_caller: maxCount + 1,
|
|
106
|
-
offset_caller: offset,
|
|
107
|
-
});
|
|
108
|
-
if (error) {
|
|
109
|
-
console.warn("Error fetching connectivity for herd time range:", error.message);
|
|
110
|
-
return {
|
|
111
|
-
status: EnumWebResponse.ERROR,
|
|
112
|
-
msg: error.message,
|
|
113
|
-
data: [],
|
|
114
|
-
hasMore: false,
|
|
115
|
-
nextOffset: offset,
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
const sorted = (data || []).sort((a, b) => {
|
|
119
|
-
if (!a.timestamp_start || !b.timestamp_start)
|
|
120
|
-
return 0;
|
|
121
|
-
return (new Date(a.timestamp_start).getTime() -
|
|
122
|
-
new Date(b.timestamp_start).getTime());
|
|
123
|
-
});
|
|
124
|
-
const hasMore = sorted.length > maxCount;
|
|
125
|
-
const items = hasMore ? sorted.slice(0, maxCount) : sorted;
|
|
126
|
-
const nextOffset = offset + items.length;
|
|
127
|
-
return {
|
|
128
|
-
...IWebResponse.success(items).to_compatible(),
|
|
129
|
-
hasMore,
|
|
130
|
-
nextOffset,
|
|
131
|
-
};
|
|
17
|
+
return get_connectivity_for_herd_time_range_query(await newServerClient(), herdId, startTimestamp, endTimestamp, maxCount, offset);
|
|
132
18
|
}
|
|
133
19
|
/** Connectivity records for an artifact (uses session when set, else device + time window). */
|
|
134
20
|
export async function server_get_connectivity_for_artifact(artifactId, maxElements = 1000) {
|
|
135
|
-
|
|
136
|
-
const { data, error } = await supabase.rpc("get_connectivity_for_artifact", {
|
|
137
|
-
artifact_id_caller: artifactId,
|
|
138
|
-
max_elements_caller: maxElements,
|
|
139
|
-
});
|
|
140
|
-
if (error) {
|
|
141
|
-
console.warn("Error fetching connectivity for artifact:", error.message);
|
|
142
|
-
return {
|
|
143
|
-
status: EnumWebResponse.ERROR,
|
|
144
|
-
msg: error.message,
|
|
145
|
-
data: [],
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
const sortedConnectivity = (data || []).sort((a, b) => {
|
|
149
|
-
if (!a.timestamp_start || !b.timestamp_start)
|
|
150
|
-
return 0;
|
|
151
|
-
return (new Date(a.timestamp_start).getTime() -
|
|
152
|
-
new Date(b.timestamp_start).getTime());
|
|
153
|
-
});
|
|
154
|
-
return IWebResponse.success(sortedConnectivity).to_compatible();
|
|
21
|
+
return get_connectivity_for_artifact_query(await newServerClient(), artifactId, maxElements);
|
|
155
22
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { SupabaseClient } from "@supabase/supabase-js";
|
|
2
|
+
import { ConnectivityInsert, ConnectivityUpdate, IConnectivity, IConnectivityWithCoordinates } from "../types/db";
|
|
3
|
+
import { IWebResponseCompatible } from "../types/requests";
|
|
4
|
+
import { Database } from "../types/supabase";
|
|
5
|
+
export type HerdConnectivityTimeRangeResponse = IWebResponseCompatible<IConnectivityWithCoordinates[]> & {
|
|
6
|
+
hasMore: boolean;
|
|
7
|
+
nextOffset: number;
|
|
8
|
+
};
|
|
9
|
+
export declare function get_connectivity_by_session_id_query(client: SupabaseClient<Database>, sessionId: number): Promise<IWebResponseCompatible<IConnectivityWithCoordinates[]>>;
|
|
10
|
+
export declare function get_connectivity_by_device_id_query(client: SupabaseClient<Database>, deviceId: number, timestamp: string): Promise<IWebResponseCompatible<IConnectivityWithCoordinates[]>>;
|
|
11
|
+
export declare function insert_connectivity_query(client: SupabaseClient<Database>, connectivity: ConnectivityInsert | ConnectivityInsert[]): Promise<IWebResponseCompatible<IConnectivity[]>>;
|
|
12
|
+
export declare function update_connectivity_query(client: SupabaseClient<Database>, connectivity: (ConnectivityUpdate & {
|
|
13
|
+
id: number;
|
|
14
|
+
}) | (ConnectivityUpdate & {
|
|
15
|
+
id: number;
|
|
16
|
+
})[]): Promise<IWebResponseCompatible<IConnectivity[]>>;
|
|
17
|
+
export declare function get_connectivity_for_herd_time_range_query(client: SupabaseClient<Database>, herdId: number, startTimestamp: string, endTimestamp: string, maxCount?: number, offset?: number): Promise<HerdConnectivityTimeRangeResponse>;
|
|
18
|
+
export declare function get_connectivity_for_artifact_query(client: SupabaseClient<Database>, artifactId: number, maxElements?: number): Promise<IWebResponseCompatible<IConnectivityWithCoordinates[]>>;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { EnumWebResponse, IWebResponse, } from "../types/requests";
|
|
2
|
+
function sortConnectivityByTimestamp(data) {
|
|
3
|
+
return data.sort((a, b) => {
|
|
4
|
+
if (!a.timestamp_start || !b.timestamp_start)
|
|
5
|
+
return 0;
|
|
6
|
+
return (new Date(a.timestamp_start).getTime() -
|
|
7
|
+
new Date(b.timestamp_start).getTime());
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
export async function get_connectivity_by_session_id_query(client, sessionId) {
|
|
11
|
+
const { data, error } = await client.rpc("get_connectivity_with_coordinates", { session_id_caller: sessionId });
|
|
12
|
+
if (error) {
|
|
13
|
+
console.warn("Error fetching connectivity by session id:", error.message);
|
|
14
|
+
return {
|
|
15
|
+
status: EnumWebResponse.ERROR,
|
|
16
|
+
msg: error.message,
|
|
17
|
+
data: [],
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
return IWebResponse.success(sortConnectivityByTimestamp(data || [])).to_compatible();
|
|
21
|
+
}
|
|
22
|
+
export async function get_connectivity_by_device_id_query(client, deviceId, timestamp) {
|
|
23
|
+
const { data, error } = await client.rpc("get_connectivity_with_coordinates_by_device_and_timestamp", { device_id_caller: deviceId, timestamp_filter: timestamp });
|
|
24
|
+
if (error) {
|
|
25
|
+
console.warn("Error fetching connectivity by session id:", error.message);
|
|
26
|
+
return {
|
|
27
|
+
status: EnumWebResponse.ERROR,
|
|
28
|
+
msg: error.message,
|
|
29
|
+
data: [],
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
return IWebResponse.success(sortConnectivityByTimestamp(data || [])).to_compatible();
|
|
33
|
+
}
|
|
34
|
+
export async function insert_connectivity_query(client, connectivity) {
|
|
35
|
+
const connectivityArray = Array.isArray(connectivity)
|
|
36
|
+
? connectivity
|
|
37
|
+
: [connectivity];
|
|
38
|
+
const { data, error } = await client
|
|
39
|
+
.from("connectivity")
|
|
40
|
+
.insert(connectivityArray)
|
|
41
|
+
.select("*");
|
|
42
|
+
if (error) {
|
|
43
|
+
console.warn("Error inserting connectivity:", error.message);
|
|
44
|
+
return {
|
|
45
|
+
status: EnumWebResponse.ERROR,
|
|
46
|
+
msg: error.message,
|
|
47
|
+
data: [],
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
return IWebResponse.success(data || []).to_compatible();
|
|
51
|
+
}
|
|
52
|
+
export async function update_connectivity_query(client, connectivity) {
|
|
53
|
+
const connectivityArray = Array.isArray(connectivity)
|
|
54
|
+
? connectivity
|
|
55
|
+
: [connectivity];
|
|
56
|
+
const updatedConnectivity = [];
|
|
57
|
+
for (const record of connectivityArray) {
|
|
58
|
+
const { id, ...updateData } = record;
|
|
59
|
+
delete updateData.inserted_at;
|
|
60
|
+
const { data, error } = await client
|
|
61
|
+
.from("connectivity")
|
|
62
|
+
.update(updateData)
|
|
63
|
+
.eq("id", id)
|
|
64
|
+
.select("*")
|
|
65
|
+
.single();
|
|
66
|
+
if (error) {
|
|
67
|
+
console.warn("Error updating connectivity:", error.message);
|
|
68
|
+
return {
|
|
69
|
+
status: EnumWebResponse.ERROR,
|
|
70
|
+
msg: error.message,
|
|
71
|
+
data: [],
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
if (data) {
|
|
75
|
+
updatedConnectivity.push(data);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return IWebResponse.success(updatedConnectivity).to_compatible();
|
|
79
|
+
}
|
|
80
|
+
export async function get_connectivity_for_herd_time_range_query(client, herdId, startTimestamp, endTimestamp, maxCount = 1000, offset = 0) {
|
|
81
|
+
const { data, error } = await client.rpc("get_connectivity_for_herd_time_range", {
|
|
82
|
+
herd_id_caller: herdId,
|
|
83
|
+
start_timestamp_caller: startTimestamp,
|
|
84
|
+
end_timestamp_caller: endTimestamp,
|
|
85
|
+
max_elements_caller: maxCount + 1,
|
|
86
|
+
offset_caller: offset,
|
|
87
|
+
});
|
|
88
|
+
if (error) {
|
|
89
|
+
console.warn("Error fetching connectivity for herd time range:", error.message);
|
|
90
|
+
return {
|
|
91
|
+
status: EnumWebResponse.ERROR,
|
|
92
|
+
msg: error.message,
|
|
93
|
+
data: [],
|
|
94
|
+
hasMore: false,
|
|
95
|
+
nextOffset: offset,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
const sorted = sortConnectivityByTimestamp(data || []);
|
|
99
|
+
const hasMore = sorted.length > maxCount;
|
|
100
|
+
const items = hasMore ? sorted.slice(0, maxCount) : sorted;
|
|
101
|
+
return {
|
|
102
|
+
...IWebResponse.success(items).to_compatible(),
|
|
103
|
+
hasMore,
|
|
104
|
+
nextOffset: offset + items.length,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
export async function get_connectivity_for_artifact_query(client, artifactId, maxElements = 1000) {
|
|
108
|
+
const { data, error } = await client.rpc("get_connectivity_for_artifact", {
|
|
109
|
+
artifact_id_caller: artifactId,
|
|
110
|
+
max_elements_caller: maxElements,
|
|
111
|
+
});
|
|
112
|
+
if (error) {
|
|
113
|
+
console.warn("Error fetching connectivity for artifact:", error.message);
|
|
114
|
+
return {
|
|
115
|
+
status: EnumWebResponse.ERROR,
|
|
116
|
+
msg: error.message,
|
|
117
|
+
data: [],
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
return IWebResponse.success(sortConnectivityByTimestamp(data || [])).to_compatible();
|
|
121
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { ContactInsert, ContactUpdate } from "../types/db";
|
|
2
|
+
export declare function server_get_contacts_by_herd_id(herd_id: number, options?: {
|
|
3
|
+
include_inactive?: boolean;
|
|
4
|
+
}): Promise<import("../types").IWebResponseCompatible<{
|
|
5
|
+
contact_type_id: number | null;
|
|
6
|
+
created_at: string;
|
|
7
|
+
created_by: string | null;
|
|
8
|
+
email: string | null;
|
|
9
|
+
herd_id: number;
|
|
10
|
+
id: number;
|
|
11
|
+
lifecycle: import("../types").Database["public"]["Enums"]["entity_lifecycle"];
|
|
12
|
+
lifecycle_changed_at: string;
|
|
13
|
+
lifecycle_changed_by: string | null;
|
|
14
|
+
lifecycle_reason: string | null;
|
|
15
|
+
name: string;
|
|
16
|
+
notes: string | null;
|
|
17
|
+
phone: string | null;
|
|
18
|
+
radio_frequency: string | null;
|
|
19
|
+
updated_at: string;
|
|
20
|
+
updated_by: string | null;
|
|
21
|
+
}[]>>;
|
|
22
|
+
export declare function server_get_contact_by_id(contact_id: number): Promise<import("../types").IWebResponseCompatible<{
|
|
23
|
+
contact_type_id: number | null;
|
|
24
|
+
created_at: string;
|
|
25
|
+
created_by: string | null;
|
|
26
|
+
email: string | null;
|
|
27
|
+
herd_id: number;
|
|
28
|
+
id: number;
|
|
29
|
+
lifecycle: import("../types").Database["public"]["Enums"]["entity_lifecycle"];
|
|
30
|
+
lifecycle_changed_at: string;
|
|
31
|
+
lifecycle_changed_by: string | null;
|
|
32
|
+
lifecycle_reason: string | null;
|
|
33
|
+
name: string;
|
|
34
|
+
notes: string | null;
|
|
35
|
+
phone: string | null;
|
|
36
|
+
radio_frequency: string | null;
|
|
37
|
+
updated_at: string;
|
|
38
|
+
updated_by: string | null;
|
|
39
|
+
} | null>>;
|
|
40
|
+
export declare function server_create_contact(row: ContactInsert): Promise<import("../types").IWebResponseCompatible<{
|
|
41
|
+
contact_type_id: number | null;
|
|
42
|
+
created_at: string;
|
|
43
|
+
created_by: string | null;
|
|
44
|
+
email: string | null;
|
|
45
|
+
herd_id: number;
|
|
46
|
+
id: number;
|
|
47
|
+
lifecycle: import("../types").Database["public"]["Enums"]["entity_lifecycle"];
|
|
48
|
+
lifecycle_changed_at: string;
|
|
49
|
+
lifecycle_changed_by: string | null;
|
|
50
|
+
lifecycle_reason: string | null;
|
|
51
|
+
name: string;
|
|
52
|
+
notes: string | null;
|
|
53
|
+
phone: string | null;
|
|
54
|
+
radio_frequency: string | null;
|
|
55
|
+
updated_at: string;
|
|
56
|
+
updated_by: string | null;
|
|
57
|
+
} | null>>;
|
|
58
|
+
export declare function server_update_contact(contact_id: number, patch: ContactUpdate): Promise<import("../types").IWebResponseCompatible<{
|
|
59
|
+
contact_type_id: number | null;
|
|
60
|
+
created_at: string;
|
|
61
|
+
created_by: string | null;
|
|
62
|
+
email: string | null;
|
|
63
|
+
herd_id: number;
|
|
64
|
+
id: number;
|
|
65
|
+
lifecycle: import("../types").Database["public"]["Enums"]["entity_lifecycle"];
|
|
66
|
+
lifecycle_changed_at: string;
|
|
67
|
+
lifecycle_changed_by: string | null;
|
|
68
|
+
lifecycle_reason: string | null;
|
|
69
|
+
name: string;
|
|
70
|
+
notes: string | null;
|
|
71
|
+
phone: string | null;
|
|
72
|
+
radio_frequency: string | null;
|
|
73
|
+
updated_at: string;
|
|
74
|
+
updated_by: string | null;
|
|
75
|
+
} | null>>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { newServerClient } from "../supabase/server";
|
|
2
|
+
import { create_contact, get_contact_by_id, get_contacts_by_herd_id, update_contact, } from "./contacts";
|
|
3
|
+
export async function server_get_contacts_by_herd_id(herd_id, options) {
|
|
4
|
+
const client = await newServerClient();
|
|
5
|
+
return get_contacts_by_herd_id(client, herd_id, options);
|
|
6
|
+
}
|
|
7
|
+
export async function server_get_contact_by_id(contact_id) {
|
|
8
|
+
const client = await newServerClient();
|
|
9
|
+
return get_contact_by_id(client, contact_id);
|
|
10
|
+
}
|
|
11
|
+
export async function server_create_contact(row) {
|
|
12
|
+
const client = await newServerClient();
|
|
13
|
+
return create_contact(client, row);
|
|
14
|
+
}
|
|
15
|
+
export async function server_update_contact(contact_id, patch) {
|
|
16
|
+
const client = await newServerClient();
|
|
17
|
+
return update_contact(client, contact_id, patch);
|
|
18
|
+
}
|
|
@@ -1,14 +1,5 @@
|
|
|
1
|
-
"use server";
|
|
2
1
|
import { newServerClient } from "../supabase/server";
|
|
3
|
-
import {
|
|
2
|
+
import { transfer_device_to_herd_query } from "./deviceTransfer.queries";
|
|
4
3
|
export async function transferDeviceToHerd(deviceId, targetHerdId) {
|
|
5
|
-
|
|
6
|
-
const { error } = await client.rpc("transfer_device_to_herd", {
|
|
7
|
-
p_device_id: deviceId,
|
|
8
|
-
p_target_herd_id: targetHerdId,
|
|
9
|
-
});
|
|
10
|
-
if (error) {
|
|
11
|
-
return IWebResponse.error(error.message).to_compatible();
|
|
12
|
-
}
|
|
13
|
-
return IWebResponse.success(true).to_compatible();
|
|
4
|
+
return transfer_device_to_herd_query(await newServerClient(), deviceId, targetHerdId);
|
|
14
5
|
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { SupabaseClient } from "@supabase/supabase-js";
|
|
2
|
+
import { IWebResponseCompatible } from "../types/requests";
|
|
3
|
+
import { Database } from "../types/supabase";
|
|
4
|
+
export declare function transfer_device_to_herd_query(client: SupabaseClient<Database>, deviceId: number, targetHerdId: number): Promise<IWebResponseCompatible<boolean>>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { IWebResponse } from "../types/requests";
|
|
2
|
+
export async function transfer_device_to_herd_query(client, deviceId, targetHerdId) {
|
|
3
|
+
const { error } = await client.rpc("transfer_device_to_herd", {
|
|
4
|
+
p_device_id: deviceId,
|
|
5
|
+
p_target_herd_id: targetHerdId,
|
|
6
|
+
});
|
|
7
|
+
if (error) {
|
|
8
|
+
return IWebResponse.error(error.message).to_compatible();
|
|
9
|
+
}
|
|
10
|
+
return IWebResponse.success(true).to_compatible();
|
|
11
|
+
}
|