Genero
This commit is contained in:
@@ -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 {
|
export class CreateStudentDto {
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
@@ -9,14 +17,21 @@ export class CreateStudentDto {
|
|||||||
@IsString()
|
@IsString()
|
||||||
nombre: string;
|
nombre: string;
|
||||||
|
|
||||||
|
@IsOptional()
|
||||||
@IsString()
|
@IsString()
|
||||||
fecha_nacimiento: string;
|
fecha_nacimiento?: string;
|
||||||
|
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
@IsNumber()
|
@IsNumber()
|
||||||
id_carrera: number;
|
id_carrera: number;
|
||||||
|
|
||||||
|
@IsOptional()
|
||||||
@IsEmail()
|
@IsEmail()
|
||||||
@IsString()
|
correo?: string;
|
||||||
correo: string;
|
|
||||||
}
|
@IsOptional()
|
||||||
|
@IsEnum(Genero, {
|
||||||
|
message: 'genero debe ser Femenino, Masculino u Otro',
|
||||||
|
})
|
||||||
|
genero?: Genero;
|
||||||
|
}
|
||||||
|
|||||||
@@ -11,6 +11,12 @@ import {
|
|||||||
PrimaryGeneratedColumn,
|
PrimaryGeneratedColumn,
|
||||||
} from 'typeorm';
|
} from 'typeorm';
|
||||||
|
|
||||||
|
export enum Genero {
|
||||||
|
FEMENINO = 'Femenino',
|
||||||
|
MASCULINO = 'Masculino',
|
||||||
|
OTRO = 'Otro',
|
||||||
|
}
|
||||||
|
|
||||||
@Entity({ name: 'alumno' })
|
@Entity({ name: 'alumno' })
|
||||||
export class Alumno {
|
export class Alumno {
|
||||||
@PrimaryGeneratedColumn({ name: 'id_cuenta', type: 'int', unsigned: true })
|
@PrimaryGeneratedColumn({ name: 'id_cuenta', type: 'int', unsigned: true })
|
||||||
@@ -68,6 +74,14 @@ export class Alumno {
|
|||||||
@Column({ name: 'generacion', type: 'int', width: 4, nullable: true })
|
@Column({ name: 'generacion', type: 'int', width: 4, nullable: true })
|
||||||
generacion: number | null;
|
generacion: number | null;
|
||||||
|
|
||||||
|
@Column({
|
||||||
|
name: 'genero',
|
||||||
|
type: 'enum',
|
||||||
|
enum: Genero,
|
||||||
|
nullable: true,
|
||||||
|
})
|
||||||
|
genero: Genero | null;
|
||||||
|
|
||||||
@ManyToOne(() => Carrera, (carrera) => carrera.estudiantes, {
|
@ManyToOne(() => Carrera, (carrera) => carrera.estudiantes, {
|
||||||
eager: true,
|
eager: true,
|
||||||
nullable: true,
|
nullable: true,
|
||||||
|
|||||||
@@ -11,6 +11,11 @@ import { Role } from 'src/role.enum';
|
|||||||
export class AlumnoController {
|
export class AlumnoController {
|
||||||
constructor(private readonly alumnoService: AlumnoService) {}
|
constructor(private readonly alumnoService: AlumnoService) {}
|
||||||
|
|
||||||
|
@Get()
|
||||||
|
async find(){
|
||||||
|
return this.alumnoService.findAll()
|
||||||
|
}
|
||||||
|
|
||||||
@Post()
|
@Post()
|
||||||
async create(@Body() createStudentDto: CreateStudentDto): Promise<Alumno> {
|
async create(@Body() createStudentDto: CreateStudentDto): Promise<Alumno> {
|
||||||
return this.alumnoService.create(createStudentDto);
|
return this.alumnoService.create(createStudentDto);
|
||||||
|
|||||||
@@ -14,6 +14,12 @@ export class AlumnoService {
|
|||||||
private readonly carreraRepository: Repository<Carrera>,
|
private readonly carreraRepository: Repository<Carrera>,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
|
async findAll(): Promise<Alumno[]> {
|
||||||
|
return this.studentRepository.find({
|
||||||
|
take: 100,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
async create(data: CreateStudentDto): Promise<Alumno> {
|
async create(data: CreateStudentDto): Promise<Alumno> {
|
||||||
const { id_carrera, ...rest } = data;
|
const { id_carrera, ...rest } = data;
|
||||||
const carrera = await this.carreraRepository.findOne({
|
const carrera = await this.carreraRepository.findOne({
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ export class AlumnoInscritoService {
|
|||||||
.getMany();
|
.getMany();
|
||||||
|
|
||||||
if (students.length === 0) {
|
if (students.length === 0) {
|
||||||
throw new NotFoundException('unregistered student');
|
throw new NotFoundException('Estudiante no Registrado');
|
||||||
}
|
}
|
||||||
|
|
||||||
return students;
|
return students;
|
||||||
|
|||||||
Reference in New Issue
Block a user