pasar de status 2 a status 3 listo
This commit is contained in:
@@ -20,7 +20,7 @@ const registro = async (body) => {
|
||||
throw new Error(
|
||||
'Este servicio se encuentra cancelado o rechazado. No se puede aceptar hasta que se corriga lo necesario.'
|
||||
);
|
||||
else if (res.idStatus !== 1)
|
||||
else if (res.idStatus > 1)
|
||||
throw new Error('Este servicio ya paso por el Registro.');
|
||||
|
||||
let password = encriptar.generarPassword();
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
const validar = require('../../helper/validar');
|
||||
const gmail = require('../../helper/gmail');
|
||||
const correos = require('../../helper/correos');
|
||||
const Servicio = require('../../db/tablas/Servicio');
|
||||
const Usuario = require('../../db/tablas/Usuario');
|
||||
const Programa = require('../../db/tablas/Programa');
|
||||
|
||||
const registroValidado = async (body) => {
|
||||
let idServicio = validar.validarId(body.idServicio);
|
||||
let fechaNacimiento = validar.validarFecha(body.fechaNacimiento);
|
||||
let telefono = validar.validarNumero(body.telefono, 10);
|
||||
let direccion = validar.validar(body.direccion, 'La dirección', 200);
|
||||
|
||||
return Servicio.findOne({
|
||||
where: { idServicio },
|
||||
include: [
|
||||
{ model: Usuario },
|
||||
{ model: Programa, include: [{ model: Usuario }] },
|
||||
],
|
||||
})
|
||||
.then(async (res) => {
|
||||
if (!res) throw new Error('No existe este servicio.');
|
||||
if (res.idStatus === 3)
|
||||
throw new Error('Este servicio ya se encuentra en Registro Validado.');
|
||||
else if (res.idStatus >= 7)
|
||||
throw new Error(
|
||||
'Este servicio se encuentra cancelado o rechazado. Comunicate con COESI para solucionar tu problema.'
|
||||
);
|
||||
else if (res.idStatus > 2)
|
||||
throw new Error('Este servicio ya paso por el Registro Validado.');
|
||||
else if (res.idStatus === 1)
|
||||
throw new Error(
|
||||
'Este servicio aun no puede pasar a Registro Validado.'
|
||||
);
|
||||
|
||||
let correoAlumno = correos.registroValidadoAlumno(res.Usuario.nombre);
|
||||
let correoResponsable = correos.registroValidadoResponsable(
|
||||
res.Usuario.nombre
|
||||
);
|
||||
|
||||
await gmail(correoAlumno.subject, res.correo, correoAlumno.msj);
|
||||
await gmail(
|
||||
correoResponsable.subject,
|
||||
res.Programa.Usuario.usuario,
|
||||
correoResponsable.msj
|
||||
);
|
||||
|
||||
return Servicio.update(
|
||||
{ idStatus: 3, direccion, telefono, fechaNacimiento },
|
||||
{ where: { idServicio } }
|
||||
);
|
||||
})
|
||||
.then((res) => {
|
||||
return {
|
||||
message:
|
||||
'Se cambio de estatus correctamente y se envio un correo al alumno y al responsable de programa.',
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = registroValidado;
|
||||
|
||||
@@ -13,9 +13,10 @@ const yaExiste = (campo) => {
|
||||
throw new Error(`${campo} ya se encuentra en uso.`);
|
||||
};
|
||||
|
||||
const validar = (texto, campo) => {
|
||||
const validar = (texto, campo, length) => {
|
||||
noHay(texto, campo);
|
||||
if (typeof texto !== 'string') noValido(campo);
|
||||
if (typeof texto !== 'string' || (length && texto.length > length))
|
||||
noValido(campo);
|
||||
return texto;
|
||||
};
|
||||
|
||||
@@ -69,13 +70,14 @@ const validarFecha = (fecha) => {
|
||||
return fechaMoment;
|
||||
};
|
||||
|
||||
const validarNumero = (numero) => {
|
||||
const validarNumero = (numero, length) => {
|
||||
let campo = 'El numero';
|
||||
|
||||
noHay(numero, campo);
|
||||
if (
|
||||
typeof numero !== 'string' ||
|
||||
!validator.isNumeric(numero, { no_symbols: true })
|
||||
!validator.isNumeric(numero, { no_symbols: true }) ||
|
||||
(length && numero.length > length)
|
||||
)
|
||||
noValido(campo);
|
||||
return numero;
|
||||
|
||||
@@ -10,6 +10,7 @@ const admin = require('../controller/Servicio/admin');
|
||||
const alumno = require('../controller/Servicio/alumno');
|
||||
const cancelar = require('../controller/Servicio/cancelar');
|
||||
const registro = require('../controller/Servicio/registro');
|
||||
const registroValidado = require('../controller/Servicio/registroValidado');
|
||||
|
||||
app.post(`${route}/nuevo`, upload.single('cartaAceptacion'), (req, res) => {
|
||||
return nuevo(JSON.parse(req.body.alumno), req.file.filename)
|
||||
@@ -81,4 +82,14 @@ app.put(`${route}/registro`, (req, res) => {
|
||||
});
|
||||
});
|
||||
|
||||
app.put(`${route}/registro_validado`, (req, res) => {
|
||||
return registroValidado(req.body)
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
});
|
||||
|
||||
module.exports = app;
|
||||
|
||||
Reference in New Issue
Block a user