From d9afbcd1e9ad7c6db1514896a9c4c32f9c79b837 Mon Sep 17 00:00:00 2001 From: IO420 <320154041@pcpuma.acatlan.unam.mx> Date: Wed, 10 Sep 2025 16:39:44 -0400 Subject: [PATCH] added Login --- src/student/entities/student.entity.ts | 49 +++++++++++++++++++++++++- src/user/dto/create-user.dto.ts | 2 +- src/user/user.controller.ts | 5 --- src/user/user.service.ts | 29 +++------------ 4 files changed, 54 insertions(+), 31 deletions(-) diff --git a/src/student/entities/student.entity.ts b/src/student/entities/student.entity.ts index d0dfbfb..cf56a28 100644 --- a/src/student/entities/student.entity.ts +++ b/src/student/entities/student.entity.ts @@ -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; +} diff --git a/src/user/dto/create-user.dto.ts b/src/user/dto/create-user.dto.ts index bdc828d..64c7d6c 100644 --- a/src/user/dto/create-user.dto.ts +++ b/src/user/dto/create-user.dto.ts @@ -3,7 +3,7 @@ import { IsString } from "class-validator"; export class CreateUserDto { @IsString() - username:string + usuario:string @IsString() password:string diff --git a/src/user/user.controller.ts b/src/user/user.controller.ts index ffe72cc..2c733ad 100644 --- a/src/user/user.controller.ts +++ b/src/user/user.controller.ts @@ -7,11 +7,6 @@ import { UpdateUserDto } from './dto/update-user.dto'; export class UserController { constructor(private readonly userService: UserService) {} - @Get() - findAll() { - return this.userService.findAll(); - } - @Post() Login(@Body() user: CreateUserDto) { return this.userService.Login(user); diff --git a/src/user/user.service.ts b/src/user/user.service.ts index 41e901b..83c581b 100644 --- a/src/user/user.service.ts +++ b/src/user/user.service.ts @@ -12,45 +12,26 @@ export class UserService { private userRepository: Repository, ) { } - create(createUserDto: CreateUserDto) { - return 'This action adds a new user'; - } + async findOneByNameandPassword(data:CreateUserDto): Promise { - findAll() { - return `This action returns all user`; - } - - async findOneByName(nombre: string): Promise { + const { usuario, password } = data const user = await this.userRepository.findOne({ - where: { nombre } + where: { usuario,password } }) if (!user) { throw new NotFoundException( - `El usuario ${nombre} no fue encontrado`, + `El usuario ${usuario} no fue encontrado`, ); } 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) { - const { username } = data - if (!username) { - throw new UnauthorizedException('Credenciales inválidas.'); - } - - const user = await this.findOneByName(username) + const user = await this.findOneByNameandPassword(data); return user }