Files
2025-02-27 15:38:46 -06:00

67 lines
2.2 KiB
JavaScript

const helperPath = '../../helper';
const correos = require(`${helperPath}/correos`);
const encriptar = require(`${helperPath}/encriptar`);
const gmail = require(`${helperPath}/gmail`);
const validar = require(`${helperPath}/validar`);
const dbPath = '../../db/tablas';
const Servicio = require(`${dbPath}/Servicio`);
const Usuario = require(`${dbPath}/Usuario`);
const registro = async (body) => {
const idServicio = validar.validarNumeroEntero(
body.idServicio,
'id servicio'
);
let password = encriptar.generarPassword(); // esta genera la contraseña
if (process.env.MODE == "pruebas") password = 'qwertyui'
// const password = pass //encriptar.encriptar(pass)
let correo = {};
let idUsuario;
return Servicio.findOne({
where: { idServicio },
include: [{ model: Usuario }],
})
.then((res) => {
if (!res) throw new Error('No existe este Servicio Social.');
switch (res.idStatus) {
case 1:
correo = correos.preRegistro(password, res.Usuario.nombre);
idUsuario = res.idUsuario;
return gmail(correo.subject, res.correo, correo.msj);
case 2:
throw new Error('Este Servicio Social ya se encuentra en Registro.');
case 3:
case 4:
case 5:
throw new Error('Este Servicio Social ya paso por el Registro.');
case 6:
throw new Error('Este Servicio Social ya finalizó.');
case 7:
case 8:
case 9:
throw new Error(
'Este Servicio Social se encuentra rechazado. No se puede aceptar hasta que se corriga lo necesario.'
);
case 10:
throw new Error('Este Servicio Social fue cancelado.');
default:
throw new Error('Id status no valido.');
}
})
.then((res) => {
return Usuario.update(
{ password: encriptar.encriptar(password), activo: true },
{ where: { idUsuario } }
);
})
.then((res) => Servicio.update({ idStatus: 2 }, { where: { idServicio } }))
.then((res) => ({
message:
'Se cambio de estatus correctamente y se envio un correo al alumno con sus credenciales.'
}));
};
module.exports = registro;