diff --git a/src/Profesor/dto/profesorDto.dto.ts b/src/Profesor/dto/profesorDto.dto.ts index b165454..1f083e4 100644 --- a/src/Profesor/dto/profesorDto.dto.ts +++ b/src/Profesor/dto/profesorDto.dto.ts @@ -2,10 +2,6 @@ import { IsBoolean, IsInt, IsNotEmpty, IsNumber, IsString, IsOptional, Length} f export class profesorDto{ - @IsInt() - @IsNotEmpty() - id_profesor: number; - @IsInt() @IsNotEmpty() id_usuario: number; @@ -78,10 +74,10 @@ export class profesorDto{ fotografia: string; @IsBoolean() - @IsNotEmpty() - activo: boolean = false; + @IsOptional() + activo: boolean; @IsBoolean() - @IsNotEmpty() - mostrar: boolean = true; + @IsOptional() + mostrar: boolean; } \ No newline at end of file diff --git a/src/Profesor/dto/profesorFilterDto.dto.ts b/src/Profesor/dto/profesorFilterDto.dto.ts deleted file mode 100644 index f2095b9..0000000 --- a/src/Profesor/dto/profesorFilterDto.dto.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { IsOptional, IsString, IsInt, IsBoolean } from 'class-validator'; - -export class ProfesorFilterDto { - @IsOptional() - @IsString() - nombre?: string; - - @IsOptional() - @IsInt() - id_categoria?: number; - - @IsOptional() - @IsInt() - id_carrera?: number; - - @IsOptional() - @IsString() - extension?: string; - - @IsOptional() - @IsInt() - id_adscripcion?: number; - - @IsOptional() - @IsInt() - id_edificio?: number; - - @IsOptional() - @IsBoolean() - activo?: boolean; -} diff --git a/src/Profesor/entities/profesor.entity.ts b/src/Profesor/entities/profesor.entity.ts index d8bd57d..31e3264 100644 --- a/src/Profesor/entities/profesor.entity.ts +++ b/src/Profesor/entities/profesor.entity.ts @@ -1,6 +1,6 @@ import { Entity, - PrimaryColumn, + PrimaryGeneratedColumn, Column, ManyToOne, OneToMany, @@ -16,7 +16,7 @@ import { User } from 'src/users/entities/user.entity'; @Entity() export class Profesor { - @PrimaryColumn({ type: 'int', nullable: false }) + @PrimaryGeneratedColumn() id_profesor: number; @Column({ type: 'int',nullable: false }) diff --git a/src/Profesor/profesor.controller.ts b/src/Profesor/profesor.controller.ts index 85aa4fd..68e1215 100644 --- a/src/Profesor/profesor.controller.ts +++ b/src/Profesor/profesor.controller.ts @@ -1,4 +1,4 @@ -import { Body, Controller, Delete, Get, Param, ParseIntPipe, Post, Put } from '@nestjs/common'; +import { Body, Controller, Delete, Get, Param, ParseIntPipe, Post, Put, Query } from '@nestjs/common'; import { ProfesorService } from './profesor.service'; import { profesorDto } from './dto/profesorDto.dto'; @@ -16,6 +16,14 @@ export class ProfesorController { return this.profesorService.findAll(); } + @Get('page') + findAllPaginated(@Query('page') page: number = 1, @Query('limit') limit: number = 10) { + page = page < 1 ? 1 : page; + limit = limit > 10 || limit < 1 ? 10 : limit; // Limitar el límite máximo a 10 por página + + return this.profesorService.findAllPaginated(page, limit); + } + @Put(':id_profesor') async postModify(@Param('id_profesor', ParseIntPipe) id_profesor: number, @Body() data: profesorDto) { return this.profesorService.modify(id_profesor, data); diff --git a/src/Profesor/profesor.service.ts b/src/Profesor/profesor.service.ts index 6336f5f..3dba275 100644 --- a/src/Profesor/profesor.service.ts +++ b/src/Profesor/profesor.service.ts @@ -3,7 +3,6 @@ import { Profesor } from './entities/profesor.entity'; import { InjectRepository } from '@nestjs/typeorm'; import { Repository } from 'typeorm'; import { profesorDto } from './dto/profesorDto.dto'; -import { ProfesorFilterDto } from './dto/profesorFilterDto.dto'; @Injectable() export class ProfesorService { @@ -31,7 +30,11 @@ export class ProfesorService { //brings all teachers async findAll(): Promise { - return this.profesorRepository.find(); + return this.profesorRepository.find({ + order: { + nombre: 'ASC', + }, + }); } //modify teacher @@ -96,4 +99,18 @@ export class ProfesorService { return query.getMany(); } + + async findAllPaginated(page: number, limit: number): Promise<{ profesores: Profesor[], total: number, totalPages: number }> { + const [profesores, total] = await this.profesorRepository.findAndCount({ + skip: (page - 1) * limit, + take: limit, + order: { + nombre: 'ASC', + }, + }); + + const totalPages = Math.ceil(total / limit); + + return { profesores, total, totalPages }; + } } diff --git a/src/auth/auth.controller.ts b/src/auth/auth.controller.ts index 86fe81d..1ec9d93 100644 --- a/src/auth/auth.controller.ts +++ b/src/auth/auth.controller.ts @@ -37,8 +37,8 @@ export class AuthController { } @Put('Modificacion/:id') - async update(@Param('id') userId: number, @Body() updateUserDto: Record) { - return this.authService.update(userId, updateUserDto); + async update(@Param('id') userId: number, @Body() data: registerDto) { + return this.authService.update(userId, data); } @Delete(':id') diff --git a/src/auth/auth.service.ts b/src/auth/auth.service.ts index 6a2e42c..5b88f77 100644 --- a/src/auth/auth.service.ts +++ b/src/auth/auth.service.ts @@ -65,16 +65,17 @@ export class AuthService { return { token: token }; } - async update(userId, updateUserDto) { + //update user + async update(userId, data:registerDto) { - const{contraseña}=updateUserDto; + const{contraseña}=data; if(contraseña){ const hashedpassword = await hash(contraseña, 10); - updateUserDto = {...updateUserDto,contraseña:hashedpassword}; + data = {...data,contraseña:hashedpassword}; } - return await this.userRepository.update(userId, updateUserDto); + return await this.userRepository.update(userId, data); } async remove(userId: number): Promise {