fixed foreign key

This commit is contained in:
2025-09-18 16:50:10 -06:00
parent 719779b763
commit b7ac5aea50
18 changed files with 66 additions and 169 deletions
+11 -14
View File
@@ -9,25 +9,25 @@ import {
PrimaryGeneratedColumn,
} from 'typeorm';
@Entity({ name: 'carrea' })
@Entity({ name: 'carrera' })
export class Carrera {
@PrimaryGeneratedColumn({ name: 'id_carrera', type: 'int', unsigned: true })
id_carrera: number;
@Column({
name: 'nombre_carrea',
name: 'carrera',
type: 'varchar',
length: 100,
nullable: false,
})
nombre_carrea: string;
carrera: string;
@OneToMany(() => Student, (id_carrera) => id_carrera.id_cuenta)
id_carreras: Student[];
@OneToMany(() => Alumno, (student) => student.carrera)
estudiantes: Alumno[];
}
@Entity({ name: 'alumno' })
export class Student {
export class Alumno {
@PrimaryGeneratedColumn({ name: 'id_cuenta', type: 'int', unsigned: true })
id_cuenta: number;
@@ -83,19 +83,16 @@ export class Student {
@Column({ name: 'generacion', type: 'int', width: 4, nullable: true })
generacion: number | null;
@OneToMany(
() => DetalleServicio,
(id_detalle_servicio) => id_detalle_servicio.id_cuenta,
)
@OneToMany(() => DetalleServicio, (detalle) => detalle.id_cuenta)
detalles_servicio: DetalleServicio[];
@ManyToOne(() => Carrera, (id_cuenta) => id_cuenta.id_carreras, {
@ManyToOne(() => Carrera, (carrera) => carrera.estudiantes, {
eager: true,
nullable: true,
})
@JoinColumn({ name: 'id_carrera' })
id_periodos: Carrera;
carrera: Carrera;
@OneToMany(() => AlumnoSancion, (id_cuenta) => id_cuenta.id_alumno_sancion)
id_cuentas: AlumnoSancion[];
@OneToMany(() => AlumnoSancion, (alusancion) => alusancion.id_cuenta)
sanciones: AlumnoSancion[];
}
+3 -3
View File
@@ -1,19 +1,19 @@
import { Controller, Get, Post, Body, Param } from '@nestjs/common';
import { AlumnoService } from './student.service';
import { CreateStudentDto } from './dto/create-student.dto';
import { Student } from './entities/student.entity';
import { Alumno } from './entities/student.entity';
@Controller('student')
export class StudentController {
constructor(private readonly alumnoService: AlumnoService) {}
@Post()
async create(@Body() createStudentDto: CreateStudentDto): Promise<Student> {
async create(@Body() createStudentDto: CreateStudentDto): Promise<Alumno> {
return this.alumnoService.create(createStudentDto);
}
@Get()
async findAll(): Promise<Student[]> {
async findAll(): Promise<Alumno[]> {
return this.alumnoService.findAll();
}
+2 -2
View File
@@ -2,10 +2,10 @@ import { Module } from '@nestjs/common';
import { AlumnoService } from './student.service';
import { StudentController } from './student.controller';
import { TypeOrmModule } from '@nestjs/typeorm';
import { Student } from './entities/student.entity';
import { Alumno } from './entities/student.entity';
@Module({
imports: [TypeOrmModule.forFeature([Student])],
imports: [TypeOrmModule.forFeature([Alumno])],
controllers: [StudentController],
providers: [AlumnoService],
})
+8 -8
View File
@@ -1,27 +1,27 @@
import { Injectable, NotFoundException } from '@nestjs/common';
import { CreateStudentDto } from './dto/create-student.dto';
import { Student } from './entities/student.entity';
import { Alumno } from './entities/student.entity';
import { EntityManager, Repository } from 'typeorm';
import { InjectRepository } from '@nestjs/typeorm';
@Injectable()
export class AlumnoService {
constructor(
@InjectRepository(Student)
private readonly studentRepository: Repository<Student>,
@InjectRepository(Alumno)
private readonly studentRepository: Repository<Alumno>,
) {}
async create(createStudentDto: CreateStudentDto): Promise<Student> {
async create(createStudentDto: CreateStudentDto): Promise<Alumno> {
//Hubo pedos con la base , revisar
const student = this.studentRepository.create(createStudentDto);
return await this.studentRepository.save(student);
}
findAll(): Promise<Student[]> {
findAll(): Promise<Alumno[]> {
return this.studentRepository.find({ skip: 5000, take: 50 });
}
async findOne(id_cuenta: number): Promise<Student> {
async findOne(id_cuenta: number): Promise<Alumno> {
const student = await this.studentRepository.findOne({
where: { id_cuenta },
});
@@ -31,7 +31,7 @@ export class AlumnoService {
return student;
}
async GetCredit(id_cuenta: number): Promise<Student['credito']> {
async GetCredit(id_cuenta: number): Promise<Alumno['credito']> {
const student = await this.findOne(id_cuenta);
return student.credito;
}
@@ -41,7 +41,7 @@ export class AlumnoService {
credit: number,
manager: EntityManager,
) {
const repo = manager.getRepository(Student);
const repo = manager.getRepository(Alumno);
return await repo
.createQueryBuilder()
.update()