cambios para completar user
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
import * as jwt from 'jsonwebtoken'
|
||||
export class AuthController {
|
||||
static async signUsuario (type: string, usuarioId: string) {
|
||||
const secret = 'Holabeb'
|
||||
const token = jwt.sign({ type, usuarioId }, secret, { expiresIn: '1h' })
|
||||
return token
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ import { Usuario } from '@src/entity/Usuario'
|
||||
import { Request, Response } from 'express'
|
||||
import { validate } from 'class-validator'
|
||||
import { getRepository } from 'typeorm'
|
||||
import { AuthController } from './Auth'
|
||||
export class UsuarioController {
|
||||
static async create (req: Request, res: Response) {
|
||||
console.log(req.file)
|
||||
@@ -91,11 +92,17 @@ export class UsuarioController {
|
||||
if (!usuario.checkIfUnencryptedPasswordIsValid(secreto)) {
|
||||
throw new Error('Usuario o *contraseña invalidos')
|
||||
}
|
||||
const token = await AuthController.signUsuario(
|
||||
usuario.interno ? 'usuarioInterno' : 'usuarioExterno',
|
||||
usuario.id
|
||||
)
|
||||
console.log(token)
|
||||
res.status(200).json({
|
||||
nombre: usuario.nombre,
|
||||
apellidoPaterno: usuario.apellidoPaterno,
|
||||
apellidoMaterno: usuario.apellidoMaterno,
|
||||
interno: usuario.interno
|
||||
interno: usuario.interno,
|
||||
token
|
||||
})
|
||||
} catch (err) {
|
||||
res.status(400).send(err.message)
|
||||
|
||||
Reference in New Issue
Block a user