solo falta token y subir foto al server
This commit is contained in:
@@ -8,6 +8,7 @@ const Mesa = require('../../db/tables/Mesa')
|
||||
const activar = async (body) => {
|
||||
let idPrestamo = await validador.validarId(body.idPrestamo).then((res) => res)
|
||||
let idOperador = await validador.validarId(body.idOperador).then((res) => res)
|
||||
let idMesa
|
||||
|
||||
return Operador.findOne({ where: { idOperador } })
|
||||
.then((res) => {
|
||||
@@ -26,9 +27,7 @@ const activar = async (body) => {
|
||||
'No se ha regresado el equipo del previo prestamo.',
|
||||
400
|
||||
)
|
||||
}
|
||||
if (res.idOperadorEntrega)
|
||||
validador.error('Ya se ha entregado el equipo al usuario.', 400)
|
||||
} else validador.error('Ya se ha entregado el equipo al usuario.', 400)
|
||||
return Equipo.update(
|
||||
{ activo: true },
|
||||
{ where: { idEquipo: res.idEquipo } }
|
||||
@@ -37,15 +36,19 @@ const activar = async (body) => {
|
||||
.then(() => {
|
||||
return Mesa.findAll({
|
||||
where: { [Op.and]: [{ activo: false }, { idStatus: 1 }] },
|
||||
order: [['updatedAt', 'DESC']],
|
||||
order: [['updatedAt', 'ASC']],
|
||||
})
|
||||
})
|
||||
.then((res) => {
|
||||
idMesa = res[0].idMesa
|
||||
return Prestamo.update(
|
||||
{ idOperadorEntrega: idOperador, idMesa: res[0].idMesa },
|
||||
{ idOperadorEntrega: idOperador, idMesa },
|
||||
{ where: { idPrestamo } }
|
||||
)
|
||||
})
|
||||
.then(() => {
|
||||
return Mesa.update({ activo: true }, { where: { idMesa } })
|
||||
})
|
||||
.then(() => {
|
||||
return {
|
||||
code: 200,
|
||||
|
||||
@@ -10,7 +10,8 @@ const Mesa = require('../../db/tables/Mesa')
|
||||
|
||||
const activo = async (body) => {
|
||||
let idUsuario = await validador.validarId(body.idUsuario).then((res) => res)
|
||||
let busqueda = {
|
||||
|
||||
return Prestamo.findOne({
|
||||
include: [
|
||||
{ model: Horario },
|
||||
{ model: Mesa, include: [{ model: Status }] },
|
||||
@@ -23,12 +24,13 @@ const activo = async (body) => {
|
||||
},
|
||||
],
|
||||
where: { [Op.and]: [{ idUsuario }, { activo: true }] },
|
||||
}
|
||||
|
||||
return Prestamo.findOne(busqueda).then((res) => {
|
||||
}).then((res) => {
|
||||
if (!res) validador.error('El usuario no tiene un prestamo activo.', 400)
|
||||
return {
|
||||
data: validador.objetoPrestamoEquipo(res),
|
||||
data: {
|
||||
prestamo: validador.objetoPrestamoEquipo(res),
|
||||
qr: `https://api.qrserver.com/v1/create-qr-code/?size=150x150&data=${res.idPrestamo}`,
|
||||
},
|
||||
code: 200,
|
||||
}
|
||||
})
|
||||
|
||||
@@ -3,15 +3,13 @@ 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)
|
||||
return Prestamo.findOne({ where: { idPrestamo } })
|
||||
.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)
|
||||
if (!res.activo)
|
||||
validador.error('Ya ha sido cancelado este prestamo.', 400)
|
||||
return Prestamo.update({ activo: false }, { where: { idPrestamo } })
|
||||
})
|
||||
.then(() => {
|
||||
return {
|
||||
|
||||
@@ -18,35 +18,16 @@ const equipo = async (body) => {
|
||||
.then((res) => res)
|
||||
let idHorario = await validador.validarId(body.idHorario).then((res) => res)
|
||||
let kiosko = '1'
|
||||
let horaFin = await validador.validarTexto(body.horario).then((res) => {
|
||||
let hora = res.substr(res.indexOf('-') + 1)
|
||||
let horaNumero = Number(hora.substr(0, hora.indexOf(':')))
|
||||
let horaLimite = moment()
|
||||
let horaFin = await validador
|
||||
.validarTexto(body.horario)
|
||||
.then((res) => validador.stringToMoment(res))
|
||||
|
||||
horaLimite.set('hour', horaNumero)
|
||||
horaLimite.set('minute', 0)
|
||||
horaLimite.set('second', 0)
|
||||
return horaLimite
|
||||
})
|
||||
let busquedaPrestamo = {
|
||||
return Prestamo.findOne({
|
||||
where: { [Op.and]: [{ idUsuario }, { activo: true }] },
|
||||
}
|
||||
let busquedaEquipo = {
|
||||
include: [
|
||||
{
|
||||
model: Carrito,
|
||||
where: { kiosko },
|
||||
include: [{ model: TipoCarrito, where: { idTipoCarrito } }],
|
||||
},
|
||||
],
|
||||
where: { idStatus: 1 },
|
||||
order: [['updatedAt', 'DESC']],
|
||||
}
|
||||
|
||||
return Prestamo.findOne(busquedaPrestamo)
|
||||
})
|
||||
.then((res) => {
|
||||
if (res) validador.error('Este usuario ya tiene un prestamo activo.', 400)
|
||||
busquedaPrestamo = {
|
||||
return Prestamo.findAll({
|
||||
where: {
|
||||
[Op.and]: [
|
||||
{ idHorario },
|
||||
@@ -54,45 +35,36 @@ const equipo = async (body) => {
|
||||
{ idEquipo: { [Op.not]: null } },
|
||||
],
|
||||
},
|
||||
include: [
|
||||
{
|
||||
model: Equipo,
|
||||
include: [
|
||||
{
|
||||
model: Carrito,
|
||||
include: [{ model: TipoCarrito, where: { idTipoCarrito } }],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
}
|
||||
return Prestamo.findAll(busquedaPrestamo)
|
||||
include: [{ model: Equipo }],
|
||||
})
|
||||
})
|
||||
.then(async (res) => {
|
||||
let equipo = await Equipo.findAll(busquedaEquipo).then((res2) => {
|
||||
let idEquipo = await Equipo.findAll({
|
||||
where: { idStatus: 1 },
|
||||
order: [['updatedAt', 'ASC']],
|
||||
}).then((res2) => {
|
||||
for (let i = 0; i < res2.length; i++) {
|
||||
let enUso = false
|
||||
|
||||
for (let j = 0; j < res.length; j++) {
|
||||
if (res2[i].idEquipo === res[i].idEquipo) {
|
||||
if (res2[i].idEquipo === res[i].Equipo.idEquipo) {
|
||||
enUso = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if (!enUso) return res2[i]
|
||||
if (!enUso) return res2[i].idEquipo
|
||||
}
|
||||
return {}
|
||||
return null
|
||||
})
|
||||
let data = {
|
||||
idUsuario,
|
||||
idEquipo: equipo.idEquipo,
|
||||
idHorario,
|
||||
horaFin,
|
||||
}
|
||||
|
||||
if (!equipo)
|
||||
validador.error('No hay equipos disponibles en ese horario', 400)
|
||||
return Prestamo.create(data)
|
||||
return Prestamo.create({
|
||||
idUsuario,
|
||||
idEquipo,
|
||||
idHorario,
|
||||
horaFin,
|
||||
})
|
||||
})
|
||||
.then((res) => {
|
||||
return Prestamo.findOne({
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
const validador = require('../validador')
|
||||
const Prestamo = require('../../db/tables/Prestamo')
|
||||
const Equipo = require('../../db/tables/Equipo')
|
||||
const Carrito = require('../../db/tables/Carrito')
|
||||
@@ -6,7 +7,7 @@ const Status = require('../../db/tables/Status')
|
||||
const Horario = require('../../db/tables/Horario')
|
||||
|
||||
const get = async () => {
|
||||
let busqueda = {
|
||||
return Prestamo.findAll({
|
||||
include: [
|
||||
{ model: Horario },
|
||||
{
|
||||
@@ -18,50 +19,11 @@ const get = async () => {
|
||||
},
|
||||
],
|
||||
where: { activo: true },
|
||||
}
|
||||
|
||||
return Prestamo.findAll(busqueda).then((res) => {
|
||||
}).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)
|
||||
}
|
||||
for (let i = 0; i < res.length; i++)
|
||||
data.push(validador.objetoPrestamoEquipo(res[i]))
|
||||
return { data, code: 200 }
|
||||
})
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ const validador = require('../validador')
|
||||
const Prestamo = require('../../db/tables/Prestamo')
|
||||
const Operador = require('../../db/tables/Operador')
|
||||
const Equipo = require('../../db/tables/Equipo')
|
||||
const Mesa = require('../../db/tables/Mesa')
|
||||
|
||||
const activar = async (body) => {
|
||||
let idPrestamo = await validador.validarId(body.idPrestamo).then((res) => res)
|
||||
@@ -16,11 +17,11 @@ const activar = async (body) => {
|
||||
})
|
||||
})
|
||||
.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)
|
||||
if (!res) validador.error('No existe este prestamo.', 400)
|
||||
if (!res.idOperadorEntrega) {
|
||||
if (!res.activo) validador.error('Este prestamo fue cancelado.', 400)
|
||||
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)
|
||||
|
||||
@@ -9,7 +9,8 @@ const Mesa = require('../../db/tables/Mesa')
|
||||
|
||||
const status = async (body) => {
|
||||
let idPrestamo = await validador.validarId(body.idPrestamo).then((res) => res)
|
||||
let busqueda = {
|
||||
|
||||
return Prestamo.findOne({
|
||||
include: [
|
||||
{ model: Horario },
|
||||
{ model: Mesa, include: [{ model: Status }] },
|
||||
@@ -22,12 +23,13 @@ const status = async (body) => {
|
||||
},
|
||||
],
|
||||
where: { idPrestamo },
|
||||
}
|
||||
|
||||
return Prestamo.findOne(busqueda).then((res) => {
|
||||
if (!res) validador.error('No existe ese prestamo.', 400)
|
||||
}).then((res) => {
|
||||
if (!res) validador.error('No existe este prestamo.', 400)
|
||||
return {
|
||||
data: validador.objetoPrestamoEquipo(res),
|
||||
data: {
|
||||
prestamo: validador.objetoPrestamoEquipo(res),
|
||||
qr: `https://api.qrserver.com/v1/create-qr-code/?size=150x150&data=${res.idPrestamo}`,
|
||||
},
|
||||
code: 200,
|
||||
}
|
||||
})
|
||||
|
||||
@@ -14,13 +14,12 @@ app.get(`${route}`, (req, res) => {
|
||||
.then((data) => {
|
||||
res.status(data.code).json({ prestamos: data.data })
|
||||
})
|
||||
.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 })
|
||||
res.status(data.code).json(data.data)
|
||||
})
|
||||
.catch((err) => res.status(err.code).json({ err: err.message }))
|
||||
})
|
||||
@@ -28,7 +27,7 @@ app.get(`${route}/status`, (req, res) => {
|
||||
app.get(`${route}/activo`, (req, res) => {
|
||||
return activo(req.query)
|
||||
.then((data) => {
|
||||
res.status(data.code).json({ prestamos: data.data })
|
||||
res.status(data.code).json(data.data)
|
||||
})
|
||||
.catch((err) => res.status(err.code).json({ err: err.message }))
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user