cambios para completar user

This commit is contained in:
arturo
2020-09-08 11:29:11 -05:00
parent eda0dc7d81
commit 0b4c3d56d3
10 changed files with 179 additions and 7 deletions
+17 -4
View File
@@ -1,5 +1,5 @@
import { Request, Response } from 'express'
import { getRepository } from 'typeorm'
import { getRepository, QueryBuilder } from 'typeorm'
import { Equipo } from '@src/entity/Equipo'
import { Prestamo } from '@src/entity/Prestamo'
import { Usuario } from '@src/entity/Usuario'
@@ -133,12 +133,25 @@ export class PrestamoController {
static async estatusPrestamo (req: Request, res: Response) {
const repository = getRepository(Prestamo)
const { prestamoId } = req.query
const { usuarioId } = req.query
console.log(usuarioId)
const prestamo = await repository.findOne(+prestamoId)
const prestamo = await repository
.createQueryBuilder('prestamo')
.leftJoinAndSelect('prestamo.usuario', 'usuario')
.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 prestamo no existe' })
res.status(400).json({ err: 'El usuario no tiene prestamos activos' })
return
}