@adventurelabs/scout-core 1.4.86 → 1.4.87

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.
@@ -70,7 +70,7 @@ export declare function update_part_status(client: SupabaseClient<Database>, par
70
70
  */
71
71
  export declare function get_parts_by_certificate_id(client: SupabaseClient<Database>, certificate_id: number): Promise<IWebResponseCompatible<IPart[]>>;
72
72
  /**
73
- * Retrieves all active parts for devices in a specific herd
73
+ * Retrieves all active parts for a herd
74
74
  * @param client - Supabase client instance
75
75
  * @param herd_id - ID of the herd to get parts for
76
76
  */
@@ -216,27 +216,18 @@ export async function get_parts_by_certificate_id(client, certificate_id) {
216
216
  return IWebResponse.success(data).to_compatible();
217
217
  }
218
218
  /**
219
- * Retrieves all active parts for devices in a specific herd
219
+ * Retrieves all active parts for a herd
220
220
  * @param client - Supabase client instance
221
221
  * @param herd_id - ID of the herd to get parts for
222
222
  */
223
223
  export async function get_parts_by_herd_id(client, herd_id) {
224
- const { data, error } = await client
225
- .from("parts")
226
- .select(`
227
- *,
228
- devices!parts_device_id_fkey(herd_id)
229
- `)
230
- .eq("devices.herd_id", herd_id)
231
- .eq("lifecycle", "active")
232
- .order("created_at", { ascending: false });
224
+ const { data, error } = await client.rpc("get_parts_for_herd", {
225
+ herd_id_caller: herd_id,
226
+ });
233
227
  if (error) {
234
228
  return IWebResponse.error(error.message).to_compatible();
235
229
  }
236
- if (!data) {
237
- return IWebResponse.error(`No parts found for herd: ${herd_id}`).to_compatible();
238
- }
239
- return IWebResponse.success(data).to_compatible();
230
+ return IWebResponse.success(data ?? []).to_compatible();
240
231
  }
241
232
  /**
242
233
  * Retrieves active parts for all devices across many herds in one query,
@@ -3908,6 +3908,33 @@ export type Database = {
3908
3908
  subject_id: number;
3909
3909
  }[];
3910
3910
  };
3911
+ get_parts_for_herd: {
3912
+ Args: {
3913
+ herd_id_caller: number;
3914
+ };
3915
+ Returns: {
3916
+ certificate_id: number | null;
3917
+ created_at: string;
3918
+ device_id: number | null;
3919
+ health: Database["public"]["Enums"]["health_item"];
3920
+ herd_id: number | null;
3921
+ id: number;
3922
+ lifecycle: Database["public"]["Enums"]["entity_lifecycle"];
3923
+ lifecycle_changed_at: string;
3924
+ lifecycle_changed_by: string | null;
3925
+ lifecycle_reason: string | null;
3926
+ primary_calibration_id: number | null;
3927
+ product_number: string;
3928
+ serial_number: string;
3929
+ updated_at: string | null;
3930
+ }[];
3931
+ SetofOptions: {
3932
+ from: "*";
3933
+ to: "parts";
3934
+ isOneToOne: false;
3935
+ isSetofReturn: true;
3936
+ };
3937
+ };
3911
3938
  get_pins_for_herd: {
3912
3939
  Args: {
3913
3940
  herd_id_caller: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adventurelabs/scout-core",
3
- "version": "1.4.86",
3
+ "version": "1.4.87",
4
4
  "description": "Core utilities and helpers for Adventure Labs Scout applications",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",