ticket
This commit is contained in:
@@ -1,10 +1,9 @@
|
||||
import { IsString } from "class-validator";
|
||||
import { IsString } from 'class-validator';
|
||||
|
||||
export class CreateUserDto {
|
||||
@IsString()
|
||||
usuario: string;
|
||||
|
||||
@IsString()
|
||||
usuario:string
|
||||
|
||||
@IsString()
|
||||
password:string
|
||||
@IsString()
|
||||
password: string;
|
||||
}
|
||||
|
||||
@@ -1,35 +1,34 @@
|
||||
import { Column, Entity, PrimaryGeneratedColumn } from "typeorm";
|
||||
import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm';
|
||||
|
||||
@Entity({name:'usuario'})
|
||||
@Entity({ name: 'usuario' })
|
||||
export class User {
|
||||
@PrimaryGeneratedColumn({ name: 'id_usuario', type: 'int' })
|
||||
id_usuario: number;
|
||||
|
||||
@PrimaryGeneratedColumn({name:'id_usuario',type: 'int'})
|
||||
id_usuario:number;
|
||||
@Column({ name: 'nombre', type: 'varchar' })
|
||||
nombre: string;
|
||||
|
||||
@Column({name:'nombre',type:'varchar'})
|
||||
nombre:string
|
||||
@Column({ name: 'apellido_paterno', type: 'varchar' })
|
||||
apellido_paterno: string;
|
||||
|
||||
@Column({name:'apellido_paterno',type:'varchar'})
|
||||
apellido_paterno:string
|
||||
@Column({ name: 'apellido_materno', type: 'varchar' })
|
||||
apellido_materno: string;
|
||||
|
||||
@Column({name:'apellido_materno',type:'varchar'})
|
||||
apellido_materno:string
|
||||
@Column({ name: 'usuario', type: 'varchar' })
|
||||
usuario: string;
|
||||
|
||||
@Column({name:'usuario',type:'varchar'})
|
||||
usuario:string
|
||||
@Column({ name: 'password', type: 'varchar', length: 45, nullable: false })
|
||||
password: string;
|
||||
|
||||
@Column({name:'password',type:'varchar',length:45, nullable:false})
|
||||
password:string
|
||||
@Column({ name: 'activo', type: 'tinyint', nullable: false, default: 1 })
|
||||
activo: number;
|
||||
|
||||
@Column({name:'activo',type:'tinyint',nullable:false, default:1})
|
||||
activo: number
|
||||
@Column({ name: 'descripcion', type: 'varchar', length: 50, default: null })
|
||||
description: boolean;
|
||||
|
||||
@Column({name:'descripcion',type:'varchar',length:50,default:null})
|
||||
description:boolean
|
||||
@Column({ name: 'fecha_registro', type: 'varchar' })
|
||||
fecha_registro: string;
|
||||
|
||||
@Column({name:'fecha_registro',type:'varchar'})
|
||||
fecha_registro:string
|
||||
|
||||
@Column({name:'id_perfil',})
|
||||
id_perfil:number
|
||||
@Column({ name: 'id_perfil' })
|
||||
id_perfil: number;
|
||||
}
|
||||
|
||||
+13
-14
@@ -1,4 +1,9 @@
|
||||
import { Injectable, Logger, NotFoundException, UnauthorizedException } from '@nestjs/common';
|
||||
import {
|
||||
Injectable,
|
||||
Logger,
|
||||
NotFoundException,
|
||||
UnauthorizedException,
|
||||
} from '@nestjs/common';
|
||||
import { CreateUserDto } from './dto/create-user.dto';
|
||||
import { UpdateUserDto } from './dto/update-user.dto';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
@@ -10,29 +15,23 @@ export class UserService {
|
||||
constructor(
|
||||
@InjectRepository(User)
|
||||
private userRepository: Repository<User>,
|
||||
) { }
|
||||
) {}
|
||||
|
||||
async findOneByNameandPassword(data:CreateUserDto): Promise<User> {
|
||||
|
||||
const { usuario, password } = data
|
||||
async findOneByNameandPassword(data: CreateUserDto): Promise<User> {
|
||||
const { usuario, password } = data;
|
||||
|
||||
const user = await this.userRepository.findOne({
|
||||
where: { usuario,password }
|
||||
})
|
||||
where: { usuario, password },
|
||||
});
|
||||
|
||||
if (!user) {
|
||||
throw new NotFoundException(
|
||||
`El usuario ${usuario} no fue encontrado`,
|
||||
);
|
||||
throw new NotFoundException(`El usuario ${usuario} no fue encontrado`);
|
||||
}
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
async Login(data: CreateUserDto) {
|
||||
|
||||
const user = await this.findOneByNameandPassword(data);
|
||||
return user
|
||||
return await this.findOneByNameandPassword(data);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user