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
+44 -2
View File
@@ -10,6 +10,7 @@
"license": "UNLICENSED",
"dependencies": {
"@nestjs/common": "^11.0.1",
"@nestjs/config": "^4.0.2",
"@nestjs/core": "^11.0.1",
"@nestjs/mapped-types": "*",
"@nestjs/platform-express": "^11.0.1",
@@ -29,7 +30,7 @@
"@nestjs/testing": "^11.0.1",
"@types/express": "^5.0.0",
"@types/jest": "^30.0.0",
"@types/node": "^22.10.7",
"@types/node": "^22.18.1",
"@types/supertest": "^6.0.2",
"eslint": "^9.18.0",
"eslint-config-prettier": "^10.0.1",
@@ -2318,6 +2319,33 @@
}
}
},
"node_modules/@nestjs/config": {
"version": "4.0.2",
"resolved": "https://registry.npmjs.org/@nestjs/config/-/config-4.0.2.tgz",
"integrity": "sha512-McMW6EXtpc8+CwTUwFdg6h7dYcBUpH5iUILCclAsa+MbCEvC9ZKu4dCHRlJqALuhjLw97pbQu62l4+wRwGeZqA==",
"license": "MIT",
"dependencies": {
"dotenv": "16.4.7",
"dotenv-expand": "12.0.1",
"lodash": "4.17.21"
},
"peerDependencies": {
"@nestjs/common": "^10.0.0 || ^11.0.0",
"rxjs": "^7.1.0"
}
},
"node_modules/@nestjs/config/node_modules/dotenv": {
"version": "16.4.7",
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.7.tgz",
"integrity": "sha512-47qPchRCykZC03FhkYAhrvwU4xDBFIj1QPqaarj6mdM/hgUzfPHcpkHJOn3mJAufFeeAxAzeGsr5X0M4k6fLZQ==",
"license": "BSD-2-Clause",
"engines": {
"node": ">=12"
},
"funding": {
"url": "https://dotenvx.com"
}
},
"node_modules/@nestjs/core": {
"version": "11.1.6",
"resolved": "https://registry.npmjs.org/@nestjs/core/-/core-11.1.6.tgz",
@@ -4934,6 +4962,21 @@
"url": "https://dotenvx.com"
}
},
"node_modules/dotenv-expand": {
"version": "12.0.1",
"resolved": "https://registry.npmjs.org/dotenv-expand/-/dotenv-expand-12.0.1.tgz",
"integrity": "sha512-LaKRbou8gt0RNID/9RoI+J2rvXsBRPMV7p+ElHlPhcSARbCPDYcYG2s1TIzAfWv4YSgyY5taidWzzs31lNV3yQ==",
"license": "BSD-2-Clause",
"dependencies": {
"dotenv": "^16.4.5"
},
"engines": {
"node": ">=12"
},
"funding": {
"url": "https://dotenvx.com"
}
},
"node_modules/dunder-proto": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz",
@@ -7485,7 +7528,6 @@
"version": "4.17.21",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",
"integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==",
"dev": true,
"license": "MIT"
},
"node_modules/lodash.memoize": {
+2 -1
View File
@@ -21,6 +21,7 @@
},
"dependencies": {
"@nestjs/common": "^11.0.1",
"@nestjs/config": "^4.0.2",
"@nestjs/core": "^11.0.1",
"@nestjs/mapped-types": "*",
"@nestjs/platform-express": "^11.0.1",
@@ -40,7 +41,7 @@
"@nestjs/testing": "^11.0.1",
"@types/express": "^5.0.0",
"@types/jest": "^30.0.0",
"@types/node": "^22.10.7",
"@types/node": "^22.18.1",
"@types/supertest": "^6.0.2",
"eslint": "^9.18.0",
"eslint-config-prettier": "^10.0.1",
-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
}
}
-25
View File
@@ -1,25 +0,0 @@
import { Test, TestingModule } from '@nestjs/testing';
import { INestApplication } from '@nestjs/common';
import * as request from 'supertest';
import { App } from 'supertest/types';
import { AppModule } from './../src/app.module';
describe('AppController (e2e)', () => {
let app: INestApplication<App>;
beforeEach(async () => {
const moduleFixture: TestingModule = await Test.createTestingModule({
imports: [AppModule],
}).compile();
app = moduleFixture.createNestApplication();
await app.init();
});
it('/ (GET)', () => {
return request(app.getHttpServer())
.get('/')
.expect(200)
.expect('Hello World!');
});
});
-9
View File
@@ -1,9 +0,0 @@
{
"moduleFileExtensions": ["js", "json", "ts"],
"rootDir": ".",
"testEnvironment": "node",
"testRegex": ".e2e-spec.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
}
}