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
-22
View File
@@ -1,22 +0,0 @@
import { Test, TestingModule } from '@nestjs/testing';
import { AppController } from './app.controller';
import { AppService } from './app.service';
describe('AppController', () => {
let appController: AppController;
beforeEach(async () => {
const app: TestingModule = await Test.createTestingModule({
controllers: [AppController],
providers: [AppService],
}).compile();
appController = app.get<AppController>(AppController);
});
describe('root', () => {
it('should return "Hello World!"', () => {
expect(appController.getHello()).toBe('Hello World!');
});
});
});
+22 -12
View File
@@ -1,24 +1,34 @@
import { Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { UserModule } from './user/user.module';
import { TypeOrmModule } from '@nestjs/typeorm';
import { StudentModule } from './student/student.module';
import { UserModule } from './user/user.module';
import { User } from './user/entities/user.entity';
@Module({
imports: [
TypeOrmModule.forRoot({
type: 'mysql',
host: 'localhost',
port: 3306,
username: 'root',
password: 'root',
database: 'test',
entities: [User],
synchronize: false,
ConfigModule.forRoot({
isGlobal: true,
envFilePath: '.env',
}),
UserModule],
TypeOrmModule.forRootAsync({
inject: [ConfigService],
useFactory: async (configService: ConfigService) => ({
type: 'mariadb',
host: configService.get<string>('DB_HOST'),
port: configService.get<number>('DB_PORT'),
username: configService.get<string>('DB_USER'),
password: configService.get<string>('DB_PASSWORD'),
database: configService.get<string>('DB_NAME'),
entities: [User],
synchronize: false,
}),
}),
UserModule,
],
controllers: [AppController],
providers: [AppService],
})
export class AppModule { }
export class AppModule {}
+17 -1
View File
@@ -3,6 +3,22 @@ import { Injectable } from '@nestjs/common';
@Injectable()
export class AppService {
getHello(): string {
return 'Hello World!';
return `
<h1>Guten Tag</h1>
<p>Todos los derechos reservados © 2025.</p>
<p>
Este sistema ha sido desarrollado con fines académicos y administrativos para la
Facultad de Estudios Superiores Acatlán, UNAM.
La distribución no autorizada o reproducción parcial o total del presente software está prohibida
por las disposiciones establecidas en el reglamento institucional y las leyes vigentes en materia de
propiedad intelectual.
</p>
<h4>
Encargado de la parte de programacion Lino
</h4>
<h4>
Programadores: Carlos, Axel
</h4>
`;
}
}
+1
View File
@@ -0,0 +1 @@
export class CreateStudentDto {}
+4
View File
@@ -0,0 +1,4 @@
import { PartialType } from '@nestjs/mapped-types';
import { CreateStudentDto } from './create-student.dto';
export class UpdateStudentDto extends PartialType(CreateStudentDto) {}
+1
View File
@@ -0,0 +1 @@
export class Student {}
+34
View File
@@ -0,0 +1,34 @@
import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common';
import { StudentService } from './student.service';
import { CreateStudentDto } from './dto/create-student.dto';
import { UpdateStudentDto } from './dto/update-student.dto';
@Controller('student')
export class StudentController {
constructor(private readonly studentService: StudentService) {}
@Post()
create(@Body() createStudentDto: CreateStudentDto) {
return this.studentService.create(createStudentDto);
}
@Get()
findAll() {
return this.studentService.findAll();
}
@Get(':id')
findOne(@Param('id') id: string) {
return this.studentService.findOne(+id);
}
@Patch(':id')
update(@Param('id') id: string, @Body() updateStudentDto: UpdateStudentDto) {
return this.studentService.update(+id, updateStudentDto);
}
@Delete(':id')
remove(@Param('id') id: string) {
return this.studentService.remove(+id);
}
}
+9
View File
@@ -0,0 +1,9 @@
import { Module } from '@nestjs/common';
import { StudentService } from './student.service';
import { StudentController } from './student.controller';
@Module({
controllers: [StudentController],
providers: [StudentService],
})
export class StudentModule {}
+26
View File
@@ -0,0 +1,26 @@
import { Injectable } from '@nestjs/common';
import { CreateStudentDto } from './dto/create-student.dto';
import { UpdateStudentDto } from './dto/update-student.dto';
@Injectable()
export class StudentService {
create(createStudentDto: CreateStudentDto) {
return 'This action adds a new student';
}
findAll() {
return `This action returns all student`;
}
findOne(id: number) {
return `This action returns a #${id} student`;
}
update(id: number, updateStudentDto: UpdateStudentDto) {
return `This action updates a #${id} student`;
}
remove(id: number) {
return `This action removes a #${id} student`;
}
}
+10 -1
View File
@@ -1 +1,10 @@
export class CreateUserDto {}
import { IsString } from "class-validator";
export class CreateUserDto {
@IsString()
username:string
@IsString()
password:string
}
+31 -2
View File
@@ -1,6 +1,35 @@
import { Entity } from "typeorm";
import { Column, Entity, PrimaryGeneratedColumn } from "typeorm";
@Entity()
@Entity({name:'usuario'})
export class User {
@PrimaryGeneratedColumn({name:'id_usuario',type: 'int'})
id_usuario:number;
@Column({name:'nombre',type:'varchar'})
nombre:string
@Column({name:'apellido_paterno',type:'varchar'})
apellido_paterno:string
@Column({name:'apellido_materno',type:'varchar'})
apellido_materno:string
@Column({name:'usuario',type:'varchar'})
usuario: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:'descripcion',type:'varchar',length:50,default:null})
description:boolean
@Column({name:'fecha_registro',type:'varchar'})
fecha_registro:string
@Column({name:'id_perfil',})
id_perfil:number
}
-20
View File
@@ -1,20 +0,0 @@
import { Test, TestingModule } from '@nestjs/testing';
import { UserController } from './user.controller';
import { UserService } from './user.service';
describe('UserController', () => {
let controller: UserController;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [UserController],
providers: [UserService],
}).compile();
controller = module.get<UserController>(UserController);
});
it('should be defined', () => {
expect(controller).toBeDefined();
});
});
+4 -18
View File
@@ -7,28 +7,14 @@ import { UpdateUserDto } from './dto/update-user.dto';
export class UserController {
constructor(private readonly userService: UserService) {}
@Post()
create(@Body() createUserDto: CreateUserDto) {
return this.userService.create(createUserDto);
}
@Get()
findAll() {
return this.userService.findAll();
}
@Get(':id')
findOne(@Param('id') id: string) {
return this.userService.findOne(+id);
}
@Patch(':id')
update(@Param('id') id: string, @Body() updateUserDto: UpdateUserDto) {
return this.userService.update(+id, updateUserDto);
}
@Delete(':id')
remove(@Param('id') id: string) {
return this.userService.remove(+id);
@Post()
Login(@Body() user: CreateUserDto) {
return this.userService.Login(user);
}
}
+6
View File
@@ -1,9 +1,15 @@
import { Module } from '@nestjs/common';
import { UserService } from './user.service';
import { UserController } from './user.controller';
import { TypeOrmModule } from '@nestjs/typeorm';
import { User } from './entities/user.entity';
@Module({
imports:[
TypeOrmModule.forFeature([User])
],
controllers: [UserController],
providers: [UserService],
exports: [UserService],
})
export class UserModule {}
-18
View File
@@ -1,18 +0,0 @@
import { Test, TestingModule } from '@nestjs/testing';
import { UserService } from './user.service';
describe('UserService', () => {
let service: UserService;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [UserService],
}).compile();
service = module.get<UserService>(UserService);
});
it('should be defined', () => {
expect(service).toBeDefined();
});
});
+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
}
}