Migrate major controllers and services to PostgreSQL (gpi schema), fix build errors, add file and audit log support
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
import { Request, Response } from 'express';
|
||||
import * as inspectionService from '../services/inspectionService.js';
|
||||
import { notificationService } from '../services/notificationService.js';
|
||||
import '../middleware/roleMiddleware.js'; // Ensure type augmentation
|
||||
import * as fileService from '../services/fileService.js';
|
||||
import fs from 'fs';
|
||||
|
||||
export const createInspection = async (req: Request, res: Response) => {
|
||||
try {
|
||||
@@ -13,14 +14,13 @@ export const createInspection = async (req: Request, res: Response) => {
|
||||
createdBy
|
||||
});
|
||||
|
||||
// Notificação de Inspeção Reprovada
|
||||
if (req.body.appearance === 'rejected' && organizationId) {
|
||||
await notificationService.create({
|
||||
organizationId,
|
||||
title: 'Inspeção Reprovada',
|
||||
message: `Uma inspeção foi reprovada na obra (ID: ${req.body.projectId}).`,
|
||||
type: 'error',
|
||||
metadata: { inspectionId: inspection._id, projectId: req.body.projectId, triggerType: 'inspection_rejected' }
|
||||
metadata: { inspectionId: inspection.id, projectId: req.body.projectId, triggerType: 'inspection_rejected' }
|
||||
});
|
||||
}
|
||||
|
||||
@@ -105,9 +105,15 @@ export const uploadPhoto = async (req: Request, res: Response) => {
|
||||
return res.status(400).json({ error: 'No file uploaded' });
|
||||
}
|
||||
|
||||
// Return the public URL for the file
|
||||
// Assuming 'uploads' is served statically at /uploads
|
||||
const fileUrl = `/uploads/${req.file.filename}`;
|
||||
const buffer = fs.readFileSync(req.file.path);
|
||||
const savedFile = await fileService.saveFile(req.file.originalname, req.file.mimetype, buffer);
|
||||
|
||||
// Clean up temp file
|
||||
fs.unlinkSync(req.file.path);
|
||||
|
||||
// We'll use /api/datasheets/file/:id to serve these if we use the same endpoint
|
||||
// or create a new general /api/files/:id
|
||||
const fileUrl = `/api/datasheets/file/${savedFile.id}`;
|
||||
|
||||
res.json({ url: fileUrl });
|
||||
} catch (error: unknown) {
|
||||
|
||||
Reference in New Issue
Block a user