add lineas_investigacion,proyectos_academicos,datos_academicos to filter,register and update
This commit is contained in:
@@ -8,47 +8,47 @@ export class profesorDto{
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
@Length(10)
|
||||
@Length(0,10)
|
||||
num_trabajador: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
@Length(80)
|
||||
@Length(0,80)
|
||||
nombre: string;
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
@Length(10)
|
||||
@Length(0,10)
|
||||
rfc: string;
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
@Length(3)
|
||||
@Length(0,3)
|
||||
homoclave: string;
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
@Length(13)
|
||||
@Length(0,13)
|
||||
tel_oficina: string;
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
@Length(10)
|
||||
@Length(0,10)
|
||||
extension: string;
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
@Length(13)
|
||||
@Length(0,13)
|
||||
tel_personal: string;
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
@Length(65)
|
||||
@Length(0,65)
|
||||
correo_pcp: string;
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
@Length(65)
|
||||
@Length(0,65)
|
||||
correo_per: string;
|
||||
|
||||
@IsNumber()
|
||||
@@ -65,12 +65,12 @@ export class profesorDto{
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
@Length(256)
|
||||
@Length(0,256)
|
||||
ubicacion: string;
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
@Length(150)
|
||||
@Length(0,150)
|
||||
fotografia: string;
|
||||
|
||||
@IsBoolean()
|
||||
@@ -80,29 +80,33 @@ export class profesorDto{
|
||||
@IsBoolean()
|
||||
@IsOptional()
|
||||
mostrar: boolean;
|
||||
|
||||
proyectosAcademicos: ProyectoDto[];
|
||||
datosAcademicos: DatosAcademicos[];
|
||||
lineasInvestigacion: LineasInvestigacion[];
|
||||
}
|
||||
|
||||
export class CreateProyectoDto {
|
||||
export class ProyectoDto {
|
||||
|
||||
@IsOptional()
|
||||
@Length(500)
|
||||
@Length(0, 500)
|
||||
proyecto: string;
|
||||
}
|
||||
|
||||
export class CreateDatosAcademicos{
|
||||
export class DatosAcademicos{
|
||||
|
||||
@IsOptional()
|
||||
@Length(30)
|
||||
@Length(0,30)
|
||||
grado_maximo: string;
|
||||
|
||||
@IsOptional()
|
||||
@Length(600)
|
||||
@Length(0,600)
|
||||
grados_obtenidos: string;
|
||||
}
|
||||
|
||||
export class CreateLineasInvestigacion{
|
||||
export class LineasInvestigacion{
|
||||
|
||||
@IsOptional()
|
||||
@Length(300)
|
||||
@Length(0,300)
|
||||
lineas_inv: string;
|
||||
}
|
||||
@@ -104,10 +104,10 @@ export class Profesor {
|
||||
@OneToMany(() => DatosAcademicos, datosAcademicos => datosAcademicos.profesor)
|
||||
datosAcademicos: DatosAcademicos[];
|
||||
|
||||
@OneToMany(() => LineasInvestigacion, lineasInvestigacion => lineasInvestigacion.profesor)
|
||||
@OneToMany(() => LineasInvestigacion, linea => linea.profesor)
|
||||
lineasInvestigacion: LineasInvestigacion[];
|
||||
|
||||
@OneToMany(() => ProyectosAcademicos, proyectosAcademicos => proyectosAcademicos.profesor)
|
||||
@OneToMany(() => ProyectosAcademicos, proyecto => proyecto.profesor)
|
||||
proyectosAcademicos: ProyectosAcademicos[];
|
||||
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ export class ProfesorService {
|
||||
|
||||
//register teacher
|
||||
async register(data: profesorDto) {
|
||||
const {num_trabajador,rfc } = data;
|
||||
const {num_trabajador,rfc,proyectosAcademicos, datosAcademicos, lineasInvestigacion } = data;
|
||||
|
||||
const existrfc = await this.profesorRepository.findOne({where:{rfc}});
|
||||
if(existrfc){
|
||||
@@ -40,7 +40,45 @@ export class ProfesorService {
|
||||
}
|
||||
|
||||
const newProfesor = this.profesorRepository.create(data);
|
||||
return this.profesorRepository.save(newProfesor);
|
||||
const savedProfesor = await this.profesorRepository.save(newProfesor);
|
||||
|
||||
if (proyectosAcademicos && proyectosAcademicos.length > 0) {
|
||||
const proyectos = proyectosAcademicos.map(proyecto => {
|
||||
const newProyecto = this.proyectosAcademicosRepository.create({
|
||||
...proyecto,
|
||||
profesor: savedProfesor,
|
||||
id_profesor: savedProfesor.id_profesor,
|
||||
});
|
||||
return newProyecto;
|
||||
});
|
||||
await this.proyectosAcademicosRepository.save(proyectos);
|
||||
}
|
||||
|
||||
if (datosAcademicos && datosAcademicos.length > 0) {
|
||||
const datos = datosAcademicos.map(dato => {
|
||||
const newDato = this.datosAcademicosRepository.create({
|
||||
...dato,
|
||||
profesor: savedProfesor,
|
||||
id_profesor: savedProfesor.id_profesor,
|
||||
});
|
||||
return newDato;
|
||||
});
|
||||
await this.datosAcademicosRepository.save(datos);
|
||||
}
|
||||
|
||||
if (lineasInvestigacion && lineasInvestigacion.length > 0) {
|
||||
const lineas = lineasInvestigacion.map(linea => {
|
||||
const newLinea = this.lineasInvestigacionRepository.create({
|
||||
...linea,
|
||||
profesor: savedProfesor,
|
||||
id_profesor: savedProfesor.id_profesor,
|
||||
});
|
||||
return newLinea;
|
||||
});
|
||||
await this.lineasInvestigacionRepository.save(lineas);
|
||||
}
|
||||
|
||||
return savedProfesor;
|
||||
}
|
||||
|
||||
//brings all teachers
|
||||
@@ -59,8 +97,50 @@ export class ProfesorService {
|
||||
throw new HttpException('Profesor not found', 404);
|
||||
}
|
||||
|
||||
Object.assign(profesor, data);
|
||||
return this.profesorRepository.save(profesor);
|
||||
const { proyectosAcademicos, datosAcademicos, lineasInvestigacion, ...profesorData } = data;
|
||||
Object.assign(profesor, profesorData);
|
||||
const savedProfesor = await this.profesorRepository.save(profesor);
|
||||
|
||||
if (proyectosAcademicos) {
|
||||
await this.proyectosAcademicosRepository.delete({ profesor: { id_profesor } });
|
||||
const proyectos = proyectosAcademicos.map(proyecto => {
|
||||
const newProyecto = this.proyectosAcademicosRepository.create({
|
||||
...proyecto,
|
||||
profesor: savedProfesor,
|
||||
id_profesor: savedProfesor.id_profesor,
|
||||
});
|
||||
return newProyecto;
|
||||
});
|
||||
await this.proyectosAcademicosRepository.save(proyectos);
|
||||
}
|
||||
|
||||
if (datosAcademicos) {
|
||||
await this.datosAcademicosRepository.delete({ profesor: { id_profesor } });
|
||||
const datos = datosAcademicos.map(dato => {
|
||||
const newDato = this.datosAcademicosRepository.create({
|
||||
...dato,
|
||||
profesor: savedProfesor,
|
||||
id_profesor: savedProfesor.id_profesor,
|
||||
});
|
||||
return newDato;
|
||||
});
|
||||
await this.datosAcademicosRepository.save(datos);
|
||||
}
|
||||
|
||||
if (lineasInvestigacion) {
|
||||
await this.lineasInvestigacionRepository.delete({ profesor: { id_profesor } });
|
||||
const lineas = lineasInvestigacion.map(linea => {
|
||||
const newLinea = this.lineasInvestigacionRepository.create({
|
||||
...linea,
|
||||
profesor: savedProfesor,
|
||||
id_profesor: savedProfesor.id_profesor,
|
||||
});
|
||||
return newLinea;
|
||||
});
|
||||
await this.lineasInvestigacionRepository.save(lineas);
|
||||
}
|
||||
|
||||
return savedProfesor;
|
||||
}
|
||||
|
||||
//remove teacher
|
||||
@@ -120,8 +200,15 @@ export class ProfesorService {
|
||||
return query.getMany();
|
||||
}
|
||||
|
||||
async findAllPaginated(page: number, limit: number, filters: any): Promise<{ profesores: Profesor[], total: number, totalPages: number }> {
|
||||
const query = this.profesorRepository.createQueryBuilder('profesor');
|
||||
async findAllPaginated(
|
||||
page: number,
|
||||
limit: number,
|
||||
filters: any
|
||||
): Promise<{ profesores: Profesor[], total: number, totalPages: number }> {
|
||||
const query = this.profesorRepository.createQueryBuilder('profesor')
|
||||
.leftJoinAndSelect('profesor.proyectosAcademicos', 'proyectosAcademicos')
|
||||
.leftJoinAndSelect('profesor.datosAcademicos', 'datosAcademicos')
|
||||
.leftJoinAndSelect('profesor.lineasInvestigacion', 'lineasInvestigacion');
|
||||
|
||||
if (filters.nombre) {
|
||||
query.andWhere('profesor.nombre LIKE :nombre', { nombre: `%${filters.nombre}%` });
|
||||
|
||||
@@ -16,7 +16,7 @@ export class LineasInvestigacion {
|
||||
@Column({ type: 'varchar', length: 350, nullable: true })
|
||||
lineas_inv_html: string;
|
||||
|
||||
@ManyToOne(() => Profesor, profesor => profesor.lineasInvestigacion)
|
||||
@ManyToOne(() => Profesor, profesor => profesor.lineasInvestigacion)
|
||||
@JoinColumn({ name: 'id_profesor' })
|
||||
profesor: Profesor;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user