nuevo servicio

This commit is contained in:
2020-11-16 12:47:46 -06:00
parent c49ef87cfc
commit 8e97cf4605
7 changed files with 117 additions and 18 deletions
+51 -8
View File
@@ -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;
+11 -2
View File
@@ -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) => {
+9 -2
View File
@@ -53,6 +53,10 @@ Servicio.init(
allowNull: true,
defaultValue: null,
},
carpeta: {
type: DataTypes.STRING(30),
allowNull: false,
},
cartaAceptacion: {
type: DataTypes.STRING(30),
allowNull: false,
@@ -112,6 +116,7 @@ Servicio.belongsTo(Status, {
name: 'idStatus',
type: DataTypes.INTEGER,
allowNull: false,
defaultValue: 1,
},
});
@@ -127,7 +132,8 @@ Servicio.belongsTo(CuestionarioAlumno, {
foreignKey: {
name: 'idCuestionarioAlumno',
type: DataTypes.INTEGER,
allowNull: false,
allowNull: true,
defaultValue: null,
},
});
@@ -135,7 +141,8 @@ Servicio.belongsTo(CuestionarioPrograma, {
foreignKey: {
name: 'idCuestionarioPrograma',
type: DataTypes.INTEGER,
allowNull: false,
allowNull: true,
defaultValue: null,
},
});
+14 -3
View File
@@ -1,4 +1,5 @@
const validator = require('validator');
const moment = require('moment');
const noValido = (campo) => {
throw new Error(`El ${campo} no es valido.`);
@@ -53,12 +54,22 @@ const validarNumeroCuenta = (numeroCuenta) => {
return numeroCuenta;
};
const validarFecha = (fecha) => {
let campo = 'fecha';
let fechaMoment = moment(fecha);
noHay(fecha, campo);
if (fechaMoment.isValid()) noValido(campo);
return fechaMoment;
};
module.exports = {
noValido,
yaExiste,
noHay,
validarCorreo,
validarId,
validarTexto,
yaExiste,
noValido,
noHay,
validarNumeroCuenta,
validarFecha,
};
+27
View File
@@ -0,0 +1,27 @@
const express = require('express');
const app = express();
const route = '/servicio';
const nuevo = require('../controller/Servicio/nuevo');
// const login = require('../controller/Usuario/login');
app.post(`${route}/nuevo`, (req, res) => {
return nuevo(req.body)
.then((data) => {
res.status(201).json(data);
})
.catch((err) => {
res.status(400).json({ message: err.message });
});
});
// app.post(`${route}/login`, (req, res) => {
// return login(req.body)
// .then((data) => {
// res.status(201).json(data);
// })
// .catch((err) => {
// res.status(400).json({ message: err.message });
// });
// });
module.exports = app;
+3 -3
View File
@@ -2,11 +2,11 @@ const express = require('express');
const app = express();
const route = '/usuario';
const escolares = require('../controller/Usuario/escolares');
// const create = require('../controller/Usuario/create');
// const nuevo = require('../controller/Servicio/ser');
// const login = require('../controller/Usuario/login');
// app.post(`${route}/create`, (req, res) => {
// return create(req.body)
// app.post(`${route}/nuevo`, (req, res) => {
// return nuevo(req.body)
// .then((data) => {
// res.status(201).json(data);
// })
+2
View File
@@ -4,5 +4,7 @@ const app = express();
// app.use(require('./'))
app.use(require('./Status'));
app.use(require('./Usuario'));
app.use(require('./Servicio'));
module.exports = app;