🚀 Auto-deploy: GPI atualizado em 03/04/2026 19:56:31
This commit is contained in:
@@ -75,3 +75,51 @@ export const deleteStockItem = async (req: AuthRequest, res: Response) => {
|
||||
res.status(204).send();
|
||||
}
|
||||
};
|
||||
export const adjustStock = async (req: AuthRequest, res: Response) => {
|
||||
try {
|
||||
const { id } = req.params;
|
||||
const { data, error } = await supabase.from('stock_items').update(req.body).eq('id', id).select().single();
|
||||
if (error) throw error;
|
||||
res.json(toCamelCase(data));
|
||||
} catch (error: unknown) {
|
||||
res.status(500).json({ error: error instanceof Error ? error.message : 'Unknown error' });
|
||||
}
|
||||
};
|
||||
|
||||
export const consumeStock = async (req: AuthRequest, res: Response) => {
|
||||
try {
|
||||
const { id } = req.params;
|
||||
const { quantity } = req.body;
|
||||
const { data: item, error: fetchError } = await supabase.from('stock_items').select('quantity').eq('id', id).single();
|
||||
if (fetchError) throw fetchError;
|
||||
|
||||
const newQuantity = (item.quantity || 0) - (quantity || 0);
|
||||
const { data, error } = await supabase.from('stock_items').update({ quantity: newQuantity }).eq('id', id).select().single();
|
||||
if (error) throw error;
|
||||
|
||||
res.json(toCamelCase(data));
|
||||
} catch (error: unknown) {
|
||||
res.status(500).json({ error: error instanceof Error ? error.message : 'Unknown error' });
|
||||
}
|
||||
};
|
||||
|
||||
export const updateStockMovement = async (req: AuthRequest, res: Response) => {
|
||||
try {
|
||||
const { id } = req.params;
|
||||
const { data, error } = await supabase.from('stock_movements').update(req.body).eq('id', id).select().single();
|
||||
if (error) throw error;
|
||||
res.json(toCamelCase(data));
|
||||
} catch (error: unknown) {
|
||||
res.status(500).json({ error: error instanceof Error ? error.message : 'Unknown error' });
|
||||
}
|
||||
};
|
||||
|
||||
export const deleteStockMovement = async (req: AuthRequest, res: Response) => {
|
||||
try {
|
||||
const { id } = req.params;
|
||||
await supabase.from('stock_movements').delete().eq('id', id);
|
||||
res.status(204).send();
|
||||
} catch (error: unknown) {
|
||||
res.status(500).json({ error: error instanceof Error ? error.message : 'Unknown error' });
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user