merge into Lino
This commit is contained in:
@@ -2,6 +2,9 @@ import { Type } from "class-transformer";
|
||||
import { IsBoolean, IsInt, IsNotEmpty, IsNumber, IsString, IsOptional, Length, ValidateNested} from "class-validator";
|
||||
|
||||
export class profesorDto{
|
||||
|
||||
@IsInt()
|
||||
id_profesor: number;
|
||||
|
||||
@IsInt()
|
||||
@IsNotEmpty()
|
||||
@@ -99,7 +102,7 @@ export class ProyectosAcademicos {
|
||||
|
||||
@IsOptional()
|
||||
@Length(0, 500)
|
||||
proyecto: string;
|
||||
proyecto_html: string;
|
||||
}
|
||||
|
||||
export class DatosAcademicos{
|
||||
@@ -117,5 +120,5 @@ export class LineasInvestigacion{
|
||||
|
||||
@IsOptional()
|
||||
@Length(0,300)
|
||||
lineas_inv: string;
|
||||
lineas_inv_html: string;
|
||||
}
|
||||
@@ -1,11 +1,12 @@
|
||||
import {
|
||||
Entity,
|
||||
PrimaryGeneratedColumn,
|
||||
PrimaryColumn,
|
||||
Column,
|
||||
ManyToOne,
|
||||
OneToMany,
|
||||
JoinColumn, PrimaryColumn
|
||||
} from "typeorm";
|
||||
JoinColumn,
|
||||
Index,
|
||||
} from 'typeorm';
|
||||
import { Edificio } from '../../edificio/entities/edificio.entity';
|
||||
import { Adscripcion } from '../../adscripcion/entities/adscripcion.entity';
|
||||
import { Categoria } from '../../categoria/entities/categoria.entity';
|
||||
@@ -14,12 +15,12 @@ import { LineasInvestigacion } from '../../lineas_investigacion/entities/lineas_
|
||||
import { ProyectosAcademicos } from '../../proyectos_academicos/entities/proyectos_academicos.entity';
|
||||
import { User } from 'src/users/entities/user.entity';
|
||||
|
||||
@Entity()
|
||||
@Entity({ name: 'profesor' })
|
||||
export class Profesor {
|
||||
@PrimaryColumn()
|
||||
@PrimaryColumn({ type: 'int', nullable: false })
|
||||
id_profesor: number;
|
||||
|
||||
@Column({ type: 'int',nullable: false })
|
||||
@Column({ type: 'int', nullable: false })
|
||||
id_usuario: number;
|
||||
|
||||
@Column({ type: 'varchar', length: 10, nullable: true })
|
||||
@@ -86,19 +87,19 @@ export class Profesor {
|
||||
fecha_actualizacion: Date;
|
||||
|
||||
@ManyToOne(() => Edificio, edificio => edificio.profesores)
|
||||
@JoinColumn({ name: 'id_edificio' })
|
||||
@JoinColumn({ name: 'id_edificio', referencedColumnName: 'id_edificio', foreignKeyConstraintName: 'FK_edificio_fk' })
|
||||
edificio: Edificio;
|
||||
|
||||
@ManyToOne(() => Adscripcion, adscripcion => adscripcion.profesores)
|
||||
@JoinColumn({ name: 'id_adscripcion' })
|
||||
@JoinColumn({ name: 'id_adscripcion', referencedColumnName: 'id_adscripcion', foreignKeyConstraintName: 'FK_adscripcion_fk' })
|
||||
adscripcion: Adscripcion;
|
||||
|
||||
@ManyToOne(() => Categoria, categoria => categoria.profesores)
|
||||
@JoinColumn({ name: 'id_categoria' })
|
||||
@JoinColumn({ name: 'id_categoria', referencedColumnName: 'id_categoria', foreignKeyConstraintName: 'FK_categoria_fk' })
|
||||
categoria: Categoria;
|
||||
|
||||
@ManyToOne(() => User, user => user.profesores)
|
||||
@JoinColumn({ name: 'id_usuario' })
|
||||
@JoinColumn({ name: 'id_usuario', referencedColumnName: 'id_usuario', foreignKeyConstraintName: 'FK_usuario_fk' })
|
||||
user: User;
|
||||
|
||||
@OneToMany(() => DatosAcademicos, datosAcademicos => datosAcademicos.profesor,{ cascade: true })
|
||||
|
||||
@@ -1,48 +1,75 @@
|
||||
import { Body, Controller, Delete, Get, Param, ParseIntPipe, Post, Put, Query,UseGuards } from '@nestjs/common';
|
||||
import { ProfesorService } from './profesor.service';
|
||||
import { profesorDto } from './dto/profesorDto.dto';
|
||||
import {Roles} from '../permissions/roles.decorator'
|
||||
import {RolesGuard} from '../permissions/roles.guard'
|
||||
import {Role} from '../permissions/role.enum'
|
||||
import {
|
||||
Body,
|
||||
Controller,
|
||||
Delete,
|
||||
Get,
|
||||
Logger,
|
||||
Param,
|
||||
ParseIntPipe,
|
||||
Post,
|
||||
Put,
|
||||
Query,
|
||||
UseGuards
|
||||
} from "@nestjs/common";
|
||||
import { ProfesorService } from "./profesor.service";
|
||||
import { profesorDto } from "./dto/profesorDto.dto";
|
||||
import { Roles } from "../permissions/roles.decorator";
|
||||
import { RolesGuard } from "../permissions/roles.guard";
|
||||
import { Role } from "../permissions/role.enum";
|
||||
|
||||
@Controller('profesor')
|
||||
@Controller("profesor")
|
||||
@UseGuards(RolesGuard)
|
||||
export class ProfesorController {
|
||||
constructor(private profesorService: ProfesorService) {}
|
||||
constructor(private profesorService: ProfesorService) {
|
||||
}
|
||||
|
||||
@Post()
|
||||
@Roles(Role.Responsable,Role.Admin)
|
||||
@Roles(Role.Responsable, Role.Admin)
|
||||
async register(@Body() data: profesorDto) {
|
||||
Logger.debug("register profesor");
|
||||
return this.profesorService.register(data);
|
||||
}
|
||||
|
||||
@Get()
|
||||
findAll() {
|
||||
Logger.debug("findAllProfesors");
|
||||
return this.profesorService.findAll();
|
||||
}
|
||||
|
||||
@Get('page')
|
||||
findAllPaginated(@Query('page') page: number = 1, @Query('limit') limit: number = 10, @Query() filters: any) {
|
||||
page = page < 1 ? 1 : page;
|
||||
limit = limit > 10 || limit < 1 ? 10 : limit;
|
||||
@Get("page")
|
||||
findAllPaginated(@Query("page") page: number = 1, @Query("limit") limit: number = 10, @Query() filters: any) {
|
||||
try {
|
||||
Logger.debug("Page Profesors");
|
||||
page = page < 1 ? 1 : page;
|
||||
limit = limit > 10 || limit < 1 ? 10 : limit;
|
||||
return this.profesorService.findAllPaginated(page, limit, filters);
|
||||
} catch (err) {
|
||||
Logger.error("profesor controller ", err.error);
|
||||
return [];
|
||||
}
|
||||
|
||||
return this.profesorService.findAllPaginated(page, limit, filters);
|
||||
}
|
||||
|
||||
@Put(':id_profesor')
|
||||
@Roles(Role.Responsable,Role.Admin)
|
||||
async modify(@Param('id_profesor', ParseIntPipe) id_profesor: number, @Body() data: profesorDto) {
|
||||
@Put(":id_profesor")
|
||||
@Roles(Role.Responsable, Role.Admin)
|
||||
async modify(@Param("id_profesor", ParseIntPipe) id_profesor: number, @Body() data: profesorDto) {
|
||||
Logger.debug("put Profesors by id");
|
||||
|
||||
return this.profesorService.modify(id_profesor, data);
|
||||
}
|
||||
|
||||
@Delete(':id_profesor')
|
||||
@Roles(Role.Responsable,Role.Admin)
|
||||
async remove(@Param('id_profesor', ParseIntPipe) id_profesor: number) {
|
||||
@Delete(":id_profesor")
|
||||
@Roles(Role.Responsable, Role.Admin)
|
||||
async remove(@Param("id_profesor", ParseIntPipe) id_profesor: number) {
|
||||
Logger.debug("delete Profesors by id");
|
||||
|
||||
return this.profesorService.remove(id_profesor);
|
||||
}
|
||||
|
||||
@Get(':id_profesor')
|
||||
async profile(@Param('id_profesor', ParseIntPipe) id_profesor: number) {
|
||||
@Get(":id_profesor")
|
||||
async profile(@Param("id_profesor", ParseIntPipe) id_profesor: number) {
|
||||
Logger.debug("get Profesors by id");
|
||||
|
||||
return this.profesorService.profile(id_profesor);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
import { HttpException, Injectable } from '@nestjs/common';
|
||||
import { Profesor } from './entities/profesor.entity';
|
||||
import { DatosAcademicosService } from '../datos_academicos/datos_academicos.service';
|
||||
import { LineasInvestigacionService } from '../lineas_investigacion/lineas_investigacion.service';
|
||||
import { ProyectosAcademicosService } from '../proyectos_academicos/proyectos_academicos.service';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
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 { HttpException, Injectable, Logger } from "@nestjs/common";
|
||||
import { Profesor } from "./entities/profesor.entity";
|
||||
import { DatosAcademicosService } from "../datos_academicos/datos_academicos.service";
|
||||
import { LineasInvestigacionService } from "../lineas_investigacion/lineas_investigacion.service";
|
||||
import { ProyectosAcademicosService } from "../proyectos_academicos/proyectos_academicos.service";
|
||||
import { InjectRepository } from "@nestjs/typeorm";
|
||||
import { Repository } from "typeorm";
|
||||
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";
|
||||
|
||||
@Injectable()
|
||||
export class ProfesorService {
|
||||
constructor(
|
||||
@InjectRepository(Profesor)
|
||||
@InjectRepository(Profesor)
|
||||
private readonly profesorRepository: Repository<Profesor>,
|
||||
private readonly datosAcademicosService: DatosAcademicosService,
|
||||
private readonly lineasInvestigacionService: LineasInvestigacionService,
|
||||
@@ -23,21 +23,38 @@ export class ProfesorService {
|
||||
@InjectRepository(LineasInvestigacion)
|
||||
private readonly lineasInvestigacionRepository: Repository<LineasInvestigacion>,
|
||||
@InjectRepository(ProyectosAcademicos)
|
||||
private readonly proyectosAcademicosRepository: Repository<ProyectosAcademicos>,
|
||||
) {}
|
||||
private readonly proyectosAcademicosRepository: Repository<ProyectosAcademicos>
|
||||
) {
|
||||
}
|
||||
|
||||
private async findAvailableId(): Promise<number> {
|
||||
let id = 1;
|
||||
let exists = true;
|
||||
|
||||
while (exists) {
|
||||
if (!await this.profesorRepository.findOne({ where: { id_profesor: id } })) {
|
||||
exists = false;
|
||||
return id;
|
||||
}
|
||||
id++;
|
||||
}
|
||||
}
|
||||
|
||||
//register teacher
|
||||
async register(data: profesorDto): Promise<Profesor | undefined> {
|
||||
const { num_trabajador, rfc, proyectosAcademicos, datosAcademicos, lineasInvestigacion} = data;
|
||||
const { num_trabajador, rfc, proyectosAcademicos, datosAcademicos, lineasInvestigacion } = data;
|
||||
|
||||
if (await this.profesorRepository.findOne({ where: { rfc } })) {
|
||||
throw new HttpException('rfc already exist', 403);
|
||||
throw new HttpException("rfc already exist", 403);
|
||||
}
|
||||
|
||||
if (await this.profesorRepository.findOne({ where: { num_trabajador } })) {
|
||||
throw new HttpException('number of worker already exist', 403);
|
||||
throw new HttpException("number of worker already exist", 403);
|
||||
}
|
||||
|
||||
const availableId = await this.findAvailableId();
|
||||
data.id_profesor = availableId;
|
||||
|
||||
const savedProfesor = await this.profesorRepository.save(data);
|
||||
|
||||
if (proyectosAcademicos && proyectosAcademicos.length > 0) {
|
||||
@@ -45,7 +62,7 @@ export class ProfesorService {
|
||||
const newProyecto = this.proyectosAcademicosRepository.create({
|
||||
...proyecto,
|
||||
profesor: savedProfesor,
|
||||
id_profesor: savedProfesor.id_profesor,
|
||||
id_profesor: savedProfesor.id_profesor
|
||||
});
|
||||
return newProyecto;
|
||||
});
|
||||
@@ -57,7 +74,7 @@ export class ProfesorService {
|
||||
const newLinea = this.lineasInvestigacionRepository.create({
|
||||
...linea,
|
||||
profesor: savedProfesor,
|
||||
id_profesor: savedProfesor.id_profesor,
|
||||
id_profesor: savedProfesor.id_profesor
|
||||
});
|
||||
return newLinea;
|
||||
});
|
||||
@@ -69,7 +86,7 @@ export class ProfesorService {
|
||||
const newDato = this.datosAcademicosRepository.create({
|
||||
...datosAcademicos,
|
||||
profesor: savedProfesor,
|
||||
id_profesor: savedProfesor.id_profesor,
|
||||
id_profesor: savedProfesor.id_profesor
|
||||
});
|
||||
return newDato;
|
||||
});
|
||||
@@ -83,8 +100,8 @@ export class ProfesorService {
|
||||
async findAll(): Promise<Profesor[]> {
|
||||
return this.profesorRepository.find({
|
||||
order: {
|
||||
nombre: 'ASC',
|
||||
},
|
||||
nombre: "ASC"
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -92,7 +109,7 @@ export class ProfesorService {
|
||||
async modify(id_profesor: number, data: profesorDto) {
|
||||
const profesor = await this.profesorRepository.findOne({ where: { id_profesor } });
|
||||
if (!profesor) {
|
||||
throw new HttpException('Profesor not found', 404);
|
||||
throw new HttpException("Profesor not found", 404);
|
||||
}
|
||||
|
||||
const { proyectosAcademicos, datosAcademicos, lineasInvestigacion, ...profesorData } = data;
|
||||
@@ -106,7 +123,7 @@ export class ProfesorService {
|
||||
const newProyecto = this.proyectosAcademicosRepository.create({
|
||||
...proyecto,
|
||||
profesor: savedProfesor,
|
||||
id_profesor: savedProfesor.id_profesor,
|
||||
id_profesor: savedProfesor.id_profesor
|
||||
});
|
||||
return newProyecto;
|
||||
});
|
||||
@@ -114,12 +131,12 @@ export class ProfesorService {
|
||||
}
|
||||
|
||||
if (lineasInvestigacion) {
|
||||
await this.lineasInvestigacionRepository.delete({ profesor: {id_profesor}});
|
||||
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,
|
||||
id_profesor: savedProfesor.id_profesor
|
||||
});
|
||||
return newLinea;
|
||||
});
|
||||
@@ -132,7 +149,7 @@ export class ProfesorService {
|
||||
const newDato = this.datosAcademicosRepository.create({
|
||||
...datosAcademicos,
|
||||
profesor: savedProfesor,
|
||||
id_profesor: savedProfesor.id_profesor,
|
||||
id_profesor: savedProfesor.id_profesor
|
||||
});
|
||||
return newDato;
|
||||
});
|
||||
@@ -144,28 +161,28 @@ export class ProfesorService {
|
||||
|
||||
//remove teacher
|
||||
async remove(id_profesor: number) {
|
||||
const profesor = await this.profesorRepository.findOne({ where: { id_profesor }, relations: ['datosAcademicos'] });
|
||||
const profesor = await this.profesorRepository.findOne({ where: { id_profesor }, relations: ["datosAcademicos"] });
|
||||
if (!profesor) {
|
||||
throw new HttpException('Profesor not found', 404);
|
||||
throw new HttpException("Profesor not found", 404);
|
||||
}
|
||||
|
||||
await this.datosAcademicosService.removeByProfesorId(id_profesor);
|
||||
await this.lineasInvestigacionService.removeByProfesorId(id_profesor);
|
||||
await this.proyectosAcademicosService.removeByProfesorId(id_profesor);
|
||||
await this.datosAcademicosService.removeByProfesorId(id_profesor);
|
||||
await this.lineasInvestigacionService.removeByProfesorId(id_profesor);
|
||||
await this.proyectosAcademicosService.removeByProfesorId(id_profesor);
|
||||
|
||||
await this.profesorRepository.remove(profesor);
|
||||
return { message: 'Profesor removed successfully' };
|
||||
return { message: "Profesor removed successfully" };
|
||||
}
|
||||
|
||||
//brings teachers by id
|
||||
async profile(id_profesor: number) {
|
||||
const profesor = await this.profesorRepository.findOne({
|
||||
where: { id_profesor },
|
||||
relations: ['proyectosAcademicos', 'datosAcademicos', 'lineasInvestigacion'],
|
||||
relations: ["proyectosAcademicos", "datosAcademicos", "lineasInvestigacion"]
|
||||
});
|
||||
|
||||
|
||||
if (!profesor) {
|
||||
throw new HttpException('Profesor not found', 404);
|
||||
throw new HttpException("Profesor not found", 404);
|
||||
}
|
||||
|
||||
return profesor;
|
||||
@@ -176,43 +193,53 @@ export class ProfesorService {
|
||||
limit: number,
|
||||
filters: any
|
||||
): Promise<{ profesores: Profesor[], total: number, totalPages: number }> {
|
||||
const query = this.profesorRepository.createQueryBuilder('profesor');
|
||||
|
||||
const query = this.profesorRepository.createQueryBuilder("profesor");
|
||||
|
||||
if (filters.nombre) {
|
||||
query.andWhere('profesor.nombre LIKE :nombre', { nombre: `%${filters.nombre}%` });
|
||||
Logger.debug('fiter by name');
|
||||
|
||||
query.andWhere("profesor.nombre LIKE :nombre", { nombre: `%${filters.nombre}%` });
|
||||
}
|
||||
|
||||
|
||||
if (filters.adscripcion) {
|
||||
query.andWhere('profesor.adscripcion = :adscripcion', { adscripcion: filters.adscripcion });
|
||||
Logger.debug("fiter by adscription");
|
||||
|
||||
query.andWhere("profesor.adscripcion = :adscripcion", { adscripcion: filters.adscripcion });
|
||||
}
|
||||
|
||||
|
||||
if (filters.categoria) {
|
||||
query.andWhere('profesor.categoria = :categoria', { categoria: filters.categoria });
|
||||
Logger.debug("fiter by category");
|
||||
|
||||
query.andWhere("profesor.categoria = :categoria", { categoria: filters.categoria });
|
||||
}
|
||||
|
||||
|
||||
if (filters.edificio) {
|
||||
query.andWhere('profesor.edificio = :edificio', { edificio: filters.edificio });
|
||||
Logger.debug("fiter by building");
|
||||
|
||||
query.andWhere("profesor.edificio = :edificio", { edificio: filters.edificio });
|
||||
}
|
||||
|
||||
if (typeof filters.activo !== 'undefined') {
|
||||
query.andWhere('profesor.activo = :activo', { activo: filters.activo });
|
||||
|
||||
if (typeof filters.activo !== "undefined") {
|
||||
Logger.debug("fiter by is active");
|
||||
|
||||
query.andWhere("profesor.activo = :activo", { activo: filters.activo });
|
||||
} else {
|
||||
query.orderBy('profesor.activo', 'DESC');
|
||||
query.orderBy("profesor.activo", "DESC");
|
||||
}
|
||||
|
||||
query.addOrderBy('profesor.nombre', 'ASC');
|
||||
|
||||
|
||||
query.addOrderBy("profesor.nombre", "ASC");
|
||||
|
||||
const [profesores, total] = await query
|
||||
.skip((page - 1) * limit)
|
||||
.take(limit)
|
||||
.getManyAndCount();
|
||||
|
||||
|
||||
const totalPages = Math.ceil(total / limit);
|
||||
|
||||
|
||||
return { profesores, total, totalPages };
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
async updateImageURL(id_profesor: number, imageUrl: string): Promise<void> {
|
||||
await this.profesorRepository.update(id_profesor, { fotografia: imageUrl });
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Entity, PrimaryColumn, Column, OneToMany } from 'typeorm';
|
||||
import { Entity, PrimaryColumn, Column, OneToMany, Index } from 'typeorm';
|
||||
|
||||
@Entity()
|
||||
@Entity({ name: 'adscripcion' })
|
||||
export class Adscripcion {
|
||||
@PrimaryColumn({ type: 'int', nullable: false })
|
||||
id_adscripcion: number;
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@ import { Injectable } from '@nestjs/common';
|
||||
@Injectable()
|
||||
export class AppService {
|
||||
getHello(): string {
|
||||
console.log("it's ok ")
|
||||
console.log("it's ok IO")
|
||||
|
||||
return "hei verden";
|
||||
}
|
||||
|
||||
@@ -73,13 +73,18 @@ export class AuthService {
|
||||
}
|
||||
|
||||
//update user
|
||||
async update(id_usuario, data:registerDto) {
|
||||
async update(id_usuario: number, data: registerDto) {
|
||||
const { contraseña } = data;
|
||||
|
||||
const{contraseña}=data;
|
||||
|
||||
if(contraseña){
|
||||
if (contraseña) {
|
||||
const hashedpassword = await hash(contraseña, 10);
|
||||
data = {...data,contraseña:hashedpassword};
|
||||
data = { ...data, contraseña: hashedpassword };
|
||||
} else {
|
||||
const user = await this.userRepository.findOne({ where: { id_usuario } });
|
||||
if (!user) {
|
||||
throw new HttpException('User not found', 404);
|
||||
}
|
||||
data = { ...data, contraseña: user.contraseña };
|
||||
}
|
||||
|
||||
return await this.userRepository.update(id_usuario, data);
|
||||
@@ -108,7 +113,7 @@ export class AuthService {
|
||||
throw new UnauthorizedException('Token has expired');
|
||||
}
|
||||
|
||||
return user;
|
||||
return ;
|
||||
} catch (error) {
|
||||
throw new UnauthorizedException('validation token failed');
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Entity, PrimaryColumn, Column, OneToMany } from 'typeorm';
|
||||
import { Entity, PrimaryColumn, Column, OneToMany, Index } from 'typeorm';
|
||||
|
||||
@Entity()
|
||||
@Entity({ name: 'categoria' })
|
||||
export class Categoria {
|
||||
@PrimaryColumn({ type: 'int', nullable: false })
|
||||
id_categoria: number;
|
||||
@@ -10,4 +10,4 @@ export class Categoria {
|
||||
|
||||
@OneToMany(() => Categoria, (categoria) => categoria.profesores)
|
||||
profesores: Categoria[];
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@ import { Profesor } from '../../Profesor/entities/profesor.entity';
|
||||
|
||||
@Entity({ name: 'datos_academicos' })
|
||||
export class DatosAcademicos {
|
||||
@PrimaryGeneratedColumn()
|
||||
@PrimaryGeneratedColumn({ name: 'PK_datos_academicos' })
|
||||
id_datos: number;
|
||||
|
||||
@Column({ type: 'int', nullable: false })
|
||||
@@ -16,6 +16,6 @@ export class DatosAcademicos {
|
||||
grados_obtenidos: string;
|
||||
|
||||
@ManyToOne(() => Profesor, (profesor) => profesor.datosAcademicos)
|
||||
@JoinColumn({ name: 'id_profesor' })
|
||||
@JoinColumn({ name: 'id_profesor', referencedColumnName: 'id_profesor', foreignKeyConstraintName: 'FK_datos_academicos' })
|
||||
profesor: Profesor;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Entity, PrimaryColumn, Column, OneToMany } from 'typeorm';
|
||||
import { Entity, PrimaryColumn, Column, OneToMany, Index } from 'typeorm';
|
||||
|
||||
@Entity()
|
||||
@Entity({ name: 'edificio' })
|
||||
export class Edificio {
|
||||
@PrimaryColumn({ type: 'int', nullable: false })
|
||||
id_edificio: number;
|
||||
|
||||
@@ -4,17 +4,16 @@ import { Profesor } from "../../Profesor/entities/profesor.entity";
|
||||
@Entity({ name: 'lineas_investigacion' })
|
||||
export class LineasInvestigacion {
|
||||
|
||||
@PrimaryGeneratedColumn()
|
||||
@PrimaryGeneratedColumn({ name: 'PK_lineas_investigacion' })
|
||||
id_linea_inv: number;
|
||||
|
||||
@Column({ type: 'int', nullable: false })
|
||||
id_profesor: number;
|
||||
|
||||
|
||||
@Column({ type: 'varchar', length: 350, nullable: true })
|
||||
lineas_inv_html: string;
|
||||
|
||||
@ManyToOne(() => Profesor, profesor => profesor.lineasInvestigacion)
|
||||
@JoinColumn({ name: 'id_profesor' })
|
||||
@JoinColumn({ name: 'id_profesor', referencedColumnName: 'id_profesor', foreignKeyConstraintName: 'FK_lineas_investigacion' })
|
||||
profesor: Profesor;
|
||||
}
|
||||
|
||||
@@ -44,11 +44,14 @@ export class RolesGuard implements CanActivate {
|
||||
);
|
||||
|
||||
const userRole: Role = userPayload.id_tipo_usuario;
|
||||
if (userRole === undefined) {
|
||||
return false; // Si el token no contiene roles, se niega el acceso
|
||||
const userId: number = userPayload.id_usuario;
|
||||
|
||||
const paramId = parseInt(request.params.id_usuario, 10);
|
||||
if (requiredRoles.includes(userRole) || userId === paramId) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return requiredRoles.includes(userRole);
|
||||
return false;
|
||||
} catch (error) {
|
||||
throw new UnauthorizedException('Invalid token');
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import { Profesor } from "../../Profesor/entities/profesor.entity";
|
||||
@Entity({ name: 'proyectos_academicos' })
|
||||
export class ProyectosAcademicos {
|
||||
|
||||
@PrimaryGeneratedColumn()
|
||||
@PrimaryGeneratedColumn({ name: 'PK_proyectos_academicos' })
|
||||
id_proyecto: number;
|
||||
|
||||
@Column({ type: 'int', nullable: false })
|
||||
@@ -14,6 +14,6 @@ export class ProyectosAcademicos {
|
||||
proyecto_html: string;
|
||||
|
||||
@ManyToOne(() => Profesor, profesor => profesor.proyectosAcademicos)
|
||||
@JoinColumn({ name: 'id_profesor' })
|
||||
@JoinColumn({ name: 'id_profesor', referencedColumnName: 'id_profesor', foreignKeyConstraintName: 'FK_proyectos_academicos' })
|
||||
profesor: Profesor;
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ import { User } from '../../users/entities/user.entity';
|
||||
|
||||
@Entity({ name: 'tipo_usuario' })
|
||||
export class TipoUsuario {
|
||||
@PrimaryGeneratedColumn()
|
||||
@PrimaryGeneratedColumn({ name: 'PK_tipo_usuario' })
|
||||
id_tipo_usuario: number;
|
||||
|
||||
@Column({ type: 'varchar', length: 30, nullable: false })
|
||||
|
||||
@@ -5,7 +5,7 @@ import { Profesor } from 'src/Profesor/entities/profesor.entity';
|
||||
@Entity({ name: 'usuario' })
|
||||
export class User {
|
||||
|
||||
@PrimaryGeneratedColumn()
|
||||
@PrimaryGeneratedColumn({ name: 'PK_usuario' })
|
||||
id_usuario: number;
|
||||
|
||||
@Column({ type: 'int', nullable: false })
|
||||
@@ -33,9 +33,9 @@ export class User {
|
||||
lastlog: Date;
|
||||
|
||||
@ManyToOne(() => TipoUsuario, tipoUsuario => tipoUsuario.users)
|
||||
@JoinColumn({ name: 'id_tipo_usuario' })
|
||||
@JoinColumn({ name: 'id_tipo_usuario', referencedColumnName: 'id_tipo_usuario', foreignKeyConstraintName: 'FK_tipo_usuario' })
|
||||
tipoUsuario: TipoUsuario;
|
||||
|
||||
@OneToMany(() => Profesor, profesor => profesor.user)
|
||||
profesores: Profesor[];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user