tabla motivo
This commit is contained in:
@@ -2,6 +2,7 @@ const validar = require('../../helper/validar');
|
||||
const dbPath = '../../db/tablas';
|
||||
const Carrito = require(`${dbPath}/Carrito`);
|
||||
const Equipo = require(`${dbPath}/Equipo`);
|
||||
const Motivo = require(`${dbPath}/Motivo`);
|
||||
const Programa = require(`${dbPath}/Programa`);
|
||||
const Status = require(`${dbPath}/Status`);
|
||||
|
||||
@@ -20,14 +21,20 @@ const update = async (body) => {
|
||||
const idPrograma = body.idPrograma
|
||||
? validar.validarNumeroEntero(body.idPrograma, 'id programa', true)
|
||||
: '';
|
||||
const motivo = body.motivo
|
||||
? validar.validarAlfanumerico(body.motivo, 'motivo', true, 500)
|
||||
: '';
|
||||
let update = {};
|
||||
|
||||
return Status.findOne({ where: { idStatus } })
|
||||
.then((res) => {
|
||||
if (idStatus) {
|
||||
if (!res) throw new Error('No existe este status.');
|
||||
if (idStatus >= 6 && !motivo)
|
||||
throw new Error('No se mando el motivo de cambio de status.');
|
||||
update.idStatus = idStatus;
|
||||
}
|
||||
|
||||
return Carrito.findOne({ where: { idCarrito } });
|
||||
})
|
||||
.then((res) => {
|
||||
@@ -46,8 +53,9 @@ const update = async (body) => {
|
||||
throw new Error('No se envió nada para actualizar.');
|
||||
return Equipo.findOne({ where: { idEquipo } });
|
||||
})
|
||||
.then((res) => {
|
||||
.then(async (res) => {
|
||||
if (!res) throw new Error('No existe este equipo.');
|
||||
if (idStatus >= 6) await Motivo.create({ motivo, idEquipo, idStatus });
|
||||
return Equipo.update(update, { where: { idEquipo } });
|
||||
})
|
||||
.then(() => ({ message: 'Se actualizó correctamente el equipo.' }));
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
const { validarNumeroEntero } = require('../../helper/validar');
|
||||
const dbPath = '../../db/tablas';
|
||||
const Motivo = require(`${dbPath}/Motivo`);
|
||||
const Equipo = require(`${dbPath}/Equipo`);
|
||||
const Status = require(`${dbPath}/Status`);
|
||||
|
||||
const historialMotivosEquipo = async (body) => {
|
||||
const pagina = validarNumeroEntero(body.pagina, 'página', false);
|
||||
const idEquipo = validarNumeroEntero(body.idEquipo, 'id equipo', true);
|
||||
|
||||
return Motivo.findAndCountAll({
|
||||
include: [
|
||||
{
|
||||
model: Equipo,
|
||||
where: { idEquipo },
|
||||
// attributes: [],
|
||||
},
|
||||
{ model: Status },
|
||||
],
|
||||
attributes: ['idMotivo', 'motivo'],
|
||||
limit: 25,
|
||||
offset: 25 * (pagina - 1),
|
||||
order: [['idMotivo', 'DESC']],
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = historialMotivosEquipo;
|
||||
@@ -8,6 +8,7 @@ const Prestamo = require(`${dbPath}/Prestamo`);
|
||||
const cancelarOperador = async (body) => {
|
||||
const idPrestamo = validarNumeroEntero(body.idPrestamo, 'id préstamo', true);
|
||||
const idOperador = validarNumeroEntero(body.idOperador, 'id operador', true);
|
||||
const motivo = validar.validarAlfanumerico(body.motivo, 'motivo', true, 500);
|
||||
let idUsuario = null;
|
||||
|
||||
return Operador.findOne({ where: { idOperador } })
|
||||
@@ -15,15 +16,16 @@ const cancelarOperador = async (body) => {
|
||||
if (!res) throw new Error('No existe este operador.');
|
||||
return Prestamo.findOne({ where: { idPrestamo } });
|
||||
})
|
||||
.then((res) => {
|
||||
.then(async (res) => {
|
||||
if (!res) throw new Error('Este préstamo no existe.');
|
||||
idUsuario = res.idUsuario;
|
||||
if (!res.activo)
|
||||
throw new Error(
|
||||
'Este préstamo ya no esta activo, no se puede cancelar.'
|
||||
);
|
||||
await Motivo.create({ motivo, idEquipo: res.idEquipo, idStatus: 7 });
|
||||
return Equipo.update(
|
||||
{ idStatus: 4 },
|
||||
{ idStatus: 7 },
|
||||
{ where: { idEquipo: res.idEquipo } }
|
||||
);
|
||||
})
|
||||
|
||||
@@ -6,6 +6,7 @@ const Carrito = require('./tablas/Carrito');
|
||||
const Equipo = require('./tablas/Equipo');
|
||||
const Infraccion = require('./tablas/Infraccion');
|
||||
const Modulo = require('./tablas/Modulo');
|
||||
const Motivo = require('./tablas/Motivo');
|
||||
const Multa = require('./tablas/Multa');
|
||||
const Operador = require('./tablas/Operador');
|
||||
const Prestamo = require('./tablas/Prestamo');
|
||||
@@ -27,6 +28,9 @@ const drop = async () => {
|
||||
await Prestamo.drop();
|
||||
console.log('La tabla Prestamo se desinstalo correctamente.'.magenta);
|
||||
|
||||
await Motivo.drop();
|
||||
console.log('La tabla Motivo se desinstalo correctamente.'.magenta);
|
||||
|
||||
await Equipo.drop();
|
||||
console.log('La tabla Equipo se desinstalo correctamente.'.magenta);
|
||||
|
||||
@@ -91,6 +95,9 @@ const sync = async () => {
|
||||
await Equipo.sync();
|
||||
console.log('La tabla Equipo se instalo correctamente.'.magenta);
|
||||
|
||||
await Motivo.sync();
|
||||
console.log('La tabla Motivo se instalo correctamente.'.magenta);
|
||||
|
||||
await Prestamo.sync();
|
||||
console.log('La tabla Prestamo se instalo correctamente.'.magenta);
|
||||
|
||||
@@ -151,6 +158,7 @@ const dataStatus = async () => {
|
||||
'Cargando',
|
||||
'Reparación',
|
||||
'Mantenimiento',
|
||||
'Revisión',
|
||||
];
|
||||
|
||||
console.log('\nPaso 6) Insertando data status.'.bold.blue);
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
const { DataTypes, Model } = require('sequelize');
|
||||
const sequelize = require('../../config/sequelize.conf');
|
||||
const Equipo = require('./Equipo');
|
||||
const Status = require('./Status');
|
||||
|
||||
class Motivo extends Model {}
|
||||
Motivo.init(
|
||||
{
|
||||
idMotivo: {
|
||||
type: DataTypes.INTEGER,
|
||||
primaryKey: true,
|
||||
allowNull: false,
|
||||
unique: true,
|
||||
autoIncrement: true,
|
||||
},
|
||||
motivo: {
|
||||
type: DataTypes.STRING(500),
|
||||
allowNull: false,
|
||||
},
|
||||
},
|
||||
{
|
||||
sequelize,
|
||||
modelName: 'Motivo',
|
||||
tableName: 'motivo',
|
||||
timestamps: true,
|
||||
createdAt: true,
|
||||
updatedAt: false,
|
||||
}
|
||||
);
|
||||
|
||||
Motivo.belongsTo(Equipo, {
|
||||
foreignKey: {
|
||||
name: 'idEquipo',
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
},
|
||||
});
|
||||
|
||||
Motivo.belongsTo(Status, {
|
||||
foreignKey: {
|
||||
name: 'idStatus',
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
},
|
||||
});
|
||||
|
||||
module.exports = Motivo;
|
||||
+4
-4
@@ -6,12 +6,12 @@ module.exports = {
|
||||
io = new Server(httpServer, {
|
||||
cors: {
|
||||
origin: [
|
||||
// 'http://localhost:3046',
|
||||
// 'http://localhost:3056',
|
||||
'http://localhost:3046',
|
||||
'http://localhost:3056',
|
||||
// 'http://132.248.80.196:3045',
|
||||
// 'http://132.248.80.196:3055',
|
||||
'https://pcpuma.acatlan.unam.mx',
|
||||
'https://pcpuma.acatlan.unam.mx:8080',
|
||||
// 'https://pcpuma.acatlan.unam.mx',
|
||||
// 'https://pcpuma.acatlan.unam.mx:8080',
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user