nuevo servicio especial listo
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
const { Op } = require('sequelize');
|
||||
const drive = require('../../helper/drive');
|
||||
const CasoEspecial = require('../../db/tablas/CasoEspecial');
|
||||
const Usuario = require('../../db/tablas/Usuario');
|
||||
const Carrera = require('../../db/tablas/Carrera');
|
||||
const validar = require('../../helper/validar');
|
||||
|
||||
const nuevo = async (body, file) => {
|
||||
console.log('Hola');
|
||||
|
||||
const idUsuario = validar.validarId(body.idUsuario);
|
||||
const idCarrera = validar.validarId(body.idCarrera);
|
||||
const idStatus = validar.validarId(body.idStatus);
|
||||
const numeroCuenta = validar.validarNumeroCuenta(body.numeroCuenta);
|
||||
const creditos = validar.validarNumero(body.creditos);
|
||||
const correo = validar.validarCorreo(body.correo);
|
||||
const fechaInicio = validar.validarFecha(body.fechaInicio);
|
||||
const fechaFin = validar.validarFecha(body.fechaFin);
|
||||
const fechaNacimiento = validar.validarFecha(body.fechaNacimiento);
|
||||
const path = `./server/uploads/${validar.validar(file, 'El archivo', 1000)}`;
|
||||
const institucion = body.institucion
|
||||
? validar.validarTexto(body.institucion, 'El texto institucion.', 100)
|
||||
: '';
|
||||
const dependencia = body.dependencia
|
||||
? validar.validarTexto(body.dependencia, 'El texto dependencia.', 100)
|
||||
: '';
|
||||
const incapacidad = body.incapacidad
|
||||
? validar.validarTexto(body.incapacidad, 'El texto incapacidad.', 100)
|
||||
: '';
|
||||
const direccion = validar.validarAlfanumerico(
|
||||
body.direccion,
|
||||
'La dirección',
|
||||
200
|
||||
);
|
||||
let carpeta = '';
|
||||
|
||||
return Usuario.findOne({
|
||||
where: { idUsuario },
|
||||
})
|
||||
.then((res) => {
|
||||
if (!res) throw new Error('Este alumno no existe en la db.');
|
||||
if (res.idTipoUsuario !== 3)
|
||||
throw new Error('Este usuario no es de tipo Alumno.');
|
||||
return Carrera.findOne({ where: { idCarrera } });
|
||||
})
|
||||
.then((res) => {
|
||||
if (!res) throw new Error('Esta carrera no existe en la db.');
|
||||
return CasoEspecial.findOne({
|
||||
where: { idUsuario },
|
||||
});
|
||||
})
|
||||
.then(async (res) => {
|
||||
if (res) throw new Error('Este alumno ya tienen un Servicio Especial.');
|
||||
return drive.folder(numeroCuenta);
|
||||
})
|
||||
.then((res) => {
|
||||
carpeta = res;
|
||||
return drive.uploadFile(
|
||||
path,
|
||||
`archivos.rar`,
|
||||
'application/x-rar',
|
||||
carpeta
|
||||
);
|
||||
})
|
||||
.then((res) =>
|
||||
CasoEspecial.create({
|
||||
idUsuario,
|
||||
idCarrera,
|
||||
idStatus,
|
||||
creditos,
|
||||
correo,
|
||||
institucion,
|
||||
dependencia,
|
||||
incapacidad,
|
||||
direccion,
|
||||
fechaInicio,
|
||||
fechaFin,
|
||||
fechaNacimiento,
|
||||
carpeta,
|
||||
archivoZip: res,
|
||||
})
|
||||
)
|
||||
.then((res) => ({
|
||||
message: `Se ha registro el Servicio Especial correctamente.`,
|
||||
}));
|
||||
};
|
||||
|
||||
module.exports = nuevo;
|
||||
|
||||
@@ -20,7 +20,7 @@ const nuevo = async (body, file) => {
|
||||
? validar.validarTexto(
|
||||
body.programaInterno,
|
||||
'El texto programa interno.',
|
||||
80
|
||||
250
|
||||
)
|
||||
: '';
|
||||
const profesor = body.profesor
|
||||
@@ -44,7 +44,7 @@ const nuevo = async (body, file) => {
|
||||
.then((res) => {
|
||||
if (!res) throw new Error('Esta carrera no existe en la db.');
|
||||
return Servicio.findOne({
|
||||
where: { idUsuario, idStatus: { [Op.ne]: 10 } },
|
||||
where: { idUsuario, idStatus: { [Op.lt]: 10 } },
|
||||
});
|
||||
})
|
||||
.then(async (res) => {
|
||||
|
||||
@@ -2,13 +2,12 @@ const { DataTypes, Model } = require('sequelize');
|
||||
const sequelize = require('../../config/sequelize.conf');
|
||||
const Usuario = require('./Usuario');
|
||||
const Carrera = require('./Carrera');
|
||||
const Programa = require('./Programa');
|
||||
const Status = require('./Status');
|
||||
|
||||
class CasoEspecial extends Model {}
|
||||
CasoEspecial.init(
|
||||
{
|
||||
idServicio: {
|
||||
idCasoEspecial: {
|
||||
type: DataTypes.INTEGER,
|
||||
primaryKey: true,
|
||||
allowNull: false,
|
||||
@@ -23,15 +22,24 @@ CasoEspecial.init(
|
||||
type: DataTypes.STRING(60),
|
||||
allowNull: false,
|
||||
},
|
||||
telefono: {
|
||||
type: DataTypes.STRING(15),
|
||||
institucion: {
|
||||
type: DataTypes.STRING(100),
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
},
|
||||
dependencia: {
|
||||
type: DataTypes.STRING(100),
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
},
|
||||
incapacidad: {
|
||||
type: DataTypes.STRING(100),
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
},
|
||||
direccion: {
|
||||
type: DataTypes.STRING(200),
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
allowNull: false,
|
||||
},
|
||||
fechaInicio: {
|
||||
type: DataTypes.DATE,
|
||||
@@ -39,13 +47,11 @@ CasoEspecial.init(
|
||||
},
|
||||
fechaFin: {
|
||||
type: DataTypes.DATE,
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
allowNull: false,
|
||||
},
|
||||
fechaNacimiento: {
|
||||
type: DataTypes.DATE,
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
allowNull: false,
|
||||
},
|
||||
carpeta: {
|
||||
type: DataTypes.STRING(60),
|
||||
@@ -89,12 +95,4 @@ CasoEspecial.belongsTo(Status, {
|
||||
},
|
||||
});
|
||||
|
||||
CasoEspecial.belongsTo(Programa, {
|
||||
foreignKey: {
|
||||
name: 'idPrograma',
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
},
|
||||
});
|
||||
|
||||
module.exports = CasoEspecial;
|
||||
|
||||
@@ -41,7 +41,7 @@ Servicio.init(
|
||||
},
|
||||
fechaFin: {
|
||||
type: DataTypes.DATE,
|
||||
allowNull: true,
|
||||
allowNull: true, // eliminar
|
||||
defaultValue: null,
|
||||
},
|
||||
fechaNacimiento: {
|
||||
@@ -52,9 +52,8 @@ Servicio.init(
|
||||
carpeta: {
|
||||
type: DataTypes.STRING(60),
|
||||
// allowNull:false,
|
||||
allowNull: true,
|
||||
// comentar linea de abajo
|
||||
defaultValue: null,
|
||||
allowNull: true, // eliminar
|
||||
defaultValue: null, // eliminar
|
||||
},
|
||||
cartaAceptacion: {
|
||||
type: DataTypes.STRING(60),
|
||||
|
||||
@@ -166,11 +166,7 @@ const archivosFicheros = async () => {
|
||||
do {
|
||||
let response = await list(pageToken);
|
||||
|
||||
for (let i = 0; i < response.files.length; i++) {
|
||||
if (response.files[i].mimeType === 'application/vnd.google-apps.folder')
|
||||
carpetas.push(response.files[i]);
|
||||
else pdf.push(response.files[i]);
|
||||
}
|
||||
console.log(response);
|
||||
if (response.nextPageToken) pageToken = response.nextPageToken;
|
||||
else pageToken = '';
|
||||
} while (pageToken);
|
||||
@@ -183,7 +179,4 @@ const archivosFicheros = async () => {
|
||||
module.exports = {
|
||||
folder,
|
||||
uploadFile,
|
||||
deleteFile,
|
||||
update,
|
||||
archivosFicheros,
|
||||
};
|
||||
|
||||
@@ -4,10 +4,60 @@ const multer = require('multer');
|
||||
const app = express();
|
||||
const upload = multer({ dest: 'server/uploads' });
|
||||
const { verificaToken } = require('../middleware/autentificacion');
|
||||
const route = '/casoEspecial';
|
||||
const route = '/caso_especial';
|
||||
const nuevo = require('../controller/CasoEspecial/nuevo');
|
||||
const serviciosEspeciales = require('../controller/CasoEspecial/serviciosEspeciales');
|
||||
const liberacion = require('../controller/CasoEspecial/liberacion');
|
||||
|
||||
const eliminarArchivo = (filename) => {
|
||||
fs.unlinkSync(`./server/uploads/${filename}`);
|
||||
};
|
||||
|
||||
app.post(
|
||||
`${route}/nuevo`,
|
||||
// verificaToken,
|
||||
upload.single('archivos'),
|
||||
(req, res) => {
|
||||
console.log(req.body.alumno);
|
||||
console.log(JSON.parse(req.body.alumno));
|
||||
console.log(typeof req.body.alumno);
|
||||
return nuevo(JSON.parse(req.body.alumno), req.file.filename)
|
||||
.then((data) => {
|
||||
res.status(201).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
if (req.file.filename) eliminarArchivo(req.file.filename);
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
app.get(
|
||||
`${route}/servicios_especiales`,
|
||||
// verificaToken,
|
||||
(req, res) => {
|
||||
return serviciosEspeciales(req.query)
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
app.put(
|
||||
`${route}/liberacion`,
|
||||
// verificaToken,
|
||||
(req, res) => {
|
||||
return liberacion(req.body)
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
module.exports = app;
|
||||
|
||||
@@ -37,7 +37,6 @@ app.post(
|
||||
})
|
||||
.catch((err) => {
|
||||
if (req.file.filename) eliminarArchivo(req.file.filename);
|
||||
// fs.unlinkSync(`./server/uploads/${req.file.filename}`);
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
}
|
||||
@@ -124,7 +123,6 @@ app.put(
|
||||
})
|
||||
.catch((err) => {
|
||||
if (req.file.filename) eliminarArchivo(req.file.filename);
|
||||
// fs.unlinkSync(`./server/uploads/${req.file.filename}`);
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
}
|
||||
@@ -141,7 +139,6 @@ app.put(
|
||||
})
|
||||
.catch((err) => {
|
||||
if (req.file.filename) eliminarArchivo(req.file.filename);
|
||||
// fs.unlinkSync(`./server/uploads/${req.file.filename}`);
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
}
|
||||
@@ -158,7 +155,6 @@ app.put(
|
||||
})
|
||||
.catch((err) => {
|
||||
if (req.file.filename) eliminarArchivo(req.file.filename);
|
||||
// fs.unlinkSync(`./server/uploads/${req.file.filename}`);
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ const app = express();
|
||||
app.use(require('./Status'));
|
||||
app.use(require('./Usuario'));
|
||||
app.use(require('./Servicio'));
|
||||
// app.use(require('./CasoEspecial'));
|
||||
app.use(require('./CasoEspecial'));
|
||||
app.use(require('./Programa'));
|
||||
app.use(require('./CuestionarioAlumno'));
|
||||
app.use(require('./CuestionarioPrograma'));
|
||||
|
||||
Reference in New Issue
Block a user