merge into lino and sam

This commit is contained in:
TheManus88
2024-06-17 20:19:58 -06:00
parent ecb55beeaf
commit 6aba8b98f2
14 changed files with 110 additions and 88 deletions
+45 -17
View File
@@ -1,11 +1,18 @@
import { Entity, PrimaryColumn, Column, ManyToOne, OneToMany, JoinColumn } from 'typeorm';
import { Edificio } from './edificio.entity';
import { Adscripcion } from './adscripcion.entity';
import { Categoria } from './categoria.entity';
import { DatosAcademicos } from './datos_academicos.entity';
import { LineasInvestigacion } from './lineas_investigacion.entity';
import { ProyectosAcademicos } from './proyectos_academicos.entity';
import { AsignaturaCarreraProfesor } from './asignatura_carrera_profesor.entity';
import {
Entity,
PrimaryColumn,
Column,
ManyToOne,
OneToMany,
JoinColumn,
} from 'typeorm';
import { Edificio } from '../../edificio/entities/edificio.entity';
import { Adscripcion } from '../../adscripcion/entities/adscripcion.entity';
import { Categoria } from '../../categoria/entities/categoria.entity';
import { DatosAcademicos } from '../../datos_academicos/entities/datos_academicos.entity';
import { LineasInvestigacion } from '../../lineas_investigacion/entities/lineas_investigacion.entity';
import { ProyectosAcademicos } from '../../proyectos_academicos/entities/proyectos_academicos.entity';
import { AsignaturaCarreraProfesor } from '../../asignatura_carrera_profesor/entities/asignatura_carrera_profesor.entity';
@Entity()
export class Profesor {
@@ -63,33 +70,54 @@ export class Profesor {
@Column({ type: 'boolean', nullable: false, default: true })
mostrar: boolean;
@Column({ type: 'timestamp', nullable: false, default: () => 'CURRENT_DATETIME' })
@Column({
type: 'timestamp',
nullable: false,
default: () => 'CURRENT_DATETIME',
})
fecha_alta: Date;
@Column({ type: 'timestamp', nullable: false, default: () => 'CURRENT_TIMESTAMP', onUpdate: 'CURRENT_TIMESTAMP' })
@Column({
type: 'timestamp',
nullable: false,
default: () => 'CURRENT_TIMESTAMP',
onUpdate: 'CURRENT_TIMESTAMP',
})
fecha_actualizacion: Date;
@ManyToOne(() => Edificio, edificio => edificio.profesores)
@ManyToOne(() => Edificio, (edificio) => edificio.profesores)
@JoinColumn({ name: 'id_edificio' })
edificio: Edificio;
@ManyToOne(() => Adscripcion, adscripcion => adscripcion.profesores)
@ManyToOne(() => Adscripcion, (adscripcion) => adscripcion.profesores)
@JoinColumn({ name: 'id_adscripcion' })
adscripcion: Adscripcion;
@ManyToOne(() => Categoria, categoria => categoria.profesores)
@ManyToOne(() => Categoria, (categoria) => categoria.profesores)
@JoinColumn({ name: 'id_categoria' })
categoria: Categoria;
@OneToMany(() => DatosAcademicos, datosAcademicos => DatosAcademicos.profesor)
@OneToMany(
() => DatosAcademicos,
(datosAcademicos) => datosAcademicos.profesor,
)
datosAcademicos: DatosAcademicos[];
@OneToMany(() => LineasInvestigacion, lineasInvestigacion => LineasInvestigacion.profesor)
@OneToMany(
() => LineasInvestigacion,
(lineasInvestigacion) => lineasInvestigacion.profesor,
)
lineasInvestigacion: LineasInvestigacion[];
@OneToMany(() => ProyectosAcademicos, proyectosAcademicos => ProyectosAcademicos.profesor)
@OneToMany(
() => ProyectosAcademicos,
(proyectosAcademicos) => proyectosAcademicos.profesor,
)
proyectosAcademicos: ProyectosAcademicos[];
@OneToMany(() => AsignaturaCarreraProfesor, acp => AsignaturaCarreraProfesor.profesor)
@OneToMany(
() => AsignaturaCarreraProfesor,
(acp) => acp.profesor,
)
asignaturaCarreraProfesores: AsignaturaCarreraProfesor[];
}
@@ -1,5 +1,5 @@
import { Entity, PrimaryColumn, Column, OneToMany } from 'typeorm';
import { Profesor } from './profesor.entity';
import {Profesor} from "../../Profesor/entities/profesor.entity";
@Entity()
export class Adscripcion {
@@ -9,6 +9,6 @@ export class Adscripcion {
@Column({ type: 'varchar', length: 150, nullable: false })
adscripcion: string;
@OneToMany(() => Profesor, profesor => Profesor.adscripcion)
@OneToMany(() => Profesor, profesor => profesor.adscripcion)
profesores: Profesor[];
}
+2 -2
View File
@@ -1,5 +1,5 @@
import { Entity, PrimaryGeneratedColumn, Column, OneToMany } from 'typeorm';
import { AsignaturaCarreraProfesor } from './asignatura_carrera_profesor.entity';
import { AsignaturaCarreraProfesor } from "../../asignatura_carrera_profesor/entities/asignatura_carrera_profesor.entity";
@Entity()
export class Asignatura {
@@ -10,6 +10,6 @@ export class Asignatura {
@Column({ type: 'varchar', length: 50, nullable: false })
materia: string;
@OneToMany(() => AsignaturaCarreraProfesor, acp => AsignaturaCarreraProfesor.asignatura)
@OneToMany(() => AsignaturaCarreraProfesor, (acp) => acp.asignatura)
asignaturaCarreraProfesores: AsignaturaCarreraProfesor[];
}
@@ -1,7 +1,7 @@
import { Entity, PrimaryColumn, Column, ManyToOne, JoinColumn } from 'typeorm';
import { Profesor } from './profesor.entity';
import { Asignatura } from './asignatura.entity';
import { Carrera } from './carrera.entity';
import { Profesor } from "../../Profesor/entities/profesor.entity";
import { Asignatura } from "../../asignatura/entities/asignatura.entity";
import { Carrera } from "../../Carrera/entities/carrera.entity";
@Entity()
export class AsignaturaCarreraProfesor {
+30 -35
View File
@@ -1,12 +1,16 @@
import { HttpException, Inject, Injectable, UnauthorizedException } from '@nestjs/common';
import {
HttpException,
Inject,
Injectable,
UnauthorizedException,
} from '@nestjs/common';
import { UsersService } from '../users/users.service';
import { JwtService } from '@nestjs/jwt';
import { registerDto } from './dto/registerDto.dto';
import { User } from 'src/users/entities/user.entity';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { hash } from 'bcrypt';
import { hash } from 'bcrypt';
import { compare } from 'bcryptjs';
import { ConfigService } from '@nestjs/config';
@@ -15,65 +19,57 @@ export class AuthService {
constructor(
private usersService: UsersService,
private jwtService: JwtService,
private configService:ConfigService,
@InjectRepository(User) private userRepository: Repository<User>
private configService: ConfigService,
@InjectRepository(User) private userRepository: Repository<User>,
) {}
//register users
async register(data: registerDto){
const{usuario,contraseña,} = data;
async register(data: registerDto) {
const { usuario, contraseña } = data;
if(await this.usersService.findOne(usuario)){
throw new HttpException("User already exist",403);
if (await this.usersService.findOne(usuario)) {
throw new HttpException('User already exist', 403);
}
const hashedpassword = await hash(contraseña, 10);
data = {...data, contraseña:hashedpassword}
return this.userRepository.save(
this.userRepository.create(data)
)
data = { ...data, contraseña: hashedpassword };
return this.userRepository.save(this.userRepository.create(data));
}
//singin
async signIn(data: registerDto) {
const{usuario,contraseña} = data;
const { usuario, contraseña } = data;
const user = await this.usersService.findOne(usuario);
if (!user) {
throw new UnauthorizedException('Invalid name');
}
const checkPassword = await compare(contraseña, (await user).contraseña)
const checkPassword = await compare(contraseña, user.contraseña);
if (!checkPassword) {
throw new UnauthorizedException('Invalid password');
}
const payload = {
idUser: user.userId,
username: user.usuario
const payload = {
idUser: user.id_usuario,
username: user.usuario,
};
const token = this.jwtService.sign(payload);
await this.usersService.updateTokenAndDates(user.userId,token, new Date(), new Date(Date.now() + 3600 * 1000));
await this.usersService.updateTokenAndDates(
user.id_usuario,
token,
new Date(),
new Date(Date.now() + 3600 * 1000),
);
return {token: token};
return { token: token };
}
async create(data){
async create(data) {}
}
async update(id, updateUserDto) {}
async update(
id,
updateUserDto
){
}
async remove(
id
){
}
async remove(id) {}
//validate tojen of users
async validateToken(token: string): Promise<User> {
@@ -99,5 +95,4 @@ export class AuthService {
throw new UnauthorizedException('validation token failed');
}
}
}
+2 -2
View File
@@ -1,5 +1,5 @@
import { Entity, PrimaryGeneratedColumn, Column, OneToMany } from 'typeorm';
import { AsignaturaCarreraProfesor } from './asignatura_carrera_profesor.entity';
import { AsignaturaCarreraProfesor } from "../../asignatura_carrera_profesor/entities/asignatura_carrera_profesor.entity";
@Entity()
export class Carrera {
@@ -10,6 +10,6 @@ export class Carrera {
@Column({ type: 'varchar', length: 150, nullable: false })
nombre: string;
@OneToMany(() => AsignaturaCarreraProfesor, asi => AsignaturaCarreraProfesor.carrera)
@OneToMany(() => AsignaturaCarreraProfesor, asi => asi.carrera)
asignaturaCarreraProfesores: AsignaturaCarreraProfesor[];
}
+2 -2
View File
@@ -1,5 +1,5 @@
import { Entity, PrimaryColumn, Column, OneToMany } from 'typeorm';
import { Profesor } from './profesor.entity';
import { Profesor } from '../../Profesor/entities/profesor.entity';
@Entity()
export class Categoria {
@@ -9,6 +9,6 @@ export class Categoria {
@Column({ type: 'varchar', length: 256, nullable: false })
categoria: string;
@OneToMany(() => Profesor, profesor => Profesor.categoria)
@OneToMany(() => Profesor, (profesor) => profesor.categoria)
profesores: Profesor[];
}
@@ -1,9 +1,8 @@
import { Entity, PrimaryColumn, Column, ManyToOne, JoinColumn } from 'typeorm';
import { Profesor } from './profesor.entity';
import { Profesor } from '../../Profesor/entities/profesor.entity';
@Entity({ name: 'datos_academicos' })
export class DatosAcademicos {
@PrimaryColumn({ type: 'int', length: 11, nullable: false })
id_datos: number;
@@ -16,7 +15,7 @@ export class DatosAcademicos {
@Column({ type: 'varchar', length: 260, nullable: true })
grados_obtenidos: string;
@ManyToOne(() => Profesor, profesor => profesor.datosAcademicos)
@ManyToOne(() => Profesor, (profesor) => profesor.datosAcademicos)
@JoinColumn({ name: 'id_profesor' })
profesor: Profesor;
}
+2 -2
View File
@@ -1,5 +1,5 @@
import { Entity, PrimaryColumn, Column, OneToMany } from 'typeorm';
import { Profesor } from './profesor.entity';
import { Profesor } from "../../Profesor/entities/profesor.entity";
@Entity()
export class Edificio {
@@ -9,6 +9,6 @@ export class Edificio {
@Column({ type: 'varchar', length: 256, nullable: false })
edificio: string;
@OneToMany(() => Profesor, profesor => Profesor.edificio)
@OneToMany(() => Profesor, profesor => profesor.edificio)
profesores: Profesor[];
}
@@ -1,5 +1,5 @@
import { Entity, PrimaryColumn, Column, ManyToOne, JoinColumn } from 'typeorm';
import { Profesor } from './profesor.entity';
import { Profesor } from "../../Profesor/entities/profesor.entity";
@Entity({ name: 'lineas_investigacion' })
export class LineasInvestigacion {
@@ -1,5 +1,5 @@
import { Entity, PrimaryColumn, Column, ManyToOne, JoinColumn } from 'typeorm';
import { Profesor } from './profesor.entity';
import { Profesor } from "../../Profesor/entities/profesor.entity";
@Entity({ name: 'proyectos_academicos' })
export class ProyectosAcademicos {
@@ -1,15 +1,14 @@
import { Entity, PrimaryColumn, Column, OneToMany } from 'typeorm';
import { User } from './user.entity';
import { User } from '../../users/entities/user.entity';
@Entity({ name: 'tipo_usuario' })
export class TipoUsuario {
@PrimaryColumn({ type: 'int', length: 11, nullable: false })
id_tipo_usuario: number;
@Column({ type: 'varchar', length: 30, nullable: false })
tipo_usuario: string;
@OneToMany(() => User, user => User.tipoUsuario)
@OneToMany(() => User, (user) => user.tipoUsuario)
users: User[];
}
+1 -1
View File
@@ -1,5 +1,5 @@
import { Entity, PrimaryColumn, Column, ManyToOne, JoinColumn } from 'typeorm';
import { TipoUsuario } from './tipo_usuario.entity';
import { TipoUsuario } from "../../tipo_usuario/entities/tipo_usuario.entity";
@Entity({ name: 'usuario' })
export class User {
+15 -14
View File
@@ -15,28 +15,29 @@ export class UsersService {
return this.users.findOne({ where: { usuario } });
}
async create(user:User): Promise<User> {
async create(user: User): Promise<User> {
const newUser = this.users.create(user);
return this.users.save(newUser);
}
async update(userId: number, updateUserDto: UserDto): Promise<User> {
await this.users.update(userId, updateUserDto);
return this.users.findOne({where:{userId}});
}
//TODO Validar Esta funcion
// async update(userId: number, updateUserDto: UserDto): Promise<User> {
// return await this.users.update(userId, updateUserDto);
// }
async remove(userId: number): Promise<void> {
await this.users.delete(userId);
}
async updateTokenAndDates(id: number, token: string, lastLogin: Date, jwtExpiry: Date): Promise<void> {
async updateTokenAndDates(
id: number,
token: string,
lastLogin: Date,
jwtExpiry: Date,
): Promise<void> {
await this.users.update(id, {
jwt:token,
lastlog:lastLogin,
expirationjwt:jwtExpiry,
});
jwt: token,
lastlog: lastLogin,
expirationjwt: jwtExpiry,
});
}
}