added Login
This commit is contained in:
@@ -1 +1,48 @@
|
|||||||
export class Student {}
|
import { Column, Entity, PrimaryColumn } from "typeorm";
|
||||||
|
|
||||||
|
@Entity({ name: 'alumno' })
|
||||||
|
export class Student {
|
||||||
|
|
||||||
|
@PrimaryColumn({ name: 'id_cuenta', type: 'int', unsigned: true })
|
||||||
|
id_cuenta: number;
|
||||||
|
|
||||||
|
@Column({ name: 'nombre', type: 'varchar', length: 300, nullable: false })
|
||||||
|
nombre: string;
|
||||||
|
|
||||||
|
@Column({ name: 'fecha_nacimiento', type: 'varchar', length: 8, nullable: true })
|
||||||
|
fecha_nacimiento: string | null;
|
||||||
|
|
||||||
|
@Column({ name: 'correo', type: 'varchar', length: 100, nullable: true })
|
||||||
|
correo: string | null;
|
||||||
|
|
||||||
|
@Column({ name: 'credito', type: 'decimal', precision: 10, scale: 2, default: 0.00 })
|
||||||
|
credito: string;
|
||||||
|
|
||||||
|
@Column({
|
||||||
|
name: 'fecha_actualizacion_credito',
|
||||||
|
type: 'timestamp',
|
||||||
|
default: () => 'CURRENT_TIMESTAMP',
|
||||||
|
onUpdate: 'CURRENT_TIMESTAMP',
|
||||||
|
})
|
||||||
|
fecha_actualizacion_credito: Date;
|
||||||
|
|
||||||
|
@Column({
|
||||||
|
name: 'vigente',
|
||||||
|
type: 'enum',
|
||||||
|
enum: ['si', 'no'],
|
||||||
|
default: 'si',
|
||||||
|
})
|
||||||
|
vigente: 'si' | 'no';
|
||||||
|
|
||||||
|
@Column({ name: 'id_periodo', type: 'int', nullable: true })
|
||||||
|
id_periodo: number | null;
|
||||||
|
|
||||||
|
@Column({ name: 'fecha_registro', type: 'datetime', nullable: false })
|
||||||
|
fecha_registro: Date;
|
||||||
|
|
||||||
|
@Column({ name: 'id_carrera', type: 'int', nullable: false })
|
||||||
|
id_carrera: number;
|
||||||
|
|
||||||
|
@Column({ name: 'generacion', type: 'int', width: 4, nullable: true })
|
||||||
|
generacion: number | null;
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { IsString } from "class-validator";
|
|||||||
export class CreateUserDto {
|
export class CreateUserDto {
|
||||||
|
|
||||||
@IsString()
|
@IsString()
|
||||||
username:string
|
usuario:string
|
||||||
|
|
||||||
@IsString()
|
@IsString()
|
||||||
password:string
|
password:string
|
||||||
|
|||||||
@@ -7,11 +7,6 @@ import { UpdateUserDto } from './dto/update-user.dto';
|
|||||||
export class UserController {
|
export class UserController {
|
||||||
constructor(private readonly userService: UserService) {}
|
constructor(private readonly userService: UserService) {}
|
||||||
|
|
||||||
@Get()
|
|
||||||
findAll() {
|
|
||||||
return this.userService.findAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Post()
|
@Post()
|
||||||
Login(@Body() user: CreateUserDto) {
|
Login(@Body() user: CreateUserDto) {
|
||||||
return this.userService.Login(user);
|
return this.userService.Login(user);
|
||||||
|
|||||||
@@ -12,45 +12,26 @@ export class UserService {
|
|||||||
private userRepository: Repository<User>,
|
private userRepository: Repository<User>,
|
||||||
) { }
|
) { }
|
||||||
|
|
||||||
create(createUserDto: CreateUserDto) {
|
async findOneByNameandPassword(data:CreateUserDto): Promise<User> {
|
||||||
return 'This action adds a new user';
|
|
||||||
}
|
|
||||||
|
|
||||||
findAll() {
|
const { usuario, password } = data
|
||||||
return `This action returns all user`;
|
|
||||||
}
|
|
||||||
|
|
||||||
async findOneByName(nombre: string): Promise<User> {
|
|
||||||
|
|
||||||
const user = await this.userRepository.findOne({
|
const user = await this.userRepository.findOne({
|
||||||
where: { nombre }
|
where: { usuario,password }
|
||||||
})
|
})
|
||||||
|
|
||||||
if (!user) {
|
if (!user) {
|
||||||
throw new NotFoundException(
|
throw new NotFoundException(
|
||||||
`El usuario ${nombre} no fue encontrado`,
|
`El usuario ${usuario} no fue encontrado`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
update(id: number, updateUserDto: UpdateUserDto) {
|
|
||||||
return `This action updates a #${id} user`;
|
|
||||||
}
|
|
||||||
|
|
||||||
remove(id: number) {
|
|
||||||
return `This action removes a #${id} user`;
|
|
||||||
}
|
|
||||||
|
|
||||||
async Login(data: CreateUserDto) {
|
async Login(data: CreateUserDto) {
|
||||||
const { username } = data
|
|
||||||
|
|
||||||
if (!username) {
|
const user = await this.findOneByNameandPassword(data);
|
||||||
throw new UnauthorizedException('Credenciales inválidas.');
|
|
||||||
}
|
|
||||||
|
|
||||||
const user = await this.findOneByName(username)
|
|
||||||
return user
|
return user
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user