cambios para completar user
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user