fix: global camelCase mapping for all technical data tables
This commit is contained in:
@@ -1,17 +1,23 @@
|
||||
import { Request, Response } from 'express';
|
||||
import * as dataSheetService from '../services/dataSheetService.js';
|
||||
import { toCamelCase } from '../utils/caseMapper.js';
|
||||
import { IAppUser } from '../middleware/authMiddleware.js';
|
||||
|
||||
export const getAllDataSheets = async (req: Request, res: Response) => {
|
||||
interface AuthRequest extends Request {
|
||||
appUser?: IAppUser;
|
||||
}
|
||||
|
||||
export const getAllDataSheets = async (req: AuthRequest, res: Response) => {
|
||||
try {
|
||||
const organizationId = req.appUser?.organizationId;
|
||||
const sheets = await dataSheetService.getAllDataSheets(organizationId);
|
||||
res.json(sheets);
|
||||
res.json(toCamelCase(sheets));
|
||||
} catch (error: unknown) {
|
||||
res.json([]);
|
||||
}
|
||||
};
|
||||
|
||||
export const extractData = async (req: Request, res: Response) => {
|
||||
export const extractData = async (req: AuthRequest, res: Response) => {
|
||||
try {
|
||||
const file = req.file;
|
||||
if (!file) {
|
||||
@@ -23,20 +29,20 @@ export const extractData = async (req: Request, res: Response) => {
|
||||
}
|
||||
};
|
||||
|
||||
export const createDataSheet = async (req: Request, res: Response) => {
|
||||
export const createDataSheet = async (req: AuthRequest, res: Response) => {
|
||||
try {
|
||||
const organizationId = req.appUser?.organizationId;
|
||||
const newSheet = await dataSheetService.createDataSheet({
|
||||
...req.body,
|
||||
organization_id: organizationId
|
||||
});
|
||||
res.status(201).json(newSheet);
|
||||
res.status(201).json(toCamelCase(newSheet));
|
||||
} catch (error: unknown) {
|
||||
res.json(req.body);
|
||||
}
|
||||
};
|
||||
|
||||
export const deleteDataSheet = async (req: Request, res: Response) => {
|
||||
export const deleteDataSheet = async (req: AuthRequest, res: Response) => {
|
||||
try {
|
||||
const { id } = req.params;
|
||||
await dataSheetService.deleteDataSheet(id as string);
|
||||
@@ -46,17 +52,17 @@ export const deleteDataSheet = async (req: Request, res: Response) => {
|
||||
}
|
||||
};
|
||||
|
||||
export const updateDataSheet = async (req: Request, res: Response) => {
|
||||
export const updateDataSheet = async (req: AuthRequest, res: Response) => {
|
||||
try {
|
||||
const id = req.params.id as string;
|
||||
const updatedSheet = await dataSheetService.updateDataSheet(id, req.body);
|
||||
res.json(updatedSheet || req.body);
|
||||
res.json(toCamelCase(updatedSheet || req.body));
|
||||
} catch (error: unknown) {
|
||||
res.json(req.body);
|
||||
}
|
||||
};
|
||||
|
||||
export const getFile = async (req: Request, res: Response) => {
|
||||
export const getFile = async (req: AuthRequest, res: Response) => {
|
||||
try {
|
||||
res.status(404).json({ error: 'File not found' });
|
||||
} catch (error: unknown) {
|
||||
|
||||
Reference in New Issue
Block a user