Fixes
This commit is contained in:
@@ -502,9 +502,22 @@ export async function createCustomerInventoryItem(
|
||||
}
|
||||
|
||||
export async function fetchPlants(token: string, includeArchived = false): Promise<Plant[]> {
|
||||
const plants = await apiRequest<Plant[]>('/api/resource/plants', { token });
|
||||
if (includeArchived) return plants || [];
|
||||
return (plants || []).filter((plant) => !plant.archived);
|
||||
const plants = await apiRequest<Array<Plant & { description?: unknown }>>('/api/resource/plants', { token });
|
||||
const normalized = (plants || []).map((plant) => {
|
||||
const legacyDescription = typeof plant.description === 'string'
|
||||
? plant.description
|
||||
: (plant.description && typeof plant.description === 'object' && 'text' in (plant.description as Record<string, unknown>)
|
||||
? String((plant.description as Record<string, unknown>).text || '')
|
||||
: null);
|
||||
|
||||
return {
|
||||
...plant,
|
||||
description: legacyDescription || null,
|
||||
} as Plant;
|
||||
});
|
||||
|
||||
if (includeArchived) return normalized;
|
||||
return normalized.filter((plant) => !plant.archived);
|
||||
}
|
||||
|
||||
export async function createPlant(
|
||||
@@ -518,7 +531,15 @@ export async function createPlant(
|
||||
return apiRequest<Plant>('/api/resource/plants', {
|
||||
method: 'POST',
|
||||
token,
|
||||
body: payload,
|
||||
body: {
|
||||
name: payload.name,
|
||||
customer: payload.customer ?? null,
|
||||
description: {
|
||||
text: payload.description?.trim() || '',
|
||||
html: '',
|
||||
json: [],
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user