added folder student and create new Ep Login

This commit is contained in:
2025-09-09 21:19:17 -04:00
parent c3444b619a
commit d73c0cf4e7
20 changed files with 245 additions and 134 deletions
+34 -3
View File
@@ -1,9 +1,17 @@
import { Injectable } 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';
import { User } from './entities/user.entity';
import { Repository } from 'typeorm';
@Injectable()
export class UserService {
constructor(
@InjectRepository(User)
private userRepository: Repository<User>,
) { }
create(createUserDto: CreateUserDto) {
return 'This action adds a new user';
}
@@ -12,8 +20,19 @@ export class UserService {
return `This action returns all user`;
}
findOne(id: number) {
return `This action returns a #${id} user`;
async findOneByName(nombre: string): Promise<User> {
const user = await this.userRepository.findOne({
where: { nombre }
})
if (!user) {
throw new NotFoundException(
`El usuario ${nombre} no fue encontrado`,
);
}
return user;
}
update(id: number, updateUserDto: UpdateUserDto) {
@@ -23,4 +42,16 @@ export class UserService {
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)
return user
}
}