listo la reservacion
This commit is contained in:
+29
-20
@@ -1,12 +1,13 @@
|
||||
import { Request, Response } from 'express'
|
||||
import { getRepository, QueryBuilder } from 'typeorm'
|
||||
import { getRepository } from 'typeorm'
|
||||
import { Equipo } from '@src/entity/Equipo'
|
||||
import { Prestamo } from '@src/entity/Prestamo'
|
||||
import { Usuario } from '@src/entity/Usuario'
|
||||
import { Operador } from '@src/entity/Operador'
|
||||
import * as moment from 'moment'
|
||||
import { Mesa } from '@src/entity/Mesa'
|
||||
export class PrestamoController {
|
||||
static async prestamo (request: Request, res: Response) {
|
||||
static async crear (request: Request, res: Response) {
|
||||
const usuarioRepository = await getRepository(Usuario)
|
||||
const equipoRepository = await getRepository(Equipo)
|
||||
const prestamoRepository = await getRepository(Prestamo)
|
||||
@@ -72,7 +73,7 @@ export class PrestamoController {
|
||||
})
|
||||
}
|
||||
|
||||
static async confirmarPrestamo (req: Request, res: Response) {
|
||||
static async confirmar (req: Request, res: Response) {
|
||||
const prestamoRepository = getRepository(Prestamo)
|
||||
const operadorRepository = getRepository(Operador)
|
||||
|
||||
@@ -111,27 +112,40 @@ export class PrestamoController {
|
||||
const equipoRepository = getRepository(Equipo)
|
||||
const prestamoRepository = getRepository(Prestamo)
|
||||
const operadorRepository = getRepository(Operador)
|
||||
const mesaRepository = getRepository(Mesa)
|
||||
|
||||
const prestamo = await prestamoRepository.findOne(req.body.prestamoId, {
|
||||
relations: ['equipo']
|
||||
const { prestamoId, operadorId } = req.body
|
||||
|
||||
const prestamo = await prestamoRepository.findOne(prestamoId, {
|
||||
relations: ['equipo', 'usuario', 'mesa']
|
||||
})
|
||||
if (!prestamo) {
|
||||
res.status(400).json({ err: 'Prestamo no encontrado' })
|
||||
}
|
||||
const operador = await operadorRepository.findOne(req.body.operadorId)
|
||||
const operador = await operadorRepository.findOne(operadorId)
|
||||
if (!operador) {
|
||||
res.status(400).json({ err: 'Operador no encontrado' })
|
||||
}
|
||||
|
||||
if (!prestamo.usuario.interno) {
|
||||
prestamo.mesa.activo = false
|
||||
}
|
||||
prestamo.activo = false
|
||||
prestamo.equipo.activo = false
|
||||
prestamo.operadorRegreso = operador
|
||||
|
||||
await equipoRepository.save(prestamo.equipo)
|
||||
await prestamoRepository.save(prestamo)
|
||||
res.status(200).json(prestamo)
|
||||
try {
|
||||
if (!prestamo.usuario.interno) {
|
||||
await mesaRepository.save(prestamo.mesa)
|
||||
}
|
||||
await equipoRepository.save(prestamo.equipo)
|
||||
await prestamoRepository.save(prestamo)
|
||||
res.status(200).send('Prestamo regresado Exitosamente')
|
||||
} catch (err) {
|
||||
res.status(400).json({ err: err.message })
|
||||
}
|
||||
}
|
||||
|
||||
static async estatusPrestamo (req: Request, res: Response) {
|
||||
static async estatus (req: Request, res: Response) {
|
||||
const repository = getRepository(Prestamo)
|
||||
const { usuarioId } = req.query
|
||||
console.log(usuarioId)
|
||||
@@ -139,26 +153,21 @@ export class PrestamoController {
|
||||
const prestamo = await repository
|
||||
.createQueryBuilder('prestamo')
|
||||
.leftJoinAndSelect('prestamo.usuario', 'usuario')
|
||||
.leftJoinAndSelect('prestamo.mesa', 'mesa')
|
||||
.where('usuario.id = :usuarioId', { usuarioId })
|
||||
.andWhere('prestamo.activo = :activo', { activo: true })
|
||||
.getOne()
|
||||
|
||||
// const prestamo = await repository.find({
|
||||
// relations: ['usuario'],
|
||||
// where: {
|
||||
// usuarioId,
|
||||
// activo: true
|
||||
// }
|
||||
// })
|
||||
if (!prestamo) {
|
||||
res.status(400).json({ err: 'El usuario no tiene prestamos activos' })
|
||||
res.status(200).json({ err: 'El usuario no tiene prestamos activos' })
|
||||
return
|
||||
}
|
||||
console.log(prestamo)
|
||||
|
||||
res.status(200).json(prestamo)
|
||||
}
|
||||
|
||||
static async cancelarPrestamo (req: Request, res: Response) {
|
||||
static async cancelar (req: Request, res: Response) {
|
||||
const repository = getRepository(Prestamo)
|
||||
|
||||
const { prestamoId } = req.body
|
||||
|
||||
Reference in New Issue
Block a user