From 6c63490acf0e3855c9efa1e01a5b08dfd8955a7e Mon Sep 17 00:00:00 2001 From: IO <320154041@pcpuma.acatlan.unam.mx> Date: Tue, 18 Jun 2024 15:21:34 -0600 Subject: [PATCH 1/3] fixed foreign key and delete carrera --- src/Profesor/dto/profesorDto.dto.ts | 33 ++++++++---------- src/Profesor/entities/profesor.entity.ts | 9 ++--- src/Profesor/profesor.controller.ts | 2 +- src/app.module.ts | 6 ---- src/asignatura/entities/asignatura.entity.ts | 15 -------- .../asignatura_carrera_profesor.entity.ts | 34 ------------------- src/carrera/entities/carrera.entity.ts | 15 -------- src/categoria/entities/categoria.entity.ts | 5 ++- .../entities/datos_academicos.entity.ts | 2 +- src/edificio/entities/edificio.entity.ts | 5 ++- 10 files changed, 22 insertions(+), 104 deletions(-) delete mode 100644 src/asignatura/entities/asignatura.entity.ts delete mode 100644 src/asignatura_carrera_profesor/entities/asignatura_carrera_profesor.entity.ts delete mode 100644 src/carrera/entities/carrera.entity.ts diff --git a/src/Profesor/dto/profesorDto.dto.ts b/src/Profesor/dto/profesorDto.dto.ts index 87607ab..4950af7 100644 --- a/src/Profesor/dto/profesorDto.dto.ts +++ b/src/Profesor/dto/profesorDto.dto.ts @@ -1,19 +1,17 @@ -import { IsBoolean, IsEmpty, IsNotEmpty, IsNumber, IsString, Length,} from "class-validator"; +import { IsBoolean, IsOptional, IsNotEmpty, IsNumber, IsString, Length,} from "class-validator"; export class profesorDto{ @IsNumber() @IsNotEmpty() - @Length(11) id_profesor: number; @IsNumber() @IsNotEmpty() - @Length(11) id_usuario: number; @IsString() - @IsEmpty() + @IsOptional() @Length(10) num_trabajador: string; @@ -23,62 +21,59 @@ export class profesorDto{ nombre: string; @IsString() - @IsEmpty() + @IsOptional() @Length(10) rfc: string; @IsString() - @IsEmpty() + @IsOptional() @Length(3) homoclave: string; @IsString() - @IsEmpty() + @IsOptional() @Length(13) tel_oficina: string; @IsString() - @IsEmpty() + @IsOptional() @Length(10) extension: string; @IsString() - @IsEmpty() + @IsOptional() @Length(13) tel_personal: string; @IsString() - @IsEmpty() + @IsOptional() @Length(65) correo_pcp: string; @IsString() - @IsEmpty() + @IsOptional() @Length(65) correo_per: string; @IsNumber() - @IsEmpty() - @Length(11) + @IsOptional() id_adscripcion: number; @IsNumber() - @IsEmpty() - @Length(11) + @IsOptional() id_categoria: number; @IsNumber() - @IsEmpty() - @Length(11) + @IsOptional() id_edificio: number; @IsString() - @IsEmpty() + @IsOptional() @Length(256) ubicacion: string; @IsString() - @IsEmpty() + @IsOptional() @Length(150) fotografia: string; diff --git a/src/Profesor/entities/profesor.entity.ts b/src/Profesor/entities/profesor.entity.ts index da56a3b..480bf7a 100644 --- a/src/Profesor/entities/profesor.entity.ts +++ b/src/Profesor/entities/profesor.entity.ts @@ -12,7 +12,6 @@ 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 { @@ -71,8 +70,9 @@ export class Profesor { mostrar: boolean; @Column({ - type: 'datetime', + type: 'timestamp', nullable: false, + default: () => 'CURRENT_TIMESTAMP', }) fecha_alta: Date; @@ -114,9 +114,4 @@ export class Profesor { ) proyectosAcademicos: ProyectosAcademicos[]; - @OneToMany( - () => AsignaturaCarreraProfesor, - (acp) => acp.profesor, - ) - asignaturaCarreraProfesores: AsignaturaCarreraProfesor[]; } diff --git a/src/Profesor/profesor.controller.ts b/src/Profesor/profesor.controller.ts index 9ad13c1..3cf47d1 100644 --- a/src/Profesor/profesor.controller.ts +++ b/src/Profesor/profesor.controller.ts @@ -8,7 +8,7 @@ export class ProfesorController { constructor(private profesorService: ProfesorService) {} @Post() - async postRegister(@Body() data: profesorDto) { + async register(@Body() data: profesorDto) { return this.profesorService.register(data); } diff --git a/src/app.module.ts b/src/app.module.ts index 80c18a0..3d3827f 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -7,9 +7,6 @@ import { TypeOrmModule } from '@nestjs/typeorm'; import { UsersModule } from './users/users.module'; import { User } from './users/entities/user.entity'; import { Adscripcion } from './adscripcion/entities/adscripcion.entity'; -import { Asignatura } from './asignatura/entities/asignatura.entity'; -import { AsignaturaCarreraProfesor } from './asignatura_carrera_profesor/entities/asignatura_carrera_profesor.entity'; -import { Carrera } from './carrera/entities/carrera.entity'; import { Categoria } from './categoria/entities/categoria.entity'; import { DatosAcademicos } from './datos_academicos/entities/datos_academicos.entity'; import { Edificio } from './edificio/entities/edificio.entity'; @@ -41,9 +38,6 @@ import { Profesor } from './Profesor/entities/profesor.entity'; User, Profesor, Adscripcion, - Asignatura, - AsignaturaCarreraProfesor, - Carrera, Categoria, DatosAcademicos, Edificio, diff --git a/src/asignatura/entities/asignatura.entity.ts b/src/asignatura/entities/asignatura.entity.ts deleted file mode 100644 index e28fee1..0000000 --- a/src/asignatura/entities/asignatura.entity.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { Entity, PrimaryGeneratedColumn, Column, OneToMany } from 'typeorm'; -import { AsignaturaCarreraProfesor } from "../../asignatura_carrera_profesor/entities/asignatura_carrera_profesor.entity"; - -@Entity() -export class Asignatura { - - @PrimaryGeneratedColumn() - id_asignatura: number; - - @Column({ type: 'varchar', length: 50, nullable: false }) - materia: string; - - @OneToMany(() => AsignaturaCarreraProfesor, (acp) => acp.asignatura) - asignaturaCarreraProfesores: AsignaturaCarreraProfesor[]; -} diff --git a/src/asignatura_carrera_profesor/entities/asignatura_carrera_profesor.entity.ts b/src/asignatura_carrera_profesor/entities/asignatura_carrera_profesor.entity.ts deleted file mode 100644 index ebf4f15..0000000 --- a/src/asignatura_carrera_profesor/entities/asignatura_carrera_profesor.entity.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { Entity, PrimaryColumn, Column, ManyToOne, JoinColumn } from 'typeorm'; -import { Profesor } from "../../Profesor/entities/profesor.entity"; -import { Asignatura } from "../../asignatura/entities/asignatura.entity"; -import { Carrera } from 'src/carrera/entities/carrera.entity'; - -@Entity() -export class AsignaturaCarreraProfesor { - @PrimaryColumn({ type: 'int', nullable: false }) - id_profesor: number; - - @PrimaryColumn({ type: 'int', nullable: false }) - id_carrera: number; - - @PrimaryColumn({ type: 'int', nullable: false }) - id_asignatura: number; - - @Column({ type: 'varchar', length: 150, nullable: false }) - semestre: string; - - @Column({ type: 'varchar', length: 150, nullable: false }) - periodo: string; - - @ManyToOne(() => Profesor, profesor => profesor.asignaturaCarreraProfesores) - @JoinColumn({ name: 'id_profesor' }) - profesor: Profesor; - - @ManyToOne(() => Carrera, carrera => carrera.asignaturaCarreraProfesores) - @JoinColumn({ name: 'id_carrera' }) - carrera: Carrera; - - @ManyToOne(() => Asignatura, asignatura => asignatura.asignaturaCarreraProfesores) - @JoinColumn({ name: 'id_asignatura' }) - asignatura: Asignatura; -} diff --git a/src/carrera/entities/carrera.entity.ts b/src/carrera/entities/carrera.entity.ts deleted file mode 100644 index 0b70e72..0000000 --- a/src/carrera/entities/carrera.entity.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { Entity, PrimaryGeneratedColumn, Column, OneToMany } from 'typeorm'; -import { AsignaturaCarreraProfesor } from "../../asignatura_carrera_profesor/entities/asignatura_carrera_profesor.entity"; - -@Entity() -export class Carrera { - - @PrimaryGeneratedColumn() - id_carrera: number; - - @Column({ type: 'varchar', length: 150, nullable: false }) - nombre: string; - - @OneToMany(() => AsignaturaCarreraProfesor, asi => asi.carrera) - asignaturaCarreraProfesores: AsignaturaCarreraProfesor[]; -} diff --git a/src/categoria/entities/categoria.entity.ts b/src/categoria/entities/categoria.entity.ts index b2e34f5..c272396 100644 --- a/src/categoria/entities/categoria.entity.ts +++ b/src/categoria/entities/categoria.entity.ts @@ -1,5 +1,4 @@ import { Entity, PrimaryColumn, Column, OneToMany } from 'typeorm'; -import { Profesor } from '../../Profesor/entities/profesor.entity'; @Entity() export class Categoria { @@ -9,6 +8,6 @@ export class Categoria { @Column({ type: 'varchar', length: 256, nullable: false }) categoria: string; - @OneToMany(() => Profesor, (profesor) => profesor.categoria) - profesores: Profesor[]; + @OneToMany(() => Categoria, (categoria) => categoria.profesores) + profesores: Categoria[]; } diff --git a/src/datos_academicos/entities/datos_academicos.entity.ts b/src/datos_academicos/entities/datos_academicos.entity.ts index 5226e04..364d139 100644 --- a/src/datos_academicos/entities/datos_academicos.entity.ts +++ b/src/datos_academicos/entities/datos_academicos.entity.ts @@ -17,5 +17,5 @@ export class DatosAcademicos { @ManyToOne(() => Profesor, (profesor) => profesor.datosAcademicos) @JoinColumn({ name: 'id_profesor' }) - profesor: Profesor; + profesor: Profesor[]; } diff --git a/src/edificio/entities/edificio.entity.ts b/src/edificio/entities/edificio.entity.ts index ebbc4ec..0619d94 100644 --- a/src/edificio/entities/edificio.entity.ts +++ b/src/edificio/entities/edificio.entity.ts @@ -1,5 +1,4 @@ import { Entity, PrimaryColumn, Column, OneToMany } from 'typeorm'; -import { Profesor } from "../../Profesor/entities/profesor.entity"; @Entity() export class Edificio { @@ -9,6 +8,6 @@ export class Edificio { @Column({ type: 'varchar', length: 256, nullable: false }) edificio: string; - @OneToMany(() => Profesor, profesor => profesor.edificio) - profesores: Profesor[]; + @OneToMany(() => Edificio, edificio => edificio.profesores) + profesores: Edificio[]; } From 6945846ef5b6171a98f6658839b84b12a3f12008 Mon Sep 17 00:00:00 2001 From: IO <320154041@pcpuma.acatlan.unam.mx> Date: Tue, 18 Jun 2024 16:24:50 -0600 Subject: [PATCH 2/3] it is working until now --- src/auth/auth.controller.ts | 2 +- src/auth/auth.service.ts | 2 +- src/auth/dto/registerDto.dto.ts | 9 ++++++++- src/datos_academicos/entities/datos_academicos.entity.ts | 2 +- src/users/entities/user.entity.ts | 4 ++-- 5 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/auth/auth.controller.ts b/src/auth/auth.controller.ts index c72d9ff..0e72522 100644 --- a/src/auth/auth.controller.ts +++ b/src/auth/auth.controller.ts @@ -27,7 +27,7 @@ export class AuthController { } @Post("register") - async postRegister(@Body() data: registerDto){ + async register(@Body() data: registerDto){ return this.authService.register(data) } diff --git a/src/auth/auth.service.ts b/src/auth/auth.service.ts index 16ecd2d..b020240 100644 --- a/src/auth/auth.service.ts +++ b/src/auth/auth.service.ts @@ -25,7 +25,7 @@ export class AuthService { //register users async register(data: registerDto) { - const { usuario, contraseña } = data; + const { usuario, contraseña} = data; if (await this.usersService.findOne(usuario)) { throw new HttpException('User already exist', 403); diff --git a/src/auth/dto/registerDto.dto.ts b/src/auth/dto/registerDto.dto.ts index f465b1a..597b033 100644 --- a/src/auth/dto/registerDto.dto.ts +++ b/src/auth/dto/registerDto.dto.ts @@ -1,4 +1,4 @@ -import {IsString, IsNotEmpty } from "class-validator"; +import {IsString, IsNotEmpty,IsNumber } from "class-validator"; export class registerDto{ @@ -10,5 +10,12 @@ export class registerDto{ @IsNotEmpty() contraseña: string; + @IsNumber() + @IsNotEmpty() + id_tipo_usuario:number; + + @IsString() + @IsNotEmpty() + correo: string; } \ No newline at end of file diff --git a/src/datos_academicos/entities/datos_academicos.entity.ts b/src/datos_academicos/entities/datos_academicos.entity.ts index 364d139..5226e04 100644 --- a/src/datos_academicos/entities/datos_academicos.entity.ts +++ b/src/datos_academicos/entities/datos_academicos.entity.ts @@ -17,5 +17,5 @@ export class DatosAcademicos { @ManyToOne(() => Profesor, (profesor) => profesor.datosAcademicos) @JoinColumn({ name: 'id_profesor' }) - profesor: Profesor[]; + profesor: Profesor; } diff --git a/src/users/entities/user.entity.ts b/src/users/entities/user.entity.ts index 8497616..40f82b7 100644 --- a/src/users/entities/user.entity.ts +++ b/src/users/entities/user.entity.ts @@ -1,11 +1,11 @@ -import { Entity, PrimaryColumn, Column, ManyToOne, JoinColumn, OneToMany } from 'typeorm'; +import { Entity, PrimaryGeneratedColumn, Column, ManyToOne, JoinColumn, OneToMany } from 'typeorm'; import { TipoUsuario } from "../../tipo_usuario/entities/tipo_usuario.entity"; import { Profesor } from 'src/Profesor/entities/profesor.entity'; @Entity({ name: 'usuario' }) export class User { - @PrimaryColumn({ type: 'int', nullable: false }) + @PrimaryGeneratedColumn() id_usuario: number; @Column({ type: 'int', nullable: false }) From 30048aa544773ac2c8fe489d8a455877b6af03cd Mon Sep 17 00:00:00 2001 From: IO <320154041@pcpuma.acatlan.unam.mx> Date: Tue, 18 Jun 2024 16:38:34 -0600 Subject: [PATCH 3/3] fixed bug --- src/Profesor/profesor.controller.ts | 1 - src/auth/auth.controller.ts | 7 +------ src/auth/auth.service.ts | 2 -- src/auth/dto/registerDto.dto.ts | 4 ++-- src/users/dto/userDto.dto.ts | 10 +++++++++- src/users/users.service.ts | 8 ++++---- 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/Profesor/profesor.controller.ts b/src/Profesor/profesor.controller.ts index 3cf47d1..85aa4fd 100644 --- a/src/Profesor/profesor.controller.ts +++ b/src/Profesor/profesor.controller.ts @@ -1,7 +1,6 @@ import { Body, Controller, Delete, Get, Param, ParseIntPipe, Post, Put } from '@nestjs/common'; import { ProfesorService } from './profesor.service'; import { profesorDto } from './dto/profesorDto.dto'; -import { ProfesorFilterDto } from './dto/profesorFilterDto.dto'; @Controller('profesor') export class ProfesorController { diff --git a/src/auth/auth.controller.ts b/src/auth/auth.controller.ts index 0e72522..6a5f60d 100644 --- a/src/auth/auth.controller.ts +++ b/src/auth/auth.controller.ts @@ -26,6 +26,7 @@ export class AuthController { return this.authService.signIn(data); } + @UseGuards(AuthGuard) @Post("register") async register(@Body() data: registerDto){ return this.authService.register(data) @@ -37,12 +38,6 @@ export class AuthController { return req.user; } - @UseGuards(AuthGuard) - @Post('Alta') - async create(@Body() data: UserDto) { - return this.authService.create(data); - } - @UseGuards(AuthGuard) @Put('Modificacion/:id') async update(@Param('id') id: number, @Body() updateUserDto: Record) { diff --git a/src/auth/auth.service.ts b/src/auth/auth.service.ts index b020240..a147f0e 100644 --- a/src/auth/auth.service.ts +++ b/src/auth/auth.service.ts @@ -65,8 +65,6 @@ export class AuthService { return { token: token }; } - async create(data) {} - async update(id, updateUserDto) {} async remove(id) {} diff --git a/src/auth/dto/registerDto.dto.ts b/src/auth/dto/registerDto.dto.ts index 597b033..bf922d1 100644 --- a/src/auth/dto/registerDto.dto.ts +++ b/src/auth/dto/registerDto.dto.ts @@ -1,4 +1,4 @@ -import {IsString, IsNotEmpty,IsNumber } from "class-validator"; +import {IsString, IsNotEmpty,IsNumber,IsEmail } from "class-validator"; export class registerDto{ @@ -14,7 +14,7 @@ export class registerDto{ @IsNotEmpty() id_tipo_usuario:number; - @IsString() + @IsEmail() @IsNotEmpty() correo: string; diff --git a/src/users/dto/userDto.dto.ts b/src/users/dto/userDto.dto.ts index 0f1ba81..54d8644 100644 --- a/src/users/dto/userDto.dto.ts +++ b/src/users/dto/userDto.dto.ts @@ -1,4 +1,4 @@ -import { IsEmail, IsNotEmpty, IsString} from "class-validator"; +import { IsEmail, IsNotEmpty, IsString,IsNumber} from "class-validator"; export class UserDto{ @IsString() @@ -9,4 +9,12 @@ export class UserDto{ @IsNotEmpty() contraseña: string; + @IsNumber() + @IsNotEmpty() + id_tipo_usuario:number; + + @IsEmail() + @IsNotEmpty() + correo: string; + } \ No newline at end of file diff --git a/src/users/users.service.ts b/src/users/users.service.ts index 107753a..bf6736b 100644 --- a/src/users/users.service.ts +++ b/src/users/users.service.ts @@ -19,10 +19,10 @@ export class UsersService { const newUser = this.users.create(user); return this.users.save(newUser); } - //TODO Validar Esta funcion - // async update(userId: number, updateUserDto: UserDto): Promise { - // return await this.users.update(userId, updateUserDto); - // } + + //async update(userId: number, updateUserDto: UserDto): Promise { + //return await this.users.update(userId, updateUserDto); + //} async remove(userId: number): Promise { await this.users.delete(userId);