SIU_Dran_net/Server/Controller/DAODocumento.js

31 lines
1.0 KiB
JavaScript
Raw Normal View History

2024-05-25 05:38:51 +00:00
import Conexion from './Conexion.js';
2024-06-03 14:13:02 +00:00
import logger from '../utils/logger.js';
import DAORegistro from './DAORegistro.js';
2024-05-25 05:38:51 +00:00
class DAODocumento {
static async agregarDocumento(req, file) {
const conexion = new Conexion();
2024-06-03 04:59:59 +00:00
const conexionEstablecida = await conexion.conectar();
2024-05-25 05:38:51 +00:00
try {
const sql = "INSERT INTO `documento`(`titulo`,`archivo`,`idUsuario`,`valido`) VALUES(?,?,?,?);";
const [result] = await conexionEstablecida.query(sql, [
req.titulo, file, req.idUsuario, 0
]);
2024-06-03 04:59:59 +00:00
if (result.affectedRows > 0) {
2024-06-03 14:13:02 +00:00
2024-06-03 04:59:59 +00:00
await DAORegistro.registrar({ getMatricula: () => req.idUsuario }, 'Agregó documento', new Date().toISOString());
}
2024-05-25 05:38:51 +00:00
return result.affectedRows > 0;
} catch (error) {
2024-06-03 04:59:59 +00:00
logger.error(`Error al agregar documento: ${error.message}`);
2024-05-25 05:38:51 +00:00
throw error;
} finally {
conexion.cerrarConexion();
}
}
}
export default DAODocumento;