This commit is contained in:
2026-01-23 16:22:41 -06:00
parent d8133c0d0e
commit 1ae0911847
5 changed files with 46 additions and 6 deletions
+20 -5
View File
@@ -1,4 +1,12 @@
import { IsEmail, IsNotEmpty, IsNumber, IsString } from 'class-validator';
import {
IsEmail,
IsNotEmpty,
IsNumber,
IsString,
IsEnum,
IsOptional,
} from 'class-validator';
import { Genero } from '../entities/student.entity';
export class CreateStudentDto {
@IsNotEmpty()
@@ -9,14 +17,21 @@ export class CreateStudentDto {
@IsString()
nombre: string;
@IsOptional()
@IsString()
fecha_nacimiento: string;
fecha_nacimiento?: string;
@IsNotEmpty()
@IsNumber()
id_carrera: number;
@IsOptional()
@IsEmail()
@IsString()
correo: string;
}
correo?: string;
@IsOptional()
@IsEnum(Genero, {
message: 'genero debe ser Femenino, Masculino u Otro',
})
genero?: Genero;
}
+14
View File
@@ -11,6 +11,12 @@ import {
PrimaryGeneratedColumn,
} from 'typeorm';
export enum Genero {
FEMENINO = 'Femenino',
MASCULINO = 'Masculino',
OTRO = 'Otro',
}
@Entity({ name: 'alumno' })
export class Alumno {
@PrimaryGeneratedColumn({ name: 'id_cuenta', type: 'int', unsigned: true })
@@ -68,6 +74,14 @@ export class Alumno {
@Column({ name: 'generacion', type: 'int', width: 4, nullable: true })
generacion: number | null;
@Column({
name: 'genero',
type: 'enum',
enum: Genero,
nullable: true,
})
genero: Genero | null;
@ManyToOne(() => Carrera, (carrera) => carrera.estudiantes, {
eager: true,
nullable: true,
+5
View File
@@ -11,6 +11,11 @@ import { Role } from 'src/role.enum';
export class AlumnoController {
constructor(private readonly alumnoService: AlumnoService) {}
@Get()
async find(){
return this.alumnoService.findAll()
}
@Post()
async create(@Body() createStudentDto: CreateStudentDto): Promise<Alumno> {
return this.alumnoService.create(createStudentDto);
+6
View File
@@ -14,6 +14,12 @@ export class AlumnoService {
private readonly carreraRepository: Repository<Carrera>,
) {}
async findAll(): Promise<Alumno[]> {
return this.studentRepository.find({
take: 100,
});
}
async create(data: CreateStudentDto): Promise<Alumno> {
const { id_carrera, ...rest } = data;
const carrera = await this.carreraRepository.findOne({
@@ -74,7 +74,7 @@ export class AlumnoInscritoService {
.getMany();
if (students.length === 0) {
throw new NotFoundException('unregistered student');
throw new NotFoundException('Estudiante no Registrado');
}
return students;