fixed foreign key
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { Student } from 'src/alumno/entities/student.entity';
|
||||
import { Alumno } from 'src/alumno/entities/student.entity';
|
||||
import { DetalleServicio } from 'src/detalle_servicio/entities/detalle_servicio.entity';
|
||||
import { OperationsController } from './operations.controller';
|
||||
import { OperationsService } from './operations.services';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
TypeOrmModule.forFeature([Student, DetalleServicio]), // entidades que usarán las transacciones
|
||||
TypeOrmModule.forFeature([Alumno, DetalleServicio]), // entidades que usarán las transacciones
|
||||
],
|
||||
controllers: [OperationsController],
|
||||
providers: [OperationsService],
|
||||
|
||||
@@ -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[];
|
||||
}
|
||||
|
||||
@@ -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,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],
|
||||
})
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { AlumnoSancionController } from './alumno_sancion.controller';
|
||||
import { AlumnoSancionService } from './alumno_sancion.service';
|
||||
|
||||
describe('AlumnoSancionController', () => {
|
||||
let controller: AlumnoSancionController;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
controllers: [AlumnoSancionController],
|
||||
providers: [AlumnoSancionService],
|
||||
}).compile();
|
||||
|
||||
controller = module.get<AlumnoSancionController>(AlumnoSancionController);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(controller).toBeDefined();
|
||||
});
|
||||
});
|
||||
@@ -1,34 +1,17 @@
|
||||
import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common';
|
||||
import { Controller, Get, Param } from '@nestjs/common';
|
||||
import { AlumnoSancionService } from './alumno_sancion.service';
|
||||
import { CreateAlumnoSancionDto } from './dto/create-alumno_sancion.dto';
|
||||
import { UpdateAlumnoSancionDto } from './dto/update-alumno_sancion.dto';
|
||||
|
||||
@Controller('alumno-sancion')
|
||||
export class AlumnoSancionController {
|
||||
constructor(private readonly alumnoSancionService: AlumnoSancionService) {}
|
||||
|
||||
@Post()
|
||||
create(@Body() createAlumnoSancionDto: CreateAlumnoSancionDto) {
|
||||
return this.alumnoSancionService.create(createAlumnoSancionDto);
|
||||
}
|
||||
|
||||
@Get()
|
||||
findAll() {
|
||||
return this.alumnoSancionService.findAll();
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
findOne(@Param('id') id: string) {
|
||||
findOne(@Param('id') id: number) {
|
||||
return this.alumnoSancionService.findOne(+id);
|
||||
}
|
||||
|
||||
@Patch(':id')
|
||||
update(@Param('id') id: string, @Body() updateAlumnoSancionDto: UpdateAlumnoSancionDto) {
|
||||
return this.alumnoSancionService.update(+id, updateAlumnoSancionDto);
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
remove(@Param('id') id: string) {
|
||||
return this.alumnoSancionService.remove(+id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,13 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { AlumnoSancionService } from './alumno_sancion.service';
|
||||
import { AlumnoSancionController } from './alumno_sancion.controller';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { AlumnoSancion } from './entities/alumno_sancion.entity';
|
||||
import { Alumno } from 'src/alumno/entities/student.entity';
|
||||
import { Sancion } from 'src/sancion/entities/sancion.entity';
|
||||
|
||||
@Module({
|
||||
imports:[TypeOrmModule.forFeature([AlumnoSancion,Alumno,Sancion])],
|
||||
controllers: [AlumnoSancionController],
|
||||
providers: [AlumnoSancionService],
|
||||
})
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { AlumnoSancionService } from './alumno_sancion.service';
|
||||
|
||||
describe('AlumnoSancionService', () => {
|
||||
let service: AlumnoSancionService;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [AlumnoSancionService],
|
||||
}).compile();
|
||||
|
||||
service = module.get<AlumnoSancionService>(AlumnoSancionService);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(service).toBeDefined();
|
||||
});
|
||||
});
|
||||
@@ -1,10 +1,7 @@
|
||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { CreateAlumnoSancionDto } from './dto/create-alumno_sancion.dto';
|
||||
import { UpdateAlumnoSancionDto } from './dto/update-alumno_sancion.dto';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { AlumnoSancion } from './entities/alumno_sancion.entity';
|
||||
import { Repository } from 'typeorm';
|
||||
import { Student } from 'src/alumno/entities/student.entity';
|
||||
|
||||
@Injectable()
|
||||
export class AlumnoSancionService {
|
||||
@@ -13,29 +10,17 @@ export class AlumnoSancionService {
|
||||
private readonly alumnosancionRepository: Repository<AlumnoSancion>,
|
||||
) {}
|
||||
|
||||
create(createAlumnoSancionDto: CreateAlumnoSancionDto) {
|
||||
return 'This action adds a new alumnoSancion';
|
||||
}
|
||||
|
||||
findAll() {
|
||||
return `This action returns all alumnoSancion`;
|
||||
}
|
||||
|
||||
async findOne(id_cuenta: CreateAlumnoSancionDto): Promise<AlumnoSancion> {
|
||||
async findOne(id_cuenta: number): Promise<AlumnoSancion> {
|
||||
const alusancion = await this.alumnosancionRepository.findOne({
|
||||
where: { id_cuenta },
|
||||
where: { id_cuenta:{id_cuenta} },
|
||||
});
|
||||
if (!alusancion) {
|
||||
throw new NotFoundException(`Student with ID ${id_cuenta} not found`);
|
||||
}
|
||||
return alusancion;
|
||||
}
|
||||
|
||||
update(id: number, updateAlumnoSancionDto: UpdateAlumnoSancionDto) {
|
||||
return `This action updates a #${id} alumnoSancion`;
|
||||
}
|
||||
|
||||
remove(id: number) {
|
||||
return `This action removes a #${id} alumnoSancion`;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Student } from 'src/alumno/entities/student.entity';
|
||||
import { Alumno } from 'src/alumno/entities/student.entity';
|
||||
import { Sancion } from 'src/sancion/entities/sancion.entity';
|
||||
import {
|
||||
Column,
|
||||
@@ -21,25 +21,17 @@ export class AlumnoSancion {
|
||||
})
|
||||
fecha_inicio: Date;
|
||||
|
||||
@ManyToOne(
|
||||
() => Student,
|
||||
(id_alumno_sancion) => id_alumno_sancion.id_cuentas,
|
||||
{
|
||||
eager: true,
|
||||
nullable: true,
|
||||
},
|
||||
)
|
||||
@ManyToOne(() => Alumno, (student) => student.sanciones, {
|
||||
eager: true,
|
||||
nullable: true,
|
||||
})
|
||||
@JoinColumn({ name: 'id_cuenta' })
|
||||
id_cuenta: Student;
|
||||
id_cuenta: Alumno;
|
||||
|
||||
@ManyToOne(
|
||||
() => Sancion,
|
||||
(id_alumno_sancion) => id_alumno_sancion.id_sanciones,
|
||||
{
|
||||
eager: true,
|
||||
nullable: true,
|
||||
},
|
||||
)
|
||||
@ManyToOne(() => Sancion, (sancion) => sancion.sancion, {
|
||||
eager: true,
|
||||
nullable: true,
|
||||
})
|
||||
@JoinColumn({ name: 'id_sancion' })
|
||||
id_sancion: Sancion;
|
||||
}
|
||||
|
||||
+5
-2
@@ -9,13 +9,14 @@ import { Perfil, User } from './user/entities/user.entity';
|
||||
import { DetalleServicioModule } from './detalle_servicio/detalle_servicio.module';
|
||||
import { PeriodoModule } from './periodo/periodo.module';
|
||||
import { ServicioModule } from './servicio/servicio.module';
|
||||
import { Student } from './alumno/entities/student.entity';
|
||||
import { Alumno, Carrera } from './alumno/entities/student.entity';
|
||||
import { DetalleServicio } from './detalle_servicio/entities/detalle_servicio.entity';
|
||||
import { Periodo } from './periodo/entities/periodo.entity';
|
||||
import { Servicio } from './servicio/entities/servicio.entity';
|
||||
import { SancionModule } from './sancion/sancion.module';
|
||||
import { AlumnoSancionModule } from './alumno_sancion/alumno_sancion.module';
|
||||
import { AlumnoSancion } from './alumno_sancion/entities/alumno_sancion.entity';
|
||||
import { Sancion } from './sancion/entities/sancion.entity';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
@@ -34,12 +35,14 @@ import { AlumnoSancion } from './alumno_sancion/entities/alumno_sancion.entity';
|
||||
database: configService.get<string>('DB_NAME'),
|
||||
entities: [
|
||||
User,
|
||||
Student,
|
||||
Alumno,
|
||||
DetalleServicio,
|
||||
Periodo,
|
||||
Servicio,
|
||||
Perfil,
|
||||
AlumnoSancion,
|
||||
Sancion,
|
||||
Carrera,
|
||||
],
|
||||
synchronize: false, //Never change to true in production!
|
||||
}),
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Student } from 'src/alumno/entities/student.entity';
|
||||
import { Alumno } from 'src/alumno/entities/student.entity';
|
||||
import { Periodo } from 'src/periodo/entities/periodo.entity';
|
||||
import { Servicio } from 'src/servicio/entities/servicio.entity';
|
||||
import { User } from 'src/user/entities/user.entity';
|
||||
@@ -38,17 +38,24 @@ export class DetalleServicio {
|
||||
})
|
||||
fecha_operacion: Date;
|
||||
|
||||
@ManyToOne(() => Student, (id_cuenta) => id_cuenta.detalles_servicio, {
|
||||
@Column()
|
||||
id_cuenta:number
|
||||
|
||||
@Column()
|
||||
id_servicio:number
|
||||
|
||||
|
||||
@ManyToOne(() => Alumno, (id_cuenta) => id_cuenta.detalles_servicio, {
|
||||
eager: true,
|
||||
})
|
||||
@JoinColumn({ name: 'id_cuenta' })
|
||||
id_cuenta: Student;
|
||||
cuenta: Alumno;
|
||||
|
||||
@ManyToOne(() => Servicio, (id_servicio) => id_servicio.detalles_servicio, {
|
||||
eager: true,
|
||||
})
|
||||
@JoinColumn({ name: 'id_servicio' })
|
||||
id_servicio: Servicio;
|
||||
servicio: Servicio;
|
||||
|
||||
@ManyToOne(() => User, (id_perfil) => id_perfil.detalles_servicio, {
|
||||
eager: true,
|
||||
|
||||
@@ -14,7 +14,7 @@ export class Sancion {
|
||||
|
||||
@OneToMany(
|
||||
() => AlumnoSancion,
|
||||
(id_sanncion) => id_sanncion.id_alumno_sancion,
|
||||
(alusancion) => alusancion.id_sancion,
|
||||
)
|
||||
id_sanciones: AlumnoSancion[];
|
||||
alumnosSancionados: AlumnoSancion[];
|
||||
}
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { SancionController } from './sancion.controller';
|
||||
import { SancionService } from './sancion.service';
|
||||
|
||||
describe('SancionController', () => {
|
||||
let controller: SancionController;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
controllers: [SancionController],
|
||||
providers: [SancionService],
|
||||
}).compile();
|
||||
|
||||
controller = module.get<SancionController>(SancionController);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(controller).toBeDefined();
|
||||
});
|
||||
});
|
||||
@@ -1,18 +0,0 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { SancionService } from './sancion.service';
|
||||
|
||||
describe('SancionService', () => {
|
||||
let service: SancionService;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [SancionService],
|
||||
}).compile();
|
||||
|
||||
service = module.get<SancionService>(SancionService);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(service).toBeDefined();
|
||||
});
|
||||
});
|
||||
@@ -8,6 +8,7 @@ export class Servicio {
|
||||
|
||||
@Column({ type: 'varchar', length: 45, nullable: false })
|
||||
servicio: string;
|
||||
|
||||
@OneToMany(
|
||||
() => DetalleServicio,
|
||||
(id_detalle_servicio) => id_detalle_servicio.id_servicio,
|
||||
|
||||
@@ -17,8 +17,8 @@ export class UserController {
|
||||
constructor(private readonly userService: UserService) {}
|
||||
|
||||
@Post()
|
||||
async Login(@Body() data: CreateUserDto, @Res() res: Response) {
|
||||
return this.userService.Login(data, res);
|
||||
async Login(@Body() data: CreateUserDto) {
|
||||
return this.userService.Login(data);
|
||||
}
|
||||
|
||||
@UseGuards(AuthGuard('jwt'))
|
||||
|
||||
Reference in New Issue
Block a user