🚀 Auto-deploy: GPI atualizado em 03/04/2026 20:14:10
This commit is contained in:
@@ -10,6 +10,7 @@ import type { PaintingScheme } from '../types';
|
||||
import { useAuth } from '../context/useAuth';
|
||||
|
||||
export const SchemesList: React.FC = () => {
|
||||
const { isAdmin } = useAuth();
|
||||
const [schemes, setSchemes] = useState<PaintingScheme[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [editItem, setEditItem] = useState<PaintingScheme | undefined>(undefined);
|
||||
@@ -17,8 +18,6 @@ export const SchemesList: React.FC = () => {
|
||||
const [isModalOpen, setIsModalOpen] = useState(false);
|
||||
const [isCloneModalOpen, setIsCloneModalOpen] = useState(false);
|
||||
const [searchTerm, setSearchTerm] = useState('');
|
||||
const { appUser } = useAuth();
|
||||
const isAdmin = appUser?.email === 'admtracksteel@gmail.com' || appUser?.role === 'admin';
|
||||
|
||||
useEffect(() => {
|
||||
fetchSchemes();
|
||||
@@ -135,7 +134,7 @@ export const SchemesList: React.FC = () => {
|
||||
onChange={(e) => setSearchTerm(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
{isAdmin && (
|
||||
{isAdmin() && (
|
||||
<Button onClick={() => { setEditItem(undefined); setIsModalOpen(true); }} size="lg" className="shadow-primary/30 h-14">
|
||||
<Plus className="w-5 h-5 mr-2" />
|
||||
Novo Esquema
|
||||
@@ -151,7 +150,7 @@ export const SchemesList: React.FC = () => {
|
||||
keyExtractor={(item) => item.id}
|
||||
titleAccessor="name"
|
||||
subtitleAccessor={(item) => `${item.manufacturer || ''} ${item.type || ''}`}
|
||||
actionRender={(item) => isAdmin ? (
|
||||
actionRender={(item) => isAdmin() ? (
|
||||
<div className="flex gap-1 justify-end">
|
||||
<button
|
||||
onClick={() => { setCloneItem(item); setIsCloneModalOpen(true); }}
|
||||
|
||||
@@ -1,18 +1,21 @@
|
||||
import { Request, Response } from 'express';
|
||||
import * as inspectionService from '../services/inspectionService.js';
|
||||
import { notificationService } from '../services/notificationService.js';
|
||||
import { toCamelCase, toSnakeCase } from '../utils/caseMapper.js';
|
||||
|
||||
export const createInspection = async (req: Request, res: Response) => {
|
||||
try {
|
||||
const organizationId = req.appUser?.organizationId;
|
||||
const createdBy = req.appUser?.email || 'guest';
|
||||
|
||||
const inspection = await inspectionService.createInspection({
|
||||
const payload = toSnakeCase({
|
||||
...req.body,
|
||||
organizationId,
|
||||
createdBy
|
||||
});
|
||||
|
||||
const inspection = await inspectionService.createInspection(payload);
|
||||
|
||||
if (req.body.appearance === 'rejected' && organizationId) {
|
||||
try {
|
||||
await notificationService.create({
|
||||
@@ -25,7 +28,7 @@ export const createInspection = async (req: Request, res: Response) => {
|
||||
} catch (e) { /* ignore notification errors */ }
|
||||
}
|
||||
|
||||
res.status(201).json(inspection);
|
||||
res.status(201).json(toCamelCase(inspection));
|
||||
} catch (error: unknown) {
|
||||
const message = error instanceof Error ? error.message : 'Unknown error';
|
||||
res.status(500).json({ error: message });
|
||||
@@ -37,7 +40,7 @@ export const getInspectionsByProject = async (req: Request, res: Response) => {
|
||||
const { projectId } = req.params;
|
||||
const organizationId = req.appUser?.organizationId;
|
||||
const inspections = await inspectionService.getInspectionsByProject(projectId as string, organizationId);
|
||||
res.json(inspections);
|
||||
res.json(toCamelCase(inspections || []));
|
||||
} catch (error: unknown) {
|
||||
res.json([]);
|
||||
}
|
||||
@@ -47,10 +50,10 @@ export const updateInspection = async (req: Request, res: Response) => {
|
||||
try {
|
||||
const inspection = await inspectionService.updateInspection(
|
||||
req.params.id as string,
|
||||
req.body
|
||||
toSnakeCase(req.body)
|
||||
);
|
||||
if (!inspection) return res.status(403).json({ error: 'Não autorizado ou não encontrado.' });
|
||||
res.json(inspection);
|
||||
res.json(toCamelCase(inspection));
|
||||
} catch (error: unknown) {
|
||||
const message = error instanceof Error ? error.message : 'Unknown error';
|
||||
res.status(500).json({ error: message });
|
||||
@@ -59,7 +62,7 @@ export const updateInspection = async (req: Request, res: Response) => {
|
||||
|
||||
export const deleteInspection = async (req: Request, res: Response) => {
|
||||
try {
|
||||
const success = await inspectionService.deleteInspection(req.params.id as string);
|
||||
await inspectionService.deleteInspection(req.params.id as string);
|
||||
res.status(204).send();
|
||||
} catch (error: unknown) {
|
||||
res.status(204).send();
|
||||
@@ -72,7 +75,7 @@ export const getAllInspections = async (req: Request, res: Response) => {
|
||||
const inspections = organizationId
|
||||
? await inspectionService.getInspectionsByOrganization(organizationId)
|
||||
: await inspectionService.getInspectionStats();
|
||||
res.json(inspections);
|
||||
res.json(toCamelCase(inspections || []));
|
||||
} catch (error: unknown) {
|
||||
res.json({ total: 0, inspections: [] });
|
||||
}
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
import { Request, Response } from 'express';
|
||||
import * as paintingSchemeService from '../services/paintingSchemeService.js';
|
||||
import { toCamelCase, toSnakeCase } from '../utils/caseMapper.js';
|
||||
|
||||
export const createPaintingScheme = async (req: Request, res: Response) => {
|
||||
try {
|
||||
const organizationId = req.appUser?.organizationId;
|
||||
const scheme = await paintingSchemeService.createPaintingScheme({ ...req.body, organizationId });
|
||||
res.status(201).json(scheme);
|
||||
const schemeData = toSnakeCase({ ...req.body, organizationId });
|
||||
const scheme = await paintingSchemeService.createPaintingScheme(schemeData);
|
||||
res.status(201).json(toCamelCase(scheme));
|
||||
} catch (error: unknown) {
|
||||
res.json(req.body);
|
||||
res.status(400).json({ error: (error as any).message });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -15,7 +17,7 @@ export const getPaintingSchemesByProject = async (req: Request, res: Response) =
|
||||
try {
|
||||
const { projectId } = req.params;
|
||||
const schemes = await paintingSchemeService.getPaintingSchemesByProject(projectId as string);
|
||||
res.json(schemes);
|
||||
res.json(toCamelCase(schemes || []));
|
||||
} catch (error: unknown) {
|
||||
res.json([]);
|
||||
}
|
||||
@@ -23,10 +25,10 @@ export const getPaintingSchemesByProject = async (req: Request, res: Response) =
|
||||
|
||||
export const updatePaintingScheme = async (req: Request, res: Response) => {
|
||||
try {
|
||||
const scheme = await paintingSchemeService.updatePaintingScheme(req.params.id as string, req.body);
|
||||
res.json(scheme || req.body);
|
||||
const scheme = await paintingSchemeService.updatePaintingScheme(req.params.id as string, toSnakeCase(req.body));
|
||||
res.json(toCamelCase(scheme || req.body));
|
||||
} catch (error: unknown) {
|
||||
res.json(req.body);
|
||||
res.status(400).json({ error: (error as any).message });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -35,7 +37,7 @@ export const deletePaintingScheme = async (req: Request, res: Response) => {
|
||||
await paintingSchemeService.deletePaintingScheme(req.params.id as string);
|
||||
res.status(204).send();
|
||||
} catch (error: unknown) {
|
||||
res.status(204).send();
|
||||
res.status(500).json({ error: (error as any).message });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -43,7 +45,7 @@ export const getAllPaintingSchemes = async (req: Request, res: Response) => {
|
||||
try {
|
||||
const organizationId = req.appUser?.organizationId;
|
||||
const schemes = await paintingSchemeService.getAllSchemes(organizationId);
|
||||
res.json(schemes);
|
||||
res.json(toCamelCase(schemes || []));
|
||||
} catch (error: unknown) {
|
||||
res.json([]);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { Request, Response } from 'express';
|
||||
import * as partService from '../services/partService.js';
|
||||
import { IAppUser } from '../middleware/authMiddleware.js';
|
||||
import { toCamelCase, toSnakeCase } from '../utils/caseMapper.js';
|
||||
|
||||
interface AuthRequest extends Request {
|
||||
appUser?: IAppUser;
|
||||
@@ -8,14 +9,12 @@ interface AuthRequest extends Request {
|
||||
|
||||
export const createPart = async (req: AuthRequest, res: Response) => {
|
||||
try {
|
||||
console.log('[CREATE PART] Received data:', JSON.stringify(req.body, null, 2));
|
||||
const organizationId = req.appUser?.organizationId;
|
||||
const part = await partService.createPart({ ...req.body, organizationId });
|
||||
console.log('[CREATE PART] Success:', part);
|
||||
res.status(201).json(part);
|
||||
const payload = toSnakeCase({ ...req.body, organizationId });
|
||||
const part = await partService.createPart(payload);
|
||||
res.status(201).json(toCamelCase(part));
|
||||
} catch (error: unknown) {
|
||||
const message = error instanceof Error ? error.message : 'Unknown error';
|
||||
console.error('[CREATE PART] Error:', message);
|
||||
res.status(500).json({ error: message });
|
||||
}
|
||||
};
|
||||
@@ -26,7 +25,7 @@ export const getPartsByProject = async (req: AuthRequest, res: Response) => {
|
||||
const organizationId = req.appUser?.organizationId;
|
||||
const isGlobalAdmin = req.appUser?.email === 'admtracksteel@gmail.com';
|
||||
const parts = await partService.getPartsByProject(projectId as string, organizationId, isGlobalAdmin);
|
||||
res.json(parts);
|
||||
res.json(toCamelCase(parts || []));
|
||||
} catch (error: unknown) {
|
||||
const message = error instanceof Error ? error.message : 'Unknown error';
|
||||
res.status(500).json({ error: message });
|
||||
@@ -37,8 +36,8 @@ export const updatePart = async (req: AuthRequest, res: Response) => {
|
||||
try {
|
||||
const organizationId = req.appUser?.organizationId;
|
||||
const isGlobalAdmin = req.appUser?.email === 'admtracksteel@gmail.com';
|
||||
const part = await partService.updatePart(req.params.id as string, req.body, organizationId, isGlobalAdmin);
|
||||
res.json(part);
|
||||
const part = await partService.updatePart(req.params.id as string, toSnakeCase(req.body), organizationId, isGlobalAdmin);
|
||||
res.json(toCamelCase(part));
|
||||
} catch (error: unknown) {
|
||||
const message = error instanceof Error ? error.message : 'Unknown error';
|
||||
res.status(500).json({ error: message });
|
||||
@@ -47,9 +46,7 @@ export const updatePart = async (req: AuthRequest, res: Response) => {
|
||||
|
||||
export const deletePart = async (req: AuthRequest, res: Response) => {
|
||||
try {
|
||||
const organizationId = req.appUser?.organizationId;
|
||||
const isGlobalAdmin = req.appUser?.email === 'admtracksteel@gmail.com';
|
||||
await partService.deletePart(req.params.id as string, organizationId, isGlobalAdmin);
|
||||
await partService.deletePart(req.params.id as string);
|
||||
res.status(204).send();
|
||||
} catch (error: unknown) {
|
||||
const message = error instanceof Error ? error.message : 'Unknown error';
|
||||
@@ -60,9 +57,9 @@ export const deletePart = async (req: AuthRequest, res: Response) => {
|
||||
export const getAllParts = async (req: AuthRequest, res: Response) => {
|
||||
try {
|
||||
const organizationId = req.appUser?.organizationId;
|
||||
const isGlobalAdmin = req.appUser?.email === 'admtracksteel@gmail.com';
|
||||
const parts = await partService.getAllParts(organizationId, isGlobalAdmin);
|
||||
res.json(parts);
|
||||
if (!organizationId) return res.json([]);
|
||||
const parts = await partService.getPartsByOrganization(organizationId);
|
||||
res.json(toCamelCase(parts || []));
|
||||
} catch (error: unknown) {
|
||||
const message = error instanceof Error ? error.message : 'Unknown error';
|
||||
res.status(500).json({ error: message });
|
||||
|
||||
Reference in New Issue
Block a user