prestamo cancelar, status, get, actualizar, regreso
This commit is contained in:
@@ -0,0 +1,45 @@
|
|||||||
|
const validador = require('../validador')
|
||||||
|
const Prestamo = require('../../db/tables/Prestamo')
|
||||||
|
const Operador = require('../../db/tables/Operador')
|
||||||
|
const Equipo = require('../../db/tables/Equipo')
|
||||||
|
const { validarEmail } = require('../validador')
|
||||||
|
|
||||||
|
const activar = async (body) => {
|
||||||
|
let idPrestamo = await validador.validarId(body.idPrestamo).then((res) => res)
|
||||||
|
let idOperador = await validador.validarId(body.idOperador).then((res) => res)
|
||||||
|
|
||||||
|
return Operador.findOne({ where: { idOperador } })
|
||||||
|
.then((res) => {
|
||||||
|
if (!res) validador.error('No existe este operador.', 400)
|
||||||
|
return Prestamo.findOne({
|
||||||
|
where: { idPrestamo },
|
||||||
|
include: [{ model: Equipo }],
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.then((res) => {
|
||||||
|
if (!res) validador.error('No existe ese prestamo.', 400)
|
||||||
|
if (!res.activo && !res.idOperadorRegreso && !res.idOperadorEntrega)
|
||||||
|
validador.error('Este prestamo fue cancelado.', 400)
|
||||||
|
if (res.idOperadorEntrega)
|
||||||
|
validador.error('Ya se ha entregado este equipo.', 400)
|
||||||
|
if (res.Equipo.activo) validador.error('Este equipo ya esta en uso.', 400)
|
||||||
|
return Equipo.update(
|
||||||
|
{ activo: true },
|
||||||
|
{ where: { idEquipo: res.idEquipo } }
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
return Prestamo.update(
|
||||||
|
{ idOperadorEntrega: idOperador },
|
||||||
|
{ where: { idPrestamo } }
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
return {
|
||||||
|
code: 200,
|
||||||
|
message: 'Se ha entregado el equipo al usuario correctamente.',
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = activar
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
const validador = require('../validador')
|
||||||
|
const Prestamo = require('../../db/tables/Prestamo')
|
||||||
|
|
||||||
|
const cancelar = async (body) => {
|
||||||
|
let idPrestamo = await validador.validarId(body.idPrestamo).then((res) => res)
|
||||||
|
let busqueda = { where: { idPrestamo } }
|
||||||
|
let actualizar = { activo: false }
|
||||||
|
|
||||||
|
return Prestamo.findOne(busqueda)
|
||||||
|
.then((res) => {
|
||||||
|
if (!res) validador.error('No existe ese prestamo.', 400)
|
||||||
|
if (res.activo === false)
|
||||||
|
validador.error('Ya ha sido desactivado este prestamo.', 400)
|
||||||
|
return Prestamo.update(actualizar, busqueda)
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
return {
|
||||||
|
code: 200,
|
||||||
|
message: 'Haz cancelado tu prestamo.',
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = cancelar
|
||||||
|
|||||||
@@ -145,6 +145,7 @@ const equipo = async (body) => {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
qr: `https://api.qrserver.com/v1/create-qr-code/?size=150x150&data=${res.idPrestamo}`,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,11 +1,69 @@
|
|||||||
const Prestamo = require('../../db/tables/Prestamo')
|
const Prestamo = require('../../db/tables/Prestamo')
|
||||||
|
const Equipo = require('../../db/tables/Equipo')
|
||||||
|
const Carrito = require('../../db/tables/Carrito')
|
||||||
|
const TipoCarrito = require('../../db/tables/TipoCarrito')
|
||||||
|
const Status = require('../../db/tables/Status')
|
||||||
|
const Horario = require('../../db/tables/Horario')
|
||||||
|
|
||||||
const get = async () => {
|
const get = async () => {
|
||||||
return Prestamo.findAll()
|
let busqueda = {
|
||||||
.then((res) => {
|
include: [
|
||||||
return res
|
{ model: Horario },
|
||||||
})
|
{
|
||||||
.catch((err) => {})
|
model: Equipo,
|
||||||
|
include: [
|
||||||
|
{ model: Status },
|
||||||
|
{ model: Carrito, include: [{ model: TipoCarrito }] },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
where: { activo: true },
|
||||||
|
}
|
||||||
|
|
||||||
|
return Prestamo.findAll(busqueda).then((res) => {
|
||||||
|
let data = []
|
||||||
|
|
||||||
|
for (let i = 0; i < res.length; i++) {
|
||||||
|
let prestamo = {
|
||||||
|
idPrestamo: res[i].idPrestamo,
|
||||||
|
horaFin: res[i].horaFin,
|
||||||
|
activo: res[i].activo,
|
||||||
|
createdAt: res[i].createdAt,
|
||||||
|
updatedAt: res[i].updatedAt,
|
||||||
|
idUsuario: res[i].idUsuario,
|
||||||
|
idOperadorEntrega: res[i].idOperadorEntrega,
|
||||||
|
idOperadorRegreso: res[i].idOperadorRegreso,
|
||||||
|
idMesa: res[i].idMesa,
|
||||||
|
Horario: {
|
||||||
|
idHorario: res[i].Horario.idHorario,
|
||||||
|
horario: res[i].Horario.horario,
|
||||||
|
},
|
||||||
|
Equipo: {
|
||||||
|
idEquipo: res[i].Equipo.idEquipo,
|
||||||
|
noSerie: res[i].Equipo.noSerie,
|
||||||
|
noInventario: res[i].Equipo.noInventario,
|
||||||
|
sobrenombre: res[i].Equipo.sobrenombre,
|
||||||
|
activo: res[i].Equipo.activo,
|
||||||
|
updatedAt: res[i].Equipo.updatedAt,
|
||||||
|
Status: {
|
||||||
|
idStatus: res[i].Equipo.Status.idStatus,
|
||||||
|
status: res[i].Equipo.Status.status,
|
||||||
|
},
|
||||||
|
Carrito: {
|
||||||
|
idCarrito: res[i].Equipo.Carrito.idCarrito,
|
||||||
|
sobrenombre: res[i].Equipo.Carrito.sobrenombre,
|
||||||
|
kiosko: res[i].Equipo.Carrito.kiosko,
|
||||||
|
TipoCarrito: {
|
||||||
|
idTipoCarrito: res[i].Equipo.Carrito.TipoCarrito.idTipoCarrito,
|
||||||
|
nombre: res[i].Equipo.Carrito.TipoCarrito.nombre,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
data.push(prestamo)
|
||||||
|
}
|
||||||
|
return { data, code: 200 }
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = get
|
module.exports = get
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
const validador = require('../validador')
|
||||||
|
const Prestamo = require('../../db/tables/Prestamo')
|
||||||
|
const Operador = require('../../db/tables/Operador')
|
||||||
|
const Equipo = require('../../db/tables/Equipo')
|
||||||
|
|
||||||
|
const activar = async (body) => {
|
||||||
|
let idPrestamo = await validador.validarId(body.idPrestamo).then((res) => res)
|
||||||
|
let idOperador = await validador.validarId(body.idOperador).then((res) => res)
|
||||||
|
|
||||||
|
return Operador.findOne({ where: { idOperador } })
|
||||||
|
.then((res) => {
|
||||||
|
if (!res) validador.error('No existe este operador.', 400)
|
||||||
|
return Prestamo.findOne({
|
||||||
|
where: { idPrestamo },
|
||||||
|
include: [{ model: Equipo }],
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.then((res) => {
|
||||||
|
if (!res) validador.error('No existe ese prestamo.', 400)
|
||||||
|
if (!res.activo && !res.idOperadorRegreso && !res.idOperadorEntrega)
|
||||||
|
validador.error('Este prestamo fue cancelado.', 400)
|
||||||
|
if (!res.idOperadorEntrega)
|
||||||
|
validador.error('Aun no ha sido entregado este equipo.', 400)
|
||||||
|
if (res.idOperadorRegreso)
|
||||||
|
validador.error('Ya se ha regresado este equipo.', 400)
|
||||||
|
if (!res.Equipo.activo) validador.error('Este equipo ya se entrego.', 400)
|
||||||
|
return Equipo.update(
|
||||||
|
{ activo: false },
|
||||||
|
{ where: { idEquipo: res.idEquipo } }
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
return Prestamo.update(
|
||||||
|
{ idOperadorRegreso: idOperador, activo: false },
|
||||||
|
{ where: { idPrestamo } }
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
return {
|
||||||
|
code: 200,
|
||||||
|
message: 'Se ha regresado el equipo correctamente.',
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = activar
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
const Prestamo = require('../../db/tables/Prestamo')
|
||||||
|
|
||||||
|
const status = async (body) => {
|
||||||
|
let busqueda = { where: { idPrestamo: body.idPrestamo } }
|
||||||
|
|
||||||
|
return Prestamo.findOne(busqueda).then((res) => {
|
||||||
|
return { code: 200, data: res }
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = status
|
||||||
|
|||||||
@@ -1,11 +1,69 @@
|
|||||||
|
const validador = require('../validador')
|
||||||
const Prestamo = require('../../db/tables/Prestamo')
|
const Prestamo = require('../../db/tables/Prestamo')
|
||||||
|
const Equipo = require('../../db/tables/Equipo')
|
||||||
|
const Carrito = require('../../db/tables/Carrito')
|
||||||
|
const TipoCarrito = require('../../db/tables/TipoCarrito')
|
||||||
|
const Status = require('../../db/tables/Status')
|
||||||
|
const Horario = require('../../db/tables/Horario')
|
||||||
|
|
||||||
const status = async (body) => {
|
const status = async (body) => {
|
||||||
return Prestamo.findOne({ where: { idPrestamo: body.idPrestamo } })
|
let idPrestamo = await validador.validarId(body.idPrestamo).then((res) => res)
|
||||||
.then((res) => {
|
let busqueda = {
|
||||||
return res
|
include: [
|
||||||
})
|
{ model: Horario },
|
||||||
.catch((err) => {})
|
{
|
||||||
|
model: Equipo,
|
||||||
|
include: [
|
||||||
|
{ model: Status },
|
||||||
|
{ model: Carrito, include: [{ model: TipoCarrito }] },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
where: { idPrestamo },
|
||||||
|
}
|
||||||
|
|
||||||
|
return Prestamo.findOne(busqueda).then((res) => {
|
||||||
|
if (!res) validador.error('No existe ese prestamo.', 400)
|
||||||
|
return {
|
||||||
|
data: {
|
||||||
|
idPrestamo: res.idPrestamo,
|
||||||
|
horaFin: res.horaFin,
|
||||||
|
activo: res.activo,
|
||||||
|
createdAt: res.createdAt,
|
||||||
|
updatedAt: res.updatedAt,
|
||||||
|
idUsuario: res.idUsuario,
|
||||||
|
idOperadorEntrega: res.idOperadorEntrega,
|
||||||
|
idOperadorRegreso: res.idOperadorRegreso,
|
||||||
|
idMesa: res.idMesa,
|
||||||
|
Horario: {
|
||||||
|
idHorario: res.Horario.idHorario,
|
||||||
|
horario: res.Horario.horario,
|
||||||
|
},
|
||||||
|
Equipo: {
|
||||||
|
idEquipo: res.Equipo.idEquipo,
|
||||||
|
noSerie: res.Equipo.noSerie,
|
||||||
|
noInventario: res.Equipo.noInventario,
|
||||||
|
sobrenombre: res.Equipo.sobrenombre,
|
||||||
|
activo: res.Equipo.activo,
|
||||||
|
updatedAt: res.Equipo.updatedAt,
|
||||||
|
Status: {
|
||||||
|
idStatus: res.Equipo.Status.idStatus,
|
||||||
|
status: res.Equipo.Status.status,
|
||||||
|
},
|
||||||
|
Carrito: {
|
||||||
|
idCarrito: res.Equipo.Carrito.idCarrito,
|
||||||
|
sobrenombre: res.Equipo.Carrito.sobrenombre,
|
||||||
|
kiosko: res.Equipo.Carrito.kiosko,
|
||||||
|
TipoCarrito: {
|
||||||
|
idTipoCarrito: res.Equipo.Carrito.TipoCarrito.idTipoCarrito,
|
||||||
|
nombre: res.Equipo.Carrito.TipoCarrito.nombre,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
code: 200,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = status
|
module.exports = status
|
||||||
|
|||||||
+52
-7
@@ -1,16 +1,28 @@
|
|||||||
const express = require('express')
|
const express = require('express')
|
||||||
const app = express()
|
const app = express()
|
||||||
const get = require('../controller/prestamo/get')
|
const get = require('../controller/prestamo/get')
|
||||||
|
const status = require('../controller/prestamo/status')
|
||||||
const equipo = require('../controller/prestamo/equipo')
|
const equipo = require('../controller/prestamo/equipo')
|
||||||
|
const cancelar = require('../controller/prestamo/cancelar')
|
||||||
|
const activar = require('../controller/prestamo/activar')
|
||||||
|
const regreso = require('../controller/prestamo/regreso')
|
||||||
const route = '/prestamo'
|
const route = '/prestamo'
|
||||||
|
|
||||||
// app.get(`${route}`, (req, res) => {
|
app.get(`${route}`, (req, res) => {
|
||||||
// return get(req.query)
|
return get()
|
||||||
// .then((data) => {
|
.then((data) => {
|
||||||
// res.status(data.code).json({ prestamo: data.data })
|
res.status(data.code).json({ prestamos: data.data })
|
||||||
// })
|
})
|
||||||
// .catch((err) => res.status(err.code).json({ err: err.message }))
|
.catch((err) => res.status(err.code).json({ err: err.message }))
|
||||||
// })
|
})
|
||||||
|
|
||||||
|
app.get(`${route}/status`, (req, res) => {
|
||||||
|
return status(req.query)
|
||||||
|
.then((data) => {
|
||||||
|
res.status(data.code).json({ prestamos: data.data })
|
||||||
|
})
|
||||||
|
.catch((err) => res.status(err.code).json({ err: err.message }))
|
||||||
|
})
|
||||||
|
|
||||||
app.post(`${route}/equipo`, (req, res) => {
|
app.post(`${route}/equipo`, (req, res) => {
|
||||||
return equipo(req.body)
|
return equipo(req.body)
|
||||||
@@ -22,4 +34,37 @@ app.post(`${route}/equipo`, (req, res) => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
app.put(`${route}/cancelar`, (req, res) => {
|
||||||
|
return cancelar(req.body)
|
||||||
|
.then((data) => {
|
||||||
|
res.status(data.code).json({ message: data.message })
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.log(err)
|
||||||
|
res.status(err.code).json({ err: err.message })
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
app.put(`${route}/activar`, (req, res) => {
|
||||||
|
return activar(req.body)
|
||||||
|
.then((data) => {
|
||||||
|
res.status(data.code).json({ message: data.message })
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.log(err)
|
||||||
|
res.status(err.code).json({ err: err.message })
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
app.put(`${route}/regreso`, (req, res) => {
|
||||||
|
return regreso(req.body)
|
||||||
|
.then((data) => {
|
||||||
|
res.status(data.code).json({ message: data.message })
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.log(err)
|
||||||
|
res.status(err.code).json({ err: err.message })
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
module.exports = app
|
module.exports = app
|
||||||
|
|||||||
Reference in New Issue
Block a user