diff --git a/src/client/pages/StockDashboard.tsx b/src/client/pages/StockDashboard.tsx
index 0acd2be..6700f8e 100644
--- a/src/client/pages/StockDashboard.tsx
+++ b/src/client/pages/StockDashboard.tsx
@@ -79,11 +79,12 @@ export const StockDashboard: React.FC = () => {
await Promise.all(
items.map(async (item) => {
try {
- const movements = await stockService.getMovements(item._id!);
- movementsMap.set(item._id!, movements);
+ const itemId = item.id || (item as any)._id;
+ if (!itemId) return;
+ const movements = await stockService.getMovements(itemId);
+ movementsMap.set(itemId, movements);
} catch (error) {
- console.error(`Error fetching movements for ${item._id}:`, error);
- movementsMap.set(item._id!, []);
+ console.error(`Error fetching movements for ${item.id}:`, error);
}
})
);
@@ -117,8 +118,8 @@ export const StockDashboard: React.FC = () => {
const manufacturer = typeof item.dataSheetId === 'object' ? (item.dataSheetId as any).manufacturer : '';
return (
- item.rrNumber.toLowerCase().includes(searchLower) ||
- item.batchNumber.toLowerCase().includes(searchLower) ||
+ (item.rrNumber || '').toLowerCase().includes(searchLower) ||
+ (item.batchNumber || '').toLowerCase().includes(searchLower) ||
productName.toLowerCase().includes(searchLower) ||
manufacturer.toLowerCase().includes(searchLower)
);
@@ -130,7 +131,8 @@ export const StockDashboard: React.FC = () => {
filteredItems.forEach(item => {
const productName = typeof item.dataSheetId === 'object' ? (item.dataSheetId as any).name : 'Unknown';
const manufacturer = typeof item.dataSheetId === 'object' ? (item.dataSheetId as any).manufacturer : '';
- const key = `${(item.dataSheetId as any)._id || item.dataSheetId}-${item.color}`;
+ const dsId = (item.dataSheetId as any).id || (item.dataSheetId as any)._id || item.dataSheetId;
+ const key = `${dsId}-${item.color}`;
if (!groups.has(key)) {
groups.set(key, {
@@ -295,7 +297,7 @@ export const StockDashboard: React.FC = () => {
{isLowStock && }
- {group.totalQty.toFixed(1)} {group.unit}
+ {(group.totalQty || 0).toFixed(1)} {group.unit}
{group.minStock > 0 && (
@@ -313,11 +315,11 @@ export const StockDashboard: React.FC = () => {
{/* Expanded Item Rows */}
{isExpanded && group.items.map(item => {
+ const itemId = item.id || (item as any)._id;
const isExpired = item.expirationDate && new Date(item.expirationDate) < new Date();
- // Check individual item min stock for legacy reasons? No, rely on group.
return (
-
+
| {/* Indentation */}
@@ -371,7 +373,7 @@ export const StockDashboard: React.FC = () => {
@@ -558,9 +558,9 @@ export const YieldStudyDashboard: React.FC = () => {
const sheet = findSheet(selectedStudy.dataSheetId);
let sv = sheet?.solidsVolume || 60;
if (sv <= 1) sv *= 100;
- const dilFactor = 100 - selectedStudy.dilutionPercent;
+ const dilFactor = 100 - (selectedStudy.dilutionPercent || 0);
const svFactor = sv * dilFactor;
- return svFactor > 0 ? (selectedStudy.targetDft * 10000 / svFactor).toFixed(1) : '0';
+ return svFactor > 0 ? ((selectedStudy.targetDft || 0) * 10000 / svFactor).toFixed(1) : '0';
})()
} µm
@@ -572,19 +572,19 @@ export const YieldStudyDashboard: React.FC = () => {
const hasRealSV = sheet?.solidsVolume && sheet.solidsVolume > 0;
let sv = sheet?.solidsVolume || 60;
if (sv <= 1) sv *= 100;
- return (
- <>
-
- SV da Tinta {hasRealSV ? '✓' : '⚠️'}
-
-
- {sv.toFixed(0)} %
-
-
- {hasRealSV ? 'Sólidos por Volume' : 'Valor padrão (edite a ficha)'}
-
- >
- );
+ return (
+ <>
+
+ SV da Tinta {hasRealSV ? '✓' : '⚠️'}
+
+
+ {(sv || 0).toFixed(0)} %
+
+
+ {hasRealSV ? 'Sólidos por Volume' : 'Valor padrão (edite a ficha)'}
+
+ >
+ );
})()}
@@ -617,13 +617,13 @@ export const YieldStudyDashboard: React.FC = () => {
Taxa Média
- {selectedStudy.totalWeight > 0 ? ((selectedStudy.estimatedPaintVolume / selectedStudy.totalWeight).toFixed(2)) : '0.00'} L/t
+ {selectedStudy.totalWeight > 0 ? (((selectedStudy.estimatedPaintVolume || 0) / selectedStudy.totalWeight).toFixed(2)) : '0.00'} L/t
Peso Total
- {selectedStudy.totalWeight.toFixed(2)} TON
+ {(selectedStudy.totalWeight || 0).toFixed(2)} TON
@@ -926,7 +926,7 @@ export const YieldStudyDashboard: React.FC = () => {
Peso Total (Ton)
- {selectedStudy.totalWeight.toFixed(2)}
+ {(selectedStudy.totalWeight || 0).toFixed(2)}
Soma das categorias
@@ -941,7 +941,7 @@ export const YieldStudyDashboard: React.FC = () => {
Taxa Média
- {selectedStudy.totalWeight > 0 ? (selectedStudy.estimatedPaintVolume / selectedStudy.totalWeight).toFixed(2) : '0.00'} L/t
+ {selectedStudy.totalWeight > 0 ? ((selectedStudy.estimatedPaintVolume || 0) / selectedStudy.totalWeight).toFixed(2) : '0.00'} L/t
Rendimento Global
@@ -969,7 +969,7 @@ export const YieldStudyDashboard: React.FC = () => {
|
{cat.name}
|
- {cat.weight.toFixed(2)} |
+ {(cat.weight || 0).toFixed(2)} |
{cat.area ? Math.round(cat.area) : '--'} |
{cat.historicalYield} |
{cat.efficiency}% |
diff --git a/src/server/controllers/yieldStudyController.ts b/src/server/controllers/yieldStudyController.ts
index 8f6a714..19e7325 100644
--- a/src/server/controllers/yieldStudyController.ts
+++ b/src/server/controllers/yieldStudyController.ts
@@ -1,11 +1,12 @@
import { Request, Response } from 'express';
import { supabase } from '../config/supabase.js';
+import { toCamelCase, toSnakeCase } from '../utils/caseMapper.js';
export const getAllStudies = async (req: Request, res: Response) => {
try {
const { data, error } = await supabase.from('yield_studies').select('*');
if (error && error.code !== '42P01') throw error;
- res.json(data || []);
+ res.json(toCamelCase(data || []));
} catch (error: unknown) {
res.json([]);
}
@@ -13,15 +14,16 @@ export const getAllStudies = async (req: Request, res: Response) => {
export const createStudy = async (req: Request, res: Response) => {
try {
+ const payload = { ...req.body, organization_id: req.appUser?.organizationId };
const { data, error } = await supabase
.from('yield_studies')
- .insert({ ...req.body, organization_id: req.appUser?.organizationId })
+ .insert(toSnakeCase(payload))
.select()
.single();
if (error) throw error;
- res.status(201).json(data);
+ res.status(201).json(toCamelCase(data));
} catch (error: unknown) {
- res.json(req.body);
+ res.status(400).json({ error: (error as any).message });
}
};
@@ -29,14 +31,14 @@ export const updateStudy = async (req: Request, res: Response) => {
try {
const { data, error } = await supabase
.from('yield_studies')
- .update(req.body)
+ .update(toSnakeCase(req.body))
.eq('id', req.params.id)
.select()
.single();
if (error) throw error;
- res.json(data);
+ res.json(toCamelCase(data));
} catch (error: unknown) {
- res.json(req.body);
+ res.status(400).json({ error: (error as any).message });
}
};
@@ -45,6 +47,6 @@ export const deleteStudy = async (req: Request, res: Response) => {
await supabase.from('yield_studies').delete().eq('id', req.params.id);
res.status(204).send();
} catch (error: unknown) {
- res.status(204).send();
+ res.status(500).json({ error: (error as any).message });
}
};
\ No newline at end of file
|