prestamo terminado

This commit is contained in:
arturo
2020-08-24 21:25:39 -05:00
parent 9c780cb1cb
commit 22d6964054
5 changed files with 253 additions and 4 deletions
+33 -2
View File
@@ -59,19 +59,50 @@ export class EquipoController {
prestamo.usuario = usuario
prestamo.operadorEntrega = operador
const m = moment()
.add({ hours: 2, minutes: 30 })
.add({ hours: 2, minutes: 35 })
.format('MMMM Do YYYY, h:mm:ss a')
prestamo.horaMaxEntrega = m
await equipoRepository.save(equipo)
await equipoRepository.save(equipo)
await prestamoRepository.save(prestamo)
prestamo.qr = `https://api.qrserver.com/v1/create-qr-code/?size=150x150&data=${prestamo.id}`
res.status(200).json({
prestamo
})
}
static async confirmarPrestamo (req: Request, res: Response) {
const prestamoRepository = getRepository(Prestamo)
const operadorRepository = getRepository(Operador)
const prestamo = await prestamoRepository.findOne(req.body.prestamoId, {
relations: ['equipo']
})
if (!prestamo) {
res.status(400).json({
err: 'El prestamo no existe'
})
return
}
const operador = await operadorRepository.findOne(req.body.operadorId)
if (!operador) {
res.status(400).json({
err: 'El operador no existe'
})
return
}
prestamo.operadorRegreso = operador
prestamo.reservado = false
prestamo.activo = true
res.status(200).json(prestamo)
}
static async regreso (req: Request, res: Response) {
const equipoRepository = getRepository(Equipo)
const prestamoRepository = getRepository(Prestamo)
+6 -1
View File
@@ -17,9 +17,12 @@ export class Prestamo {
@PrimaryGeneratedColumn()
id: number
@Column({ default: true })
@Column({ default: false })
activo: boolean
@Column({ default: true })
reservado: boolean
@UpdateDateColumn()
updatedAt: Date
@@ -28,6 +31,8 @@ export class Prestamo {
horaMaxEntrega: string
qr: string
@ManyToOne(
(type) => Usuario,
(usuario) => usuario.prestamos
+1
View File
@@ -5,5 +5,6 @@ const router = Router()
router.post('/prestamo', EquipoController.prestamo)
router.post('/regreso', EquipoController.regreso)
router.post('/confirmar', EquipoController.confirmarPrestamo)
export default router