This commit is contained in:
2025-09-24 11:34:50 -06:00
16 changed files with 225 additions and 20 deletions
+1 -3
View File
@@ -20,6 +20,4 @@ export class CreateStudentDto {
@IsEmail()
@IsString()
correo: string;
}
//Hubo pedos con la base , revisar
}
+3 -3
View File
@@ -84,9 +84,6 @@ export class Alumno {
@Column({ name: 'generacion', type: 'int', width: 4, nullable: true })
generacion: number | null;
@OneToMany(() => DetalleServicio, (detalle) => detalle.alum)
detalles_servicio: DetalleServicio[];
@ManyToOne(() => Carrera, (carrera) => carrera.estudiantes, {
eager: true,
nullable: true,
@@ -94,6 +91,9 @@ export class Alumno {
@JoinColumn({ name: 'id_carrera' })
carrera: Carrera;
@OneToMany(() => DetalleServicio, (detalle) => detalle.alum)
detalles_servicio: DetalleServicio[];
@OneToMany(() => AlumnoSancion, (alusancion) => alusancion.sancion)
sanciones: AlumnoSancion[];
+5
View File
@@ -16,5 +16,10 @@ export class AlumnoController {
findOne(@Param('id') id: number) {
return this.alumnoService.findOne(+id);
}
@Post('/create')
async newStudent(@Body() createStudentDto: CreateStudentDto) {
return this.alumnoService.create(createStudentDto);
}
}
//IO
+2 -2
View File
@@ -2,10 +2,10 @@ import { Module } from '@nestjs/common';
import { AlumnoService } from './student.service';
import { AlumnoController } from './student.controller';
import { TypeOrmModule } from '@nestjs/typeorm';
import { Alumno } from './entities/student.entity';
import { Alumno, Carrera } from './entities/student.entity';
@Module({
imports: [TypeOrmModule.forFeature([Alumno])],
imports: [TypeOrmModule.forFeature([Alumno,Carrera])],
controllers: [AlumnoController],
providers: [AlumnoService],
exports:[AlumnoService]
+16 -5
View File
@@ -1,6 +1,6 @@
import { Injectable, NotFoundException } from '@nestjs/common';
import { CreateStudentDto } from './dto/create-student.dto';
import { Alumno } from './entities/student.entity';
import { Alumno, Carrera } from './entities/student.entity';
import { EntityManager, Repository } from 'typeorm';
import { InjectRepository } from '@nestjs/typeorm';
@@ -9,17 +9,28 @@ export class AlumnoService {
constructor(
@InjectRepository(Alumno)
private readonly studentRepository: Repository<Alumno>,
@InjectRepository(Carrera)
private readonly carreraRepository: Repository<Carrera>,
) {}
async create(createStudentDto: CreateStudentDto): Promise<Alumno> {
//Hubo pedos con la base , revisar
const student = this.studentRepository.create(createStudentDto);
async create(data: CreateStudentDto): Promise<Alumno> {
const { id_carrera, ...rest } = data;
const carrera = await this.carreraRepository.findOne({
where: { id_carrera: data.id_carrera },
});
if (!carrera) {
throw new NotFoundException(`Carrera not found`);
}
const createStudent = { ...rest, carrera, fecha_registro: new Date() };
const student = this.studentRepository.create(createStudent);
return await this.studentRepository.save(student);
}
async findOne(id_cuenta: number): Promise<Alumno> {
const student = await this.studentRepository.findOne({
where: { id_cuenta: id_cuenta },
where: { id_cuenta },
select: { id_cuenta: true, nombre: true, credito: true },
});
if (!student) {