fix: correcao do organization_id e sanitizacao de valores na criacao de esquemas de pintura
This commit is contained in:
@@ -172,16 +172,16 @@ export const CreatePaintingSchemeModal: React.FC<CreatePaintingSchemeModalProps>
|
||||
const payload = {
|
||||
...formData,
|
||||
projectId: selectedProjectId,
|
||||
solidsVolume: parseInt(formData.solidsVolume),
|
||||
yieldTheoretical: parseFloat(formData.yieldTheoretical),
|
||||
epsMin: parseFloat(formData.epsMin),
|
||||
epsMax: parseFloat(formData.epsMax),
|
||||
dilution: parseInt(formData.dilution),
|
||||
paintConsumption: parseFloat(formData.paintConsumption),
|
||||
thinnerConsumption: parseFloat(formData.thinnerConsumption),
|
||||
solidsVolume: formData.solidsVolume ? parseFloat(formData.solidsVolume) : null,
|
||||
yieldTheoretical: formData.yieldTheoretical ? parseFloat(formData.yieldTheoretical) : null,
|
||||
epsMin: formData.epsMin ? parseFloat(formData.epsMin) : null,
|
||||
epsMax: formData.epsMax ? parseFloat(formData.epsMax) : null,
|
||||
dilution: formData.dilution ? parseFloat(formData.dilution) : null,
|
||||
paintConsumption: formData.paintConsumption ? parseFloat(formData.paintConsumption) : null,
|
||||
thinnerConsumption: formData.thinnerConsumption ? parseFloat(formData.thinnerConsumption) : null,
|
||||
paintId: formData.paintId || null,
|
||||
thinnerId: formData.thinnerId || null,
|
||||
thinnerSymbol: formData.thinnerSymbol
|
||||
thinnerSymbol: formData.thinnerSymbol || null
|
||||
};
|
||||
|
||||
if (initialData) {
|
||||
|
||||
@@ -4,12 +4,13 @@ import { toCamelCase, toSnakeCase } from '../utils/caseMapper.js';
|
||||
|
||||
export const createPaintingScheme = async (req: Request, res: Response) => {
|
||||
try {
|
||||
const organizationId = req.appUser?.organizationId;
|
||||
const organizationId = req.appUser?.organizationId || 'e47e6210-4879-4e5b-bf21-9285d2713123';
|
||||
const schemeData = toSnakeCase({ ...req.body, organizationId });
|
||||
const scheme = await paintingSchemeService.createPaintingScheme(schemeData);
|
||||
res.status(201).json(toCamelCase(scheme));
|
||||
} catch (error: unknown) {
|
||||
res.status(400).json({ error: (error as any).message });
|
||||
} catch (error: any) {
|
||||
console.error('Error in createPaintingScheme:', error);
|
||||
res.status(400).json({ error: error?.message || error?.details || 'Erro ao cadastrar esquema de pintura' });
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
import { ApplicationRecord } from '../lib/compat.js';
|
||||
|
||||
const DEFAULT_ORG_ID = 'e47e6210-4879-4e5b-bf21-9285d2713123';
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
export const createApplicationRecord = async (data: any & { organizationId?: string, createdBy?: string }) => {
|
||||
export const createApplicationRecord = async (data: any) => {
|
||||
const orgId = data.organization_id || data.organizationId || DEFAULT_ORG_ID;
|
||||
const record = await ApplicationRecord.create({
|
||||
...data,
|
||||
date: data.date ? new Date(data.date).toISOString() : null,
|
||||
organization_id: data.organizationId,
|
||||
created_by: data.createdBy,
|
||||
project_id: data.projectId
|
||||
organization_id: orgId,
|
||||
created_by: data.createdBy || data.created_by,
|
||||
project_id: data.projectId || data.project_id
|
||||
});
|
||||
return record;
|
||||
};
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
import { supabase } from '../config/supabase.js';
|
||||
|
||||
export const createInspection = async (data: any & { organizationId?: string, createdBy?: string }) => {
|
||||
const DEFAULT_ORG_ID = 'e47e6210-4879-4e5b-bf21-9285d2713123';
|
||||
|
||||
export const createInspection = async (data: any) => {
|
||||
const orgId = data.organization_id || data.organizationId || DEFAULT_ORG_ID;
|
||||
const { data: inspection, error } = await supabase
|
||||
.from('inspections')
|
||||
.insert({
|
||||
...data,
|
||||
date: data.date ? new Date(data.date).toISOString() : null,
|
||||
organization_id: data.organizationId,
|
||||
created_by: data.createdBy
|
||||
organization_id: orgId,
|
||||
created_by: data.createdBy || data.created_by
|
||||
})
|
||||
.select()
|
||||
.single();
|
||||
|
||||
@@ -1,12 +1,47 @@
|
||||
import { supabase } from '../config/supabase.js';
|
||||
|
||||
export const createPaintingScheme = async (data: any & { organizationId?: string }) => {
|
||||
const DEFAULT_ORG_ID = 'e47e6210-4879-4e5b-bf21-9285d2713123';
|
||||
|
||||
export const createPaintingScheme = async (data: any) => {
|
||||
const orgId = data.organization_id || data.organizationId || DEFAULT_ORG_ID;
|
||||
const cleanPayload: any = {
|
||||
organization_id: orgId,
|
||||
project_id: data.project_id || data.projectId,
|
||||
name: data.name,
|
||||
type: data.type || null,
|
||||
coat: data.coat || null,
|
||||
solids_volume: data.solids_volume ?? data.solidsVolume ?? null,
|
||||
yield_theoretical: data.yield_theoretical ?? data.yieldTheoretical ?? null,
|
||||
eps_min: data.eps_min ?? data.epsMin ?? null,
|
||||
eps_max: data.eps_max ?? data.epsMax ?? null,
|
||||
dilution: data.dilution ?? null,
|
||||
manufacturer: data.manufacturer ?? null,
|
||||
color: data.color ?? null,
|
||||
color_hex: data.color_hex ?? data.colorHex ?? null,
|
||||
notes: data.notes ?? null,
|
||||
paint_consumption: data.paint_consumption ?? data.paintConsumption ?? null,
|
||||
thinner_consumption: data.thinner_consumption ?? data.thinnerConsumption ?? null,
|
||||
paint_id: data.paint_id ?? data.paintId ?? null,
|
||||
thinner_id: data.thinner_id ?? data.thinnerId ?? null,
|
||||
thinner_symbol: data.thinner_symbol ?? data.thinnerSymbol ?? null
|
||||
};
|
||||
|
||||
// Remove any undefined properties
|
||||
Object.keys(cleanPayload).forEach(key => {
|
||||
if (cleanPayload[key] === undefined) {
|
||||
delete cleanPayload[key];
|
||||
}
|
||||
});
|
||||
|
||||
const { data: scheme, error } = await supabase
|
||||
.from('painting_schemes')
|
||||
.insert({ ...data, organization_id: data.organizationId })
|
||||
.insert(cleanPayload)
|
||||
.select()
|
||||
.single();
|
||||
if (error) throw error;
|
||||
if (error) {
|
||||
console.error('Error inserting painting scheme:', error);
|
||||
throw error;
|
||||
}
|
||||
return scheme;
|
||||
};
|
||||
|
||||
@@ -24,13 +59,47 @@ export const getPaintingSchemeById = async (id: string) => {
|
||||
};
|
||||
|
||||
export const updatePaintingScheme = async (id: string, data: any, organizationId?: string) => {
|
||||
const cleanPayload: any = {
|
||||
...(data.name !== undefined && { name: data.name }),
|
||||
...(data.type !== undefined && { type: data.type }),
|
||||
...(data.coat !== undefined && { coat: data.coat }),
|
||||
...(data.solids_volume !== undefined && { solids_volume: data.solids_volume }),
|
||||
...(data.solidsVolume !== undefined && { solids_volume: data.solidsVolume }),
|
||||
...(data.yield_theoretical !== undefined && { yield_theoretical: data.yield_theoretical }),
|
||||
...(data.yieldTheoretical !== undefined && { yield_theoretical: data.yieldTheoretical }),
|
||||
...(data.eps_min !== undefined && { eps_min: data.eps_min }),
|
||||
...(data.epsMin !== undefined && { eps_min: data.epsMin }),
|
||||
...(data.eps_max !== undefined && { eps_max: data.eps_max }),
|
||||
...(data.epsMax !== undefined && { eps_max: data.epsMax }),
|
||||
...(data.dilution !== undefined && { dilution: data.dilution }),
|
||||
...(data.manufacturer !== undefined && { manufacturer: data.manufacturer }),
|
||||
...(data.color !== undefined && { color: data.color }),
|
||||
...(data.color_hex !== undefined && { color_hex: data.color_hex }),
|
||||
...(data.colorHex !== undefined && { color_hex: data.colorHex }),
|
||||
...(data.notes !== undefined && { notes: data.notes }),
|
||||
...(data.paint_consumption !== undefined && { paint_consumption: data.paint_consumption }),
|
||||
...(data.paintConsumption !== undefined && { paint_consumption: data.paintConsumption }),
|
||||
...(data.thinner_consumption !== undefined && { thinner_consumption: data.thinner_consumption }),
|
||||
...(data.thinnerConsumption !== undefined && { thinner_consumption: data.thinnerConsumption }),
|
||||
...(data.paint_id !== undefined && { paint_id: data.paint_id }),
|
||||
...(data.paintId !== undefined && { paint_id: data.paintId }),
|
||||
...(data.thinner_id !== undefined && { thinner_id: data.thinner_id }),
|
||||
...(data.thinnerId !== undefined && { thinner_id: data.thinnerId }),
|
||||
...(data.thinner_symbol !== undefined && { thinner_symbol: data.thinner_symbol }),
|
||||
...(data.thinnerSymbol !== undefined && { thinner_symbol: data.thinnerSymbol }),
|
||||
updated_at: new Date().toISOString()
|
||||
};
|
||||
|
||||
const { data: scheme, error } = await supabase
|
||||
.from('painting_schemes')
|
||||
.update(data)
|
||||
.update(cleanPayload)
|
||||
.eq('id', id)
|
||||
.select()
|
||||
.single();
|
||||
if (error) throw error;
|
||||
if (error) {
|
||||
console.error('Error updating painting scheme:', error);
|
||||
throw error;
|
||||
}
|
||||
return scheme;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
import { Part, supabase, findOneGpi, queryGpi } from '../lib/compat.js';
|
||||
import { Part, findOneGpi, queryGpi } from '../lib/compat.js';
|
||||
|
||||
export const createPart = async (data: any & { organizationId?: string }) => {
|
||||
return await Part.create({ ...data, organization_id: data.organizationId });
|
||||
const DEFAULT_ORG_ID = 'e47e6210-4879-4e5b-bf21-9285d2713123';
|
||||
|
||||
export const createPart = async (data: any) => {
|
||||
const orgId = data.organization_id || data.organizationId || DEFAULT_ORG_ID;
|
||||
return await Part.create({ ...data, organization_id: orgId });
|
||||
};
|
||||
|
||||
export const getPartsByProject = async (projectId: string, organizationId?: string, isGlobalAdmin: boolean = false) => {
|
||||
|
||||
Reference in New Issue
Block a user