31 lines
1.0 KiB
JavaScript
31 lines
1.0 KiB
JavaScript
import Conexion from './Conexion.js';
|
|
import logger from '../utils/logger.js';
|
|
import DAORegistro from './DAORegistro.js';
|
|
|
|
class DAODocumento {
|
|
static async agregarDocumento(req, file) {
|
|
const conexion = new Conexion();
|
|
const conexionEstablecida = await conexion.conectar();
|
|
try {
|
|
const sql = "INSERT INTO `documento`(`titulo`,`archivo`,`idUsuario`,`valido`) VALUES(?,?,?,?);";
|
|
const [result] = await conexionEstablecida.query(sql, [
|
|
req.titulo, file, req.idUsuario, 0
|
|
]);
|
|
|
|
if (result.affectedRows > 0) {
|
|
|
|
await DAORegistro.registrar({ getMatricula: () => req.idUsuario }, 'Agregó documento', new Date().toISOString());
|
|
}
|
|
|
|
return result.affectedRows > 0;
|
|
} catch (error) {
|
|
logger.error(`Error al agregar documento: ${error.message}`);
|
|
throw error;
|
|
} finally {
|
|
conexion.cerrarConexion();
|
|
}
|
|
}
|
|
}
|
|
|
|
export default DAODocumento;
|