nuevo servicio
This commit is contained in:
@@ -1,15 +1,58 @@
|
||||
const { Op } = require('sequelize');
|
||||
const Servicio = require('../../db/tablas/Servicio');
|
||||
const Usuario = require('../../db/tablas/Usuario');
|
||||
const Programa = require('../../db/tablas/Programa');
|
||||
const Carrera = require('../../db/tablas/Carrera');
|
||||
const validar = require('../../helper/validar');
|
||||
|
||||
const nuevo = (body) => {
|
||||
let idPrograma = body.idUsuarioResponsable;
|
||||
let idAlumno = body.idAlumno;
|
||||
let numeroCuenta = body.numeroCuenta;
|
||||
const nuevo = async (body) => {
|
||||
let idUsuario = validar.validarId(body.idUsuarioAlumno);
|
||||
let idPrograma = validar.validarId(body.idUsuarioResponsable);
|
||||
let idCarrera = validar.validarId(body.idCarrera);
|
||||
let creditos = body.creditos;
|
||||
let nombre = body.nombre;
|
||||
let correo = body.correo;
|
||||
let fechaInicio = boyd.fechaInicio;
|
||||
let fechaFin = boyd.fechaFin;
|
||||
let nombre = validar.validarTexto(body.nombre);
|
||||
let correo = validar.validarCorreo(body.correo);
|
||||
let fechaInicio = validar.validarFecha(boyd.fechaInicio);
|
||||
let fechaFin = validar.validarFecha(boyd.fechaFin);
|
||||
let cartaAceptacion = body.cartaAceptacion;
|
||||
|
||||
return Usuario.findOne({
|
||||
where: { [Op.and]: [{ idUsuario }, { idTipoUsuario: 3 }] },
|
||||
})
|
||||
.then((res) => {
|
||||
if (!res) throw new Error('Este alumno no existe en la db.');
|
||||
return Programa.findOne({ where: { idPrograma } });
|
||||
})
|
||||
.then((res) => {
|
||||
if (!res) throw new Error('Este programa no existe en la db.');
|
||||
return Carrera.findOne({ where: { idCarrera } });
|
||||
})
|
||||
.then((res) => {
|
||||
if (!res) throw new Error('Esta carrera no existe en la db.');
|
||||
return Servicio.findOne({
|
||||
where: { [Op.and]: [{ idUsuario }, { idStatus: { [Op.ne]: 10 } }] },
|
||||
});
|
||||
})
|
||||
.then((res) => {
|
||||
if (res)
|
||||
throw new Error('Este alumno ya tienen un Servicio Social activo.');
|
||||
return Servicio.create({
|
||||
idUsuario,
|
||||
idPrograma,
|
||||
idCarrera,
|
||||
creditos,
|
||||
nombre,
|
||||
correo,
|
||||
fechaInicio,
|
||||
fechaFin,
|
||||
cartaAceptacion,
|
||||
});
|
||||
})
|
||||
.then((res) => {
|
||||
return {
|
||||
message: `Se Pre-Registro correctamente al alumno ${res.nombre}`,
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = nuevo;
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
const validar = require('../../helper/validar');
|
||||
require('../../config/config');
|
||||
const Usuario = require('../../db/tablas/Usuario');
|
||||
const axios = require('axios');
|
||||
const Usuario = require('../../db/tablas/Usuario');
|
||||
const Carrera = require('../../db/tablas/Carrera');
|
||||
|
||||
const escolares = async (body) => {
|
||||
let numeroCuenta = validar.validarNumeroCuenta(body.numeroCuenta);
|
||||
@@ -21,9 +22,17 @@ const escolares = async (body) => {
|
||||
);
|
||||
alumno = {
|
||||
nombre: data.nombre.trim(),
|
||||
carrera: data.carrconst.trim(),
|
||||
creditos: data.avance,
|
||||
carrera: data.carrconst.trim(),
|
||||
};
|
||||
return Carrera.findOne({ where: { carrera: alumno.carrera } });
|
||||
})
|
||||
.then((res) => {
|
||||
if (!res) return Carrera.create({ carrera: alumno.carrera });
|
||||
return res;
|
||||
})
|
||||
.then((res) => {
|
||||
alumno.idCarrera = res.idCarrera;
|
||||
return Usuario.findOne({ where: { usuario: numeroCuenta } });
|
||||
})
|
||||
.then((res) => {
|
||||
|
||||
Reference in New Issue
Block a user