From 215c9f6ce574154047e08e377c0c3a6c0716c62a Mon Sep 17 00:00:00 2001 From: IO <320154041@pcpuma.acatlan.unam.mx> Date: Wed, 19 Jun 2024 12:49:28 -0600 Subject: [PATCH 1/3] =?UTF-8?q?i=20don=C2=B4t=20know=20what=20i=20do?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/auth/auth.controller.ts | 4 ++-- src/auth/auth.service.ts | 9 +++++---- 2 files changed, 7 insertions(+), 6 deletions(-) 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 { From 4cb0c7d73793ebec5af8a16db2422e4bb34629ff Mon Sep 17 00:00:00 2001 From: IO <320154041@pcpuma.acatlan.unam.mx> Date: Wed, 19 Jun 2024 13:27:13 -0600 Subject: [PATCH 2/3] brings teachers in order by nombre ASC --- src/Profesor/profesor.service.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Profesor/profesor.service.ts b/src/Profesor/profesor.service.ts index fbd2599..b2cfc59 100644 --- a/src/Profesor/profesor.service.ts +++ b/src/Profesor/profesor.service.ts @@ -30,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 From 3f6bb6d00e6fb36282820a4be15403e68ea3f148 Mon Sep 17 00:00:00 2001 From: IO <320154041@pcpuma.acatlan.unam.mx> Date: Wed, 19 Jun 2024 16:18:12 -0600 Subject: [PATCH 3/3] new get test --- src/Profesor/profesor.controller.ts | 10 +++++++++- src/Profesor/profesor.service.ts | 14 ++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) 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 b2cfc59..3dba275 100644 --- a/src/Profesor/profesor.service.ts +++ b/src/Profesor/profesor.service.ts @@ -99,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 }; + } }