🚀 Auto-deploy: GPI atualizado em 03/04/2026 20:14:10
This commit is contained in:
@@ -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: [] });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user