fixed name
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { IsBoolean, IsInt, IsNotEmpty, IsNumber, IsString, IsOptional, Length} from "class-validator";
|
||||
import { Type } from "class-transformer";
|
||||
import { IsBoolean, IsInt, IsNotEmpty, IsNumber, IsString, IsOptional, Length, ValidateNested} from "class-validator";
|
||||
|
||||
export class profesorDto{
|
||||
|
||||
@@ -81,12 +82,20 @@ export class profesorDto{
|
||||
@IsOptional()
|
||||
mostrar: boolean;
|
||||
|
||||
proyectosAcademicos: ProyectoDto[];
|
||||
@ValidateNested({ each: true })
|
||||
@Type(() => ProyectosAcademicos)
|
||||
proyectosAcademicos: ProyectosAcademicos[];
|
||||
|
||||
@ValidateNested({ each: true })
|
||||
@Type(() => DatosAcademicos)
|
||||
datosAcademicos: DatosAcademicos[];
|
||||
|
||||
@ValidateNested({ each: true })
|
||||
@Type(() => LineasInvestigacion)
|
||||
lineasInvestigacion: LineasInvestigacion[];
|
||||
}
|
||||
|
||||
export class ProyectoDto {
|
||||
export class ProyectosAcademicos {
|
||||
|
||||
@IsOptional()
|
||||
@Length(0, 500)
|
||||
|
||||
@@ -11,7 +11,7 @@ export class ProfesorController {
|
||||
constructor(private profesorService: ProfesorService) {}
|
||||
|
||||
@Post()
|
||||
// @Roles(Role.Responsable,Role.Admin)
|
||||
@Roles(Role.Responsable,Role.Admin)
|
||||
async register(@Body() data: profesorDto) {
|
||||
return this.profesorService.register(data);
|
||||
}
|
||||
|
||||
@@ -9,8 +9,6 @@ import { profesorDto } from './dto/profesorDto.dto';
|
||||
import { ProyectosAcademicos } from '../proyectos_academicos/entities/proyectos_academicos.entity';
|
||||
import { DatosAcademicos } from '../datos_academicos/entities/datos_academicos.entity'
|
||||
import { LineasInvestigacion } from '../lineas_investigacion/entities/lineas_investigacion.entity'
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
|
||||
@Injectable()
|
||||
export class ProfesorService {
|
||||
@@ -29,7 +27,7 @@ export class ProfesorService {
|
||||
) {}
|
||||
|
||||
//register teacher
|
||||
async register(data: profesorDto) {
|
||||
async register(data: profesorDto): Promise<Profesor | undefined> {
|
||||
const { num_trabajador, rfc, proyectosAcademicos, datosAcademicos, lineasInvestigacion} = data;
|
||||
|
||||
if (await this.profesorRepository.findOne({ where: { rfc } })) {
|
||||
@@ -55,9 +53,9 @@ export class ProfesorService {
|
||||
}
|
||||
|
||||
if (datosAcademicos && datosAcademicos.length > 0) {
|
||||
const datos = datosAcademicos.map(dato => {
|
||||
const datos = datosAcademicos.map(datosAcademicos => {
|
||||
const newDato = this.datosAcademicosRepository.create({
|
||||
...dato,
|
||||
...datosAcademicos,
|
||||
profesor: savedProfesor,
|
||||
id_profesor: savedProfesor.id_profesor,
|
||||
});
|
||||
@@ -115,19 +113,6 @@ export class ProfesorService {
|
||||
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 => {
|
||||
@@ -141,6 +126,19 @@ export class ProfesorService {
|
||||
await this.lineasInvestigacionRepository.save(lineas);
|
||||
}
|
||||
|
||||
if (datosAcademicos) {
|
||||
await this.datosAcademicosRepository.delete({ profesor: { id_profesor } });
|
||||
const datos = datosAcademicos.map(datosAcademicos => {
|
||||
const newDato = this.datosAcademicosRepository.create({
|
||||
...datosAcademicos,
|
||||
profesor: savedProfesor,
|
||||
id_profesor: savedProfesor.id_profesor,
|
||||
});
|
||||
return newDato;
|
||||
});
|
||||
await this.datosAcademicosRepository.save(datos);
|
||||
}
|
||||
|
||||
return savedProfesor;
|
||||
}
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ export class AuthService {
|
||||
}
|
||||
|
||||
//update user
|
||||
async update(userId, data:registerDto) {
|
||||
async update(id_usuario, data:registerDto) {
|
||||
|
||||
const{contraseña}=data;
|
||||
|
||||
@@ -77,11 +77,11 @@ export class AuthService {
|
||||
data = {...data,contraseña:hashedpassword};
|
||||
}
|
||||
|
||||
return await this.userRepository.update(userId, data);
|
||||
return await this.userRepository.update(id_usuario, data);
|
||||
}
|
||||
|
||||
async remove(userId: number): Promise<void> {
|
||||
await this.userRepository.delete(userId);
|
||||
async remove(id_usuario: number): Promise<void> {
|
||||
await this.userRepository.delete(id_usuario);
|
||||
}
|
||||
|
||||
//validate tojen of users
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@ export class ProyectosAcademicosService {
|
||||
private readonly proyectosAcademicosRepository: Repository<ProyectosAcademicos>,
|
||||
) {}
|
||||
|
||||
// Add methods to manage ProyectosAcademicos entities as needed
|
||||
async removeByProfesorId(id_profesor: number): Promise<void> {
|
||||
await this.proyectosAcademicosRepository.delete({ profesor: { id_profesor } });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user