Commit inicial - Sistema de Gestion Hotelera Hacienda San Angel
- Backend Node.js/Express con PostgreSQL - Frontend React 19 con Vite - Docker Compose para orquestacion - Documentacion completa en README.md - Scripts SQL para base de datos - Configuracion de ejemplo (.env.example)
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
const pool = require('../db/connection');
|
||||
|
||||
const getReportContracts = async (req, res) => {
|
||||
try {
|
||||
// Leer query params con valores por defecto
|
||||
const page = parseInt(req.query.page) || 1; // Página actual
|
||||
const limit = parseInt(req.query.limit) || 10; // Cantidad por página
|
||||
const offset = (page - 1) * limit; // Desde dónde empezar
|
||||
|
||||
// Llamamos a la función con LIMIT y OFFSET
|
||||
const result = await pool.query(
|
||||
`SELECT * FROM reportcontracts() LIMIT $1 OFFSET $2`,
|
||||
[limit, offset]
|
||||
);
|
||||
|
||||
// Obtener total para calcular páginas
|
||||
const totalResult = await pool.query('SELECT COUNT(*) FROM contracts');
|
||||
const total = parseInt(totalResult.rows[0].count);
|
||||
const totalPages = Math.ceil(total / limit);
|
||||
|
||||
const contracts = result.rows.map(con => ({
|
||||
name_employee: con.id_contract,
|
||||
position_employee: con.name_employee,
|
||||
area_employee: con.position_employee,
|
||||
contract_end: con.end_contract,
|
||||
daily_pay: con.daily_pay,
|
||||
status_contracts: con.status_contracts
|
||||
}));
|
||||
|
||||
res.json({
|
||||
page,
|
||||
limit,
|
||||
total,
|
||||
totalPages,
|
||||
data: contracts
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
res.status(500).json({ message: 'Error al obtener los contratos' });
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = { getReportContracts };
|
||||
Reference in New Issue
Block a user