Merge branch 'lemuel' of https://repositorio.acatlan.unam.mx/CIDWA/pcpuma_acatlan_api into dev
This commit is contained in:
Generated
+810
-692
File diff suppressed because it is too large
Load Diff
@@ -1,4 +1,3 @@
|
||||
const { validarId } = require('../../helper/validar');
|
||||
const dbPath = '../../db/tablas';
|
||||
const Carrito = require(`${dbPath}/Carrito`);
|
||||
const TipoCarrito = require(`${dbPath}/TipoCarrito`);
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
const Infraccion = require('../../db/tablas/Infraccion');
|
||||
|
||||
const get = async () => Infraccion.findAll();
|
||||
|
||||
module.exports = get;
|
||||
@@ -0,0 +1,50 @@
|
||||
const moment = require('moment');
|
||||
const { validarId, validarTexto } = require('../../helper/validar');
|
||||
const dbPath = '../../db/tablas';
|
||||
const Infraccion = require(`${dbPath}/Infraccion`);
|
||||
const Prestamo = require(`${dbPath}/Prestamo`);
|
||||
const Usuario = require(`${dbPath}/Usuario`);
|
||||
const Multa = require(`${dbPath}/Multa`);
|
||||
|
||||
const multar = async (body) => {
|
||||
const idInfraccion = validarId(body.idInfraccion);
|
||||
const idPrestamo = validarId(body.idPrestamo);
|
||||
const descripcion = validarTexto(body.descripcion, 'La descripción', 500);
|
||||
let prestamo = {};
|
||||
let fechaFin = moment();
|
||||
|
||||
return Infraccion.findOne({ where: { idInfraccion } })
|
||||
.then((res) => {
|
||||
if (!res) throw new Error('No existe esta infracción.');
|
||||
if (res.gravedad == '1') fechaFin.add(7, 'd');
|
||||
else fechaFin.add(100, 'y');
|
||||
return Prestamo.findOne({
|
||||
where: { idPrestamo },
|
||||
include: [{ model: Usuario }],
|
||||
});
|
||||
})
|
||||
.then((res) => {
|
||||
if (!res) throw new Error('No existe este prestamo.');
|
||||
prestamo = res;
|
||||
return Multa.findOne({ where: { idPrestamo } });
|
||||
})
|
||||
.then((res) => {
|
||||
if (res)
|
||||
throw new Error('A este prestamo ya se le ha asignado una multa.');
|
||||
return Usuario.update(
|
||||
{ multa: true },
|
||||
{ where: { idUsuario: prestamo.Usuario.idUsuario } }
|
||||
);
|
||||
})
|
||||
.then((res) =>
|
||||
Multa.create({
|
||||
descripcion,
|
||||
idInfraccion,
|
||||
idPrestamo,
|
||||
fechaFin: fechaFin.format(),
|
||||
})
|
||||
)
|
||||
.then((res) => ({ message: `Se multo correctamente al alumno.` }));
|
||||
};
|
||||
|
||||
module.exports = multar;
|
||||
@@ -0,0 +1,22 @@
|
||||
const { validarId, validarTexto } = require('../../helper/validar');
|
||||
const dbPath = '../../db/tablas';
|
||||
const Reporte = require(`${dbPath}/Reporte`);
|
||||
const Prestamo = require(`${dbPath}/Prestamo`);
|
||||
|
||||
const reportar = async (body) => {
|
||||
const idPrestamo = validarId(body.idPrestamo);
|
||||
const descripcion = validarTexto(body.descripcion, 'La descripción', 500);
|
||||
|
||||
return Prestamo.findOne({ where: { idPrestamo } })
|
||||
.then((res) => {
|
||||
if (!res) throw new Error('No existe este prestamo.');
|
||||
return Reporte.findOne({ where: { idPrestamo } });
|
||||
})
|
||||
.then((res) => {
|
||||
if (res) throw new Error('Ya existe un reporte con este prestamo.');
|
||||
return Reporte.create({ descripcion, idPrestamo });
|
||||
})
|
||||
.then((res) => ({ message: 'Se levanto correctamente el reporte.' }));
|
||||
};
|
||||
|
||||
module.exports = reportar;
|
||||
@@ -0,0 +1,19 @@
|
||||
const { validarId, validarTexto } = require('../../helper/validar');
|
||||
const dbPath = '../../db/tablas';
|
||||
const Reporte = require(`${dbPath}/Reporte`);
|
||||
const Equipo = require(`${dbPath}/Equipo`);
|
||||
|
||||
const reportar = async (body) => {
|
||||
console.log(body);
|
||||
const idEquipo = validarId(body.idEquipo);
|
||||
const descripcion = validarTexto(body.descripcion, 'La descripción', 500);
|
||||
|
||||
return Equipo.findOne({ where: { idEquipo } })
|
||||
.then((res) => {
|
||||
if (!res) throw new Error('No existe este equipo.');
|
||||
return Reporte.create({ descripcion, idEquipo });
|
||||
})
|
||||
.then((res) => ({ message: 'Se levanto correctamente el reporte.' }));
|
||||
};
|
||||
|
||||
module.exports = reportar;
|
||||
@@ -4,10 +4,13 @@ const encriptar = require('../helper/encriptar');
|
||||
const Carrera = require('./tablas/Carrera');
|
||||
const Carrito = require('./tablas/Carrito');
|
||||
const Equipo = require('./tablas/Equipo');
|
||||
const Infraccion = require('./tablas/Infraccion');
|
||||
const Modulo = require('./tablas/Modulo');
|
||||
const Multa = require('./tablas/Multa');
|
||||
const Operador = require('./tablas/Operador');
|
||||
const Prestamo = require('./tablas/Prestamo');
|
||||
const Programa = require('./tablas/Programa');
|
||||
const Reporte = require('./tablas/Reporte');
|
||||
const Status = require('./tablas/Status');
|
||||
const TipoCarrito = require('./tablas/TipoCarrito');
|
||||
const TipoUsuario = require('./tablas/TipoUsuario');
|
||||
@@ -16,6 +19,15 @@ const Usuario = require('./tablas/Usuario');
|
||||
const drop = async () => {
|
||||
console.log('\nPaso 1) Desinstalando la db.'.bold.blue);
|
||||
|
||||
await Reporte.drop();
|
||||
console.log('La tabla Reporte se desinstalo correctamente.'.magenta);
|
||||
|
||||
await Multa.drop();
|
||||
console.log('La tabla Multa se desinstalo correctamente.'.magenta);
|
||||
|
||||
await Infraccion.drop();
|
||||
console.log('La tabla Infraccion se desinstalo correctamente.'.magenta);
|
||||
|
||||
await Prestamo.drop();
|
||||
console.log('La tabla Prestamo se desinstalo correctamente.'.magenta);
|
||||
|
||||
@@ -85,6 +97,15 @@ const sync = async () => {
|
||||
|
||||
await Prestamo.sync();
|
||||
console.log('La tabla Prestamo se instalo correctamente.'.magenta);
|
||||
|
||||
await Infraccion.sync();
|
||||
console.log('La tabla Infraccion se instalo correctamente.'.magenta);
|
||||
|
||||
await Multa.sync();
|
||||
console.log('La tabla Multa se instalo correctamente.'.magenta);
|
||||
|
||||
await Reporte.sync();
|
||||
console.log('La tabla Reporte se instalo correctamente.'.magenta);
|
||||
};
|
||||
|
||||
const dataTipoUsuario = async () => {
|
||||
@@ -156,6 +177,36 @@ const dataAdmin = async () => {
|
||||
});
|
||||
};
|
||||
|
||||
const dataInfraccion = async () => {
|
||||
const data = [
|
||||
{ infraccion: 'Manchas de suciedad', gravedad: '1' },
|
||||
{ infraccion: 'Etiquetas Removidas', gravedad: '1' },
|
||||
{ infraccion: 'Rayon en carcasa', gravedad: '1' },
|
||||
{ infraccion: 'Golpe en carcasa', gravedad: '1' },
|
||||
// { infraccion: '', gravedad: '1' },
|
||||
{ infraccion: 'Daño impacto', gravedad: '2' },
|
||||
{ infraccion: 'Derrame liquido', gravedad: '2' },
|
||||
{ infraccion: 'Trackpad dañado', gravedad: '2' },
|
||||
{ infraccion: 'Equipo abierto', gravedad: '2' },
|
||||
{ infraccion: 'Pantalla estrellada', gravedad: '2' },
|
||||
{ infraccion: 'Teclas faltantes', gravedad: '2' },
|
||||
{ infraccion: 'Teclas dañadas', gravedad: '2' },
|
||||
{ infraccion: 'Puertos dañados', gravedad: '2' },
|
||||
{ infraccion: 'Falta de hardware', gravedad: '2' },
|
||||
{ infraccion: 'Cambio de piezas', gravedad: '2' },
|
||||
// { infraccion: '', gravedad: '2' },
|
||||
];
|
||||
|
||||
console.log('\nPaso 9) Insertando data infraccion.'.bold.blue);
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
await Infraccion.create({
|
||||
infraccion: data[i].infraccion,
|
||||
gravedad: data[i].gravedad,
|
||||
});
|
||||
console.log(`Se agrego la infraccion ${data[i].infraccion}.`.magenta);
|
||||
}
|
||||
};
|
||||
|
||||
const exe = async () => {
|
||||
await drop();
|
||||
await sync();
|
||||
@@ -165,6 +216,7 @@ const exe = async () => {
|
||||
await dataStatus();
|
||||
await dataPrograma();
|
||||
await dataAdmin();
|
||||
await dataInfraccion();
|
||||
|
||||
console.log(
|
||||
'\nSe ha instalado exitosamente la base de datos.\n'.underline.bold.green
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
const { DataTypes, Model } = require('sequelize');
|
||||
const sequelize = require('../../config/sequelize.conf');
|
||||
|
||||
class Infraccion extends Model {}
|
||||
Infraccion.init(
|
||||
{
|
||||
idInfraccion: {
|
||||
type: DataTypes.INTEGER,
|
||||
primaryKey: true,
|
||||
allowNull: false,
|
||||
unique: true,
|
||||
autoIncrement: true,
|
||||
},
|
||||
infraccion: {
|
||||
type: DataTypes.STRING(100),
|
||||
allowNull: false,
|
||||
},
|
||||
gravedad: {
|
||||
type: DataTypes.STRING(1),
|
||||
allowNull: false,
|
||||
},
|
||||
},
|
||||
{
|
||||
sequelize,
|
||||
modelName: 'Infraccion',
|
||||
tableName: 'infraccion',
|
||||
timestamps: false,
|
||||
}
|
||||
);
|
||||
|
||||
module.exports = Infraccion;
|
||||
@@ -0,0 +1,51 @@
|
||||
const { DataTypes, Model } = require('sequelize');
|
||||
const sequelize = require('../../config/sequelize.conf');
|
||||
const Infraccion = require('./Infraccion');
|
||||
const Prestamo = require('./Prestamo');
|
||||
|
||||
class Multa extends Model {}
|
||||
Multa.init(
|
||||
{
|
||||
idMulta: {
|
||||
type: DataTypes.INTEGER,
|
||||
primaryKey: true,
|
||||
allowNull: false,
|
||||
unique: true,
|
||||
autoIncrement: true,
|
||||
},
|
||||
descripcion: {
|
||||
type: DataTypes.STRING(500),
|
||||
allowNull: false,
|
||||
},
|
||||
fechaFin: {
|
||||
type: DataTypes.DATE,
|
||||
allowNull: false,
|
||||
},
|
||||
},
|
||||
{
|
||||
sequelize,
|
||||
modelName: 'Multa',
|
||||
tableName: 'multa',
|
||||
timestamps: true,
|
||||
createdAt: true,
|
||||
updatedAt: false,
|
||||
}
|
||||
);
|
||||
|
||||
Multa.belongsTo(Infraccion, {
|
||||
foreignKey: {
|
||||
name: 'idInfraccion',
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
},
|
||||
});
|
||||
|
||||
Multa.belongsTo(Prestamo, {
|
||||
foreignKey: {
|
||||
name: 'idPrestamo',
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: true,
|
||||
},
|
||||
});
|
||||
|
||||
module.exports = Multa;
|
||||
@@ -0,0 +1,47 @@
|
||||
const { DataTypes, Model } = require('sequelize');
|
||||
const sequelize = require('../../config/sequelize.conf');
|
||||
const Equipo = require('./Equipo');
|
||||
const Prestamo = require('./Prestamo');
|
||||
|
||||
class Reporte extends Model {}
|
||||
Reporte.init(
|
||||
{
|
||||
idReporte: {
|
||||
type: DataTypes.INTEGER,
|
||||
primaryKey: true,
|
||||
allowNull: false,
|
||||
unique: true,
|
||||
autoIncrement: true,
|
||||
},
|
||||
descripcion: {
|
||||
type: DataTypes.STRING(500),
|
||||
allowNull: false,
|
||||
},
|
||||
},
|
||||
{
|
||||
sequelize,
|
||||
modelName: 'Reporte',
|
||||
tableName: 'reporte',
|
||||
timestamps: true,
|
||||
createdAt: true,
|
||||
updatedAt: false,
|
||||
}
|
||||
);
|
||||
|
||||
Reporte.belongsTo(Equipo, {
|
||||
foreignKey: {
|
||||
name: 'idEquipo',
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: true,
|
||||
},
|
||||
});
|
||||
|
||||
Reporte.belongsTo(Prestamo, {
|
||||
foreignKey: {
|
||||
name: 'idPrestamo',
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: true,
|
||||
},
|
||||
});
|
||||
|
||||
module.exports = Reporte;
|
||||
@@ -0,0 +1,21 @@
|
||||
const express = require('express');
|
||||
const app = express();
|
||||
const { verificaToken } = require('../middleware/autentificacion');
|
||||
const route = '/infraccion';
|
||||
const get = require('../controller/Infraccion/get');
|
||||
|
||||
app.get(
|
||||
`${route}`,
|
||||
//verificaToken,
|
||||
(req, res) => {
|
||||
return get()
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
module.exports = app;
|
||||
@@ -0,0 +1,21 @@
|
||||
const express = require('express');
|
||||
const app = express();
|
||||
const { verificaToken } = require('../middleware/autentificacion');
|
||||
const route = '/multa';
|
||||
const multar = require('../controller/Multa/multar');
|
||||
|
||||
app.post(
|
||||
`${route}`,
|
||||
//verificaToken,
|
||||
(req, res) => {
|
||||
return multar(req.body)
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
module.exports = app;
|
||||
@@ -0,0 +1,36 @@
|
||||
const express = require('express');
|
||||
const app = express();
|
||||
const { verificaToken } = require('../middleware/autentificacion');
|
||||
const route = '/reporte';
|
||||
const reportar = require('../controller/Reporte/reportar');
|
||||
const reportarEquipo = require('../controller/Reporte/reportarEquipo');
|
||||
|
||||
app.post(
|
||||
`${route}/reportar`,
|
||||
//verificaToken,
|
||||
(req, res) => {
|
||||
return reportar(req.body)
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
app.post(
|
||||
`${route}/reportar_equipo`,
|
||||
//verificaToken,
|
||||
(req, res) => {
|
||||
return reportarEquipo(req.body)
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
module.exports = app;
|
||||
@@ -3,10 +3,13 @@ const app = express();
|
||||
|
||||
app.use(require('./Carrito'));
|
||||
app.use(require('./Equipo'));
|
||||
app.use(require('./Infraccion'));
|
||||
app.use(require('./Modulo'));
|
||||
app.use(require('./Multa'));
|
||||
app.use(require('./Operador'));
|
||||
app.use(require('./Prestamo'));
|
||||
app.use(require('./Programa'));
|
||||
app.use(require('./Reporte'));
|
||||
app.use(require('./Status'));
|
||||
app.use(require('./TipoCarrito'));
|
||||
app.use(require('./Usuario'));
|
||||
|
||||
Reference in New Issue
Block a user