feat: Implement CRUD API endpoints for core modules
Adds Express.js routes and Prisma-based handlers for common database operations (Create, Read, Update, Delete) for the following modules: - Empleados (subset of Cliente model) - Asistencias - Tareas (TareaRealizada model) - Planillas Each module's routes are separated into their own files within `api/routes/`. The new routes are registered in `api/server.js`. Basic error handling, including try-catch blocks and checks for common Prisma errors (e.g., P2025 for record not found, P2003 for foreign key violations), has been implemented in each endpoint.
This commit is contained in:
@@ -1,6 +1,13 @@
|
||||
import express from 'express';
|
||||
import { PrismaClient } from './prisma/generated/client/index.js';
|
||||
import { Decimal } from '@prisma/client/runtime/library.js';
|
||||
|
||||
// Import new routers
|
||||
import empleadosRouter from './routes/empleados/empleados.js';
|
||||
import asistenciasRouter from './routes/asistencias/asistencias.js';
|
||||
import tareasRouter from './routes/tareas/tareas.js';
|
||||
import planillasRouter from './routes/planillas/planillas.js';
|
||||
|
||||
BigInt.prototype.toJSON = function () { return this.toString(); };
|
||||
Decimal.prototype.toJSON = function () { return this.toString(); };
|
||||
|
||||
@@ -8,6 +15,12 @@ const prisma = new PrismaClient();
|
||||
export const app = express();
|
||||
app.use(express.json());
|
||||
|
||||
// Mount new routers
|
||||
app.use('/api/empleados', empleadosRouter);
|
||||
app.use('/api/asistencias', asistenciasRouter);
|
||||
app.use('/api/tareas', tareasRouter);
|
||||
app.use('/api/planillas', planillasRouter);
|
||||
|
||||
app.get('/api/test', (req, res) => res.json({ message: 'Hello World' }));
|
||||
|
||||
app.post('/api/clientes/random', async (_req, res) => {
|
||||
|
||||
Reference in New Issue
Block a user